Skip to content

Commit

Permalink
UI - Fetch Latest Block Time to get channels updation time
Browse files Browse the repository at this point in the history
Signed-off-by: deekshithvarma256 <deekshithvarma256@gmail.com>
  • Loading branch information
deekshithvarma256 committed Oct 16, 2023
1 parent bed8e70 commit 546c233
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 8 deletions.
13 changes: 12 additions & 1 deletion client/src/components/Header/HeaderView.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ import {
refreshType,
getBlockListSearchType
} from '../types';
import { Tooltip } from '@material-ui/core';

const {
blockPerHour,
Expand Down Expand Up @@ -293,7 +294,17 @@ export class HeaderView extends Component {
nextProps.channels.forEach(element => {
options.push({
value: element.channel_genesis_hash,
label: element.channelname
label: (
<Tooltip
placement="right"
title={
element?.agoBlockTimes ? `Updated ${element?.agoBlockTimes} ago` : ''
}
arrow
>
<div>{element.channelname}</div>
</Tooltip>
)
});
if (
nextProps.currentChannel == null ||
Expand Down
20 changes: 13 additions & 7 deletions client/src/components/Header/HeaderView.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -216,9 +216,12 @@ describe('HeaderView', () => {
const { wrapper } = setup();
const instance = wrapper.instance();
const spy = jest.spyOn(instance, 'syncData');
expect(setInterval).toHaveBeenCalled();
const setIntervalSpy = jest.spyOn(window, 'setInterval');
wrapper.instance().componentDidMount();
expect(setIntervalSpy).toHaveBeenCalled();
jest.runOnlyPendingTimers();
expect(spy).toHaveBeenCalled();
setIntervalSpy.mockRestore();
});

test('switch calls handleThemeChange', () => {
Expand Down Expand Up @@ -250,11 +253,12 @@ describe('HeaderView', () => {
const { wrapper } = setup();
const instance = wrapper.instance();
const spy = jest.spyOn(instance, 'componentWillUnmount');

const clearIntervalSpy = jest.spyOn(window, 'clearInterval');
wrapper.unmount();

expect(spy).toHaveBeenCalledTimes(1);
expect(clearInterval).toHaveBeenCalled();
expect(clearIntervalSpy).toHaveBeenCalled();
clearIntervalSpy.mockRestore();
});

test('channels / selectedChannel state are left empty when componentWillReceiveProps gets called with empty channel list', () => {
Expand Down Expand Up @@ -365,7 +369,7 @@ describe('HeaderView', () => {

test('handleChange does nothing when channel list has only a single entry or nothing', () => {
const { wrapper } = setup();

const clearIntervalSpy = jest.spyOn(window, 'clearInterval');
wrapper.setState({
channels: [
{
Expand All @@ -382,12 +386,12 @@ describe('HeaderView', () => {
]
});

clearInterval.mockClear();
wrapper.instance().handleChange({
value: '5e02f3535193eafeb084ea68e61b6ab73b6b9123e317499be2b428c37c24c46e',
label: 'mychannels'
});
expect(clearInterval).not.toHaveBeenCalled();
expect(clearIntervalSpy).not.toHaveBeenCalled();
clearIntervalSpy.mockRestore();
});

test('registerOpen does update a state', () => {
Expand Down Expand Up @@ -449,7 +453,9 @@ describe('HeaderView', () => {

const instance = wrapper.instance();
const spy = jest.spyOn(instance, 'registerOpen');
fa.first().prop('onClick')();
if (fa.first().prop('onClick')) {
fa.first().prop('onClick')();
}
expect(spy).toHaveBeenCalledTimes(1);
});
});

0 comments on commit 546c233

Please sign in to comment.