Skip to content

Commit

Permalink
fix unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mistercrunch committed Sep 10, 2020
1 parent 96619e8 commit 8e0dbe8
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ describe('Datasource control', () => {
cy.get('#datasource_menu').click();
cy.get('a').contains('Edit Datasource').click();
// create new metric
cy.get('a[role="tab"]').contains('Metrics').click();
cy.get('button').contains('Add Item').click();
cy.get('input[value="<new metric>"]').click();
cy.get('input[value="<new metric>"]')
Expand All @@ -53,6 +54,7 @@ describe('Datasource control', () => {
// delete metric
cy.get('#datasource_menu').click();
cy.get('a').contains('Edit Datasource').click();
cy.get('a[role="tab"]').contains('Metrics').click();
cy.get(`input[value="${newMetricName}"]`)
.closest('tr')
.find('.fa-trash')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,10 @@ async function mountAndWait(props = mockedProps) {
}

describe('DatasourceModal', () => {
fetchMock.post(SAVE_ENDPOINT, SAVE_PAYLOAD);
const callsP = fetchMock.put(SAVE_ENDPOINT, SAVE_PAYLOAD);

let wrapper;

beforeEach(async () => {
fetchMock.reset();
wrapper = await mountAndWait();
});

Expand All @@ -82,6 +80,7 @@ describe('DatasourceModal', () => {
});

it('saves on confirm', async () => {
const callsP = fetchMock.post(SAVE_ENDPOINT, SAVE_PAYLOAD);
act(() => {
wrapper
.find('button[data-test="datasource-modal-save"]')
Expand All @@ -94,6 +93,9 @@ describe('DatasourceModal', () => {
okButton.simulate('click');
});
await waitForComponentToPaint(wrapper);
expect(callsP._calls).toHaveLength(2); /* eslint no-underscore-dangle: 0 */
const expected = ['http://localhost/datasource/save/'];
expect(callsP._calls.map(call => call[0])).toEqual(
expected,
); /* eslint no-underscore-dangle: 0 */
});
});

0 comments on commit 8e0dbe8

Please sign in to comment.