Skip to content

Commit

Permalink
adding warnings tests
Browse files Browse the repository at this point in the history
Signed-off-by: Harsh Pratap Singh <[email protected]>
  • Loading branch information
harsh-ps-2003 committed Jan 12, 2024
1 parent 22bbb40 commit e9ae851
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions pkg/ui/react-app/src/pages/targets/ScrapePoolList.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,48 @@ describe('ScrapePoolList', () => {
expect(alert.text()).toContain('Error fetching targets');
});
});
describe('when a warning is returned', () => {
it('displays warnings in the UI', async () => {
const mock = fetchMock.mockResponseOnce(JSON.stringify({ status: 'error', warnings: ['Warning 1', 'Warning 2'] }));

let scrapePoolList: any;
await act(async () => {
scrapePoolList = mount(<ScrapePoolList {...defaultProps} />);
});

scrapePoolList.update();

expect(mock).toHaveBeenCalledWith('../api/v1/targets?state=active', {
cache: 'no-store',
credentials: 'same-origin',
});

const warning1 = scrapePoolList.findWhere((node: { text: () => string }) => node.text() === 'Warning 1');
const warning2 = scrapePoolList.findWhere((node: { text: () => string }) => node.text() === 'Warning 2');

expect(warning1).toHaveLength(1);
expect(warning2).toHaveLength(1);
});

it('does not display warnings when there are no warnings', async () => {
const mock = fetchMock.mockResponseOnce(JSON.stringify({ status: 'success', warnings: [] }));

let scrapePoolList: any;
await act(async () => {
scrapePoolList = mount(<ScrapePoolList {...defaultProps} />);
});

scrapePoolList.update();

expect(mock).toHaveBeenCalledWith('../api/v1/targets?state=active', {
cache: 'no-store',
credentials: 'same-origin',
});

const warnings = scrapePoolList.findWhere((node: { text: () => string | string[] }) =>
node.text().includes('Warning')
);
expect(warnings).toHaveLength(0);
});
});
});

0 comments on commit e9ae851

Please sign in to comment.