diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-04-20 10:00:54 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-04-20 10:00:54 +0000 |
commit | 3cccd102ba543e02725d247893729e5c73b38295 (patch) | |
tree | f36a04ec38517f5deaaacb5acc7d949688d1e187 /spec/frontend/badges | |
parent | 205943281328046ef7b4528031b90fbda70c75ac (diff) | |
download | gitlab-ce-3cccd102ba543e02725d247893729e5c73b38295.tar.gz |
Add latest changes from gitlab-org/gitlab@14-10-stable-eev14.10.0-rc42
Diffstat (limited to 'spec/frontend/badges')
-rw-r--r-- | spec/frontend/badges/components/badge_spec.js | 6 | ||||
-rw-r--r-- | spec/frontend/badges/store/actions_spec.js | 260 |
2 files changed, 88 insertions, 178 deletions
diff --git a/spec/frontend/badges/components/badge_spec.js b/spec/frontend/badges/components/badge_spec.js index 2310fb8bd8e..fe4cf8ce8eb 100644 --- a/spec/frontend/badges/components/badge_spec.js +++ b/spec/frontend/badges/components/badge_spec.js @@ -89,11 +89,9 @@ describe('Badge component', () => { }); describe('behavior', () => { - beforeEach((done) => { + beforeEach(() => { setFixtures('<div id="dummy-element"></div>'); - createComponent({ ...dummyProps }, '#dummy-element') - .then(done) - .catch(done.fail); + return createComponent({ ...dummyProps }, '#dummy-element'); }); it('shows a badge image after loading', () => { diff --git a/spec/frontend/badges/store/actions_spec.js b/spec/frontend/badges/store/actions_spec.js index 75699f24463..02e1b8e65e4 100644 --- a/spec/frontend/badges/store/actions_spec.js +++ b/spec/frontend/badges/store/actions_spec.js @@ -33,41 +33,38 @@ describe('Badges store actions', () => { }); describe('requestNewBadge', () => { - it('commits REQUEST_NEW_BADGE', (done) => { - testAction( + it('commits REQUEST_NEW_BADGE', () => { + return testAction( actions.requestNewBadge, null, state, [{ type: mutationTypes.REQUEST_NEW_BADGE }], [], - done, ); }); }); describe('receiveNewBadge', () => { - it('commits RECEIVE_NEW_BADGE', (done) => { + it('commits RECEIVE_NEW_BADGE', () => { const newBadge = createDummyBadge(); - testAction( + return testAction( actions.receiveNewBadge, newBadge, state, [{ type: mutationTypes.RECEIVE_NEW_BADGE, payload: newBadge }], [], - done, ); }); }); describe('receiveNewBadgeError', () => { - it('commits RECEIVE_NEW_BADGE_ERROR', (done) => { - testAction( + it('commits RECEIVE_NEW_BADGE_ERROR', () => { + return testAction( actions.receiveNewBadgeError, null, state, [{ type: mutationTypes.RECEIVE_NEW_BADGE_ERROR }], [], - done, ); }); }); @@ -87,7 +84,7 @@ describe('Badges store actions', () => { }; }); - it('dispatches requestNewBadge and receiveNewBadge for successful response', (done) => { + it('dispatches requestNewBadge and receiveNewBadge for successful response', async () => { const dummyResponse = createDummyBadgeResponse(); endpointMock.replyOnce((req) => { @@ -105,16 +102,12 @@ describe('Badges store actions', () => { }); const dummyBadge = transformBackendBadge(dummyResponse); - actions - .addBadge({ state, dispatch }) - .then(() => { - expect(dispatch.mock.calls).toEqual([['receiveNewBadge', dummyBadge]]); - }) - .then(done) - .catch(done.fail); + + await actions.addBadge({ state, dispatch }); + expect(dispatch.mock.calls).toEqual([['receiveNewBadge', dummyBadge]]); }); - it('dispatches requestNewBadge and receiveNewBadgeError for error response', (done) => { + it('dispatches requestNewBadge and receiveNewBadgeError for error response', async () => { endpointMock.replyOnce((req) => { expect(req.data).toBe( JSON.stringify({ @@ -129,52 +122,43 @@ describe('Badges store actions', () => { return [500, '']; }); - actions - .addBadge({ state, dispatch }) - .then(() => done.fail('Expected Ajax call to fail!')) - .catch(() => { - expect(dispatch.mock.calls).toEqual([['receiveNewBadgeError']]); - }) - .then(done) - .catch(done.fail); + await expect(actions.addBadge({ state, dispatch })).rejects.toThrow(); + expect(dispatch.mock.calls).toEqual([['receiveNewBadgeError']]); }); }); describe('requestDeleteBadge', () => { - it('commits REQUEST_DELETE_BADGE', (done) => { - testAction( + it('commits REQUEST_DELETE_BADGE', () => { + return testAction( actions.requestDeleteBadge, badgeId, state, [{ type: mutationTypes.REQUEST_DELETE_BADGE, payload: badgeId }], [], - done, ); }); }); describe('receiveDeleteBadge', () => { - it('commits RECEIVE_DELETE_BADGE', (done) => { - testAction( + it('commits RECEIVE_DELETE_BADGE', () => { + return testAction( actions.receiveDeleteBadge, badgeId, state, [{ type: mutationTypes.RECEIVE_DELETE_BADGE, payload: badgeId }], [], - done, ); }); }); describe('receiveDeleteBadgeError', () => { - it('commits RECEIVE_DELETE_BADGE_ERROR', (done) => { - testAction( + it('commits RECEIVE_DELETE_BADGE_ERROR', () => { + return testAction( actions.receiveDeleteBadgeError, badgeId, state, [{ type: mutationTypes.RECEIVE_DELETE_BADGE_ERROR, payload: badgeId }], [], - done, ); }); }); @@ -188,91 +172,76 @@ describe('Badges store actions', () => { dispatch = jest.fn(); }); - it('dispatches requestDeleteBadge and receiveDeleteBadge for successful response', (done) => { + it('dispatches requestDeleteBadge and receiveDeleteBadge for successful response', async () => { endpointMock.replyOnce(() => { expect(dispatch.mock.calls).toEqual([['requestDeleteBadge', badgeId]]); dispatch.mockClear(); return [200, '']; }); - actions - .deleteBadge({ state, dispatch }, { id: badgeId }) - .then(() => { - expect(dispatch.mock.calls).toEqual([['receiveDeleteBadge', badgeId]]); - }) - .then(done) - .catch(done.fail); + await actions.deleteBadge({ state, dispatch }, { id: badgeId }); + expect(dispatch.mock.calls).toEqual([['receiveDeleteBadge', badgeId]]); }); - it('dispatches requestDeleteBadge and receiveDeleteBadgeError for error response', (done) => { + it('dispatches requestDeleteBadge and receiveDeleteBadgeError for error response', async () => { endpointMock.replyOnce(() => { expect(dispatch.mock.calls).toEqual([['requestDeleteBadge', badgeId]]); dispatch.mockClear(); return [500, '']; }); - actions - .deleteBadge({ state, dispatch }, { id: badgeId }) - .then(() => done.fail('Expected Ajax call to fail!')) - .catch(() => { - expect(dispatch.mock.calls).toEqual([['receiveDeleteBadgeError', badgeId]]); - }) - .then(done) - .catch(done.fail); + await expect(actions.deleteBadge({ state, dispatch }, { id: badgeId })).rejects.toThrow(); + expect(dispatch.mock.calls).toEqual([['receiveDeleteBadgeError', badgeId]]); }); }); describe('editBadge', () => { - it('commits START_EDITING', (done) => { + it('commits START_EDITING', () => { const dummyBadge = createDummyBadge(); - testAction( + return testAction( actions.editBadge, dummyBadge, state, [{ type: mutationTypes.START_EDITING, payload: dummyBadge }], [], - done, ); }); }); describe('requestLoadBadges', () => { - it('commits REQUEST_LOAD_BADGES', (done) => { + it('commits REQUEST_LOAD_BADGES', () => { const dummyData = 'this is not real data'; - testAction( + return testAction( actions.requestLoadBadges, dummyData, state, [{ type: mutationTypes.REQUEST_LOAD_BADGES, payload: dummyData }], [], - done, ); }); }); describe('receiveLoadBadges', () => { - it('commits RECEIVE_LOAD_BADGES', (done) => { + it('commits RECEIVE_LOAD_BADGES', () => { const badges = dummyBadges; - testAction( + return testAction( actions.receiveLoadBadges, badges, state, [{ type: mutationTypes.RECEIVE_LOAD_BADGES, payload: badges }], [], - done, ); }); }); describe('receiveLoadBadgesError', () => { - it('commits RECEIVE_LOAD_BADGES_ERROR', (done) => { - testAction( + it('commits RECEIVE_LOAD_BADGES_ERROR', () => { + return testAction( actions.receiveLoadBadgesError, null, state, [{ type: mutationTypes.RECEIVE_LOAD_BADGES_ERROR }], [], - done, ); }); }); @@ -286,7 +255,7 @@ describe('Badges store actions', () => { dispatch = jest.fn(); }); - it('dispatches requestLoadBadges and receiveLoadBadges for successful response', (done) => { + it('dispatches requestLoadBadges and receiveLoadBadges for successful response', async () => { const dummyData = 'this is just some data'; const dummyReponse = [ createDummyBadgeResponse(), @@ -299,18 +268,13 @@ describe('Badges store actions', () => { return [200, dummyReponse]; }); - actions - .loadBadges({ state, dispatch }, dummyData) - .then(() => { - const badges = dummyReponse.map(transformBackendBadge); + await actions.loadBadges({ state, dispatch }, dummyData); + const badges = dummyReponse.map(transformBackendBadge); - expect(dispatch.mock.calls).toEqual([['receiveLoadBadges', badges]]); - }) - .then(done) - .catch(done.fail); + expect(dispatch.mock.calls).toEqual([['receiveLoadBadges', badges]]); }); - it('dispatches requestLoadBadges and receiveLoadBadgesError for error response', (done) => { + it('dispatches requestLoadBadges and receiveLoadBadgesError for error response', async () => { const dummyData = 'this is just some data'; endpointMock.replyOnce(() => { expect(dispatch.mock.calls).toEqual([['requestLoadBadges', dummyData]]); @@ -318,53 +282,44 @@ describe('Badges store actions', () => { return [500, '']; }); - actions - .loadBadges({ state, dispatch }, dummyData) - .then(() => done.fail('Expected Ajax call to fail!')) - .catch(() => { - expect(dispatch.mock.calls).toEqual([['receiveLoadBadgesError']]); - }) - .then(done) - .catch(done.fail); + await expect(actions.loadBadges({ state, dispatch }, dummyData)).rejects.toThrow(); + expect(dispatch.mock.calls).toEqual([['receiveLoadBadgesError']]); }); }); describe('requestRenderedBadge', () => { - it('commits REQUEST_RENDERED_BADGE', (done) => { - testAction( + it('commits REQUEST_RENDERED_BADGE', () => { + return testAction( actions.requestRenderedBadge, null, state, [{ type: mutationTypes.REQUEST_RENDERED_BADGE }], [], - done, ); }); }); describe('receiveRenderedBadge', () => { - it('commits RECEIVE_RENDERED_BADGE', (done) => { + it('commits RECEIVE_RENDERED_BADGE', () => { const dummyBadge = createDummyBadge(); - testAction( + return testAction( actions.receiveRenderedBadge, dummyBadge, state, [{ type: mutationTypes.RECEIVE_RENDERED_BADGE, payload: dummyBadge }], [], - done, ); }); }); describe('receiveRenderedBadgeError', () => { - it('commits RECEIVE_RENDERED_BADGE_ERROR', (done) => { - testAction( + it('commits RECEIVE_RENDERED_BADGE_ERROR', () => { + return testAction( actions.receiveRenderedBadgeError, null, state, [{ type: mutationTypes.RECEIVE_RENDERED_BADGE_ERROR }], [], - done, ); }); }); @@ -388,56 +343,41 @@ describe('Badges store actions', () => { dispatch = jest.fn(); }); - it('returns immediately if imageUrl is empty', (done) => { + it('returns immediately if imageUrl is empty', async () => { jest.spyOn(axios, 'get').mockImplementation(() => {}); badgeInForm.imageUrl = ''; - actions - .renderBadge({ state, dispatch }) - .then(() => { - expect(axios.get).not.toHaveBeenCalled(); - }) - .then(done) - .catch(done.fail); + await actions.renderBadge({ state, dispatch }); + expect(axios.get).not.toHaveBeenCalled(); }); - it('returns immediately if linkUrl is empty', (done) => { + it('returns immediately if linkUrl is empty', async () => { jest.spyOn(axios, 'get').mockImplementation(() => {}); badgeInForm.linkUrl = ''; - actions - .renderBadge({ state, dispatch }) - .then(() => { - expect(axios.get).not.toHaveBeenCalled(); - }) - .then(done) - .catch(done.fail); + await actions.renderBadge({ state, dispatch }); + expect(axios.get).not.toHaveBeenCalled(); }); - it('escapes user input', (done) => { + it('escapes user input', async () => { jest .spyOn(axios, 'get') .mockImplementation(() => Promise.resolve({ data: createDummyBadgeResponse() })); badgeInForm.imageUrl = '&make-sandwich=true'; badgeInForm.linkUrl = '<script>I am dangerous!</script>'; - actions - .renderBadge({ state, dispatch }) - .then(() => { - expect(axios.get.mock.calls.length).toBe(1); - const url = axios.get.mock.calls[0][0]; + await actions.renderBadge({ state, dispatch }); + expect(axios.get.mock.calls.length).toBe(1); + const url = axios.get.mock.calls[0][0]; - expect(url).toMatch(new RegExp(`^${dummyEndpointUrl}/render?`)); - expect(url).toMatch( - new RegExp('\\?link_url=%3Cscript%3EI%20am%20dangerous!%3C%2Fscript%3E&'), - ); - expect(url).toMatch(new RegExp('&image_url=%26make-sandwich%3Dtrue$')); - }) - .then(done) - .catch(done.fail); + expect(url).toMatch(new RegExp(`^${dummyEndpointUrl}/render?`)); + expect(url).toMatch( + new RegExp('\\?link_url=%3Cscript%3EI%20am%20dangerous!%3C%2Fscript%3E&'), + ); + expect(url).toMatch(new RegExp('&image_url=%26make-sandwich%3Dtrue$')); }); - it('dispatches requestRenderedBadge and receiveRenderedBadge for successful response', (done) => { + it('dispatches requestRenderedBadge and receiveRenderedBadge for successful response', async () => { const dummyReponse = createDummyBadgeResponse(); endpointMock.replyOnce(() => { expect(dispatch.mock.calls).toEqual([['requestRenderedBadge']]); @@ -445,71 +385,57 @@ describe('Badges store actions', () => { return [200, dummyReponse]; }); - actions - .renderBadge({ state, dispatch }) - .then(() => { - const renderedBadge = transformBackendBadge(dummyReponse); + await actions.renderBadge({ state, dispatch }); + const renderedBadge = transformBackendBadge(dummyReponse); - expect(dispatch.mock.calls).toEqual([['receiveRenderedBadge', renderedBadge]]); - }) - .then(done) - .catch(done.fail); + expect(dispatch.mock.calls).toEqual([['receiveRenderedBadge', renderedBadge]]); }); - it('dispatches requestRenderedBadge and receiveRenderedBadgeError for error response', (done) => { + it('dispatches requestRenderedBadge and receiveRenderedBadgeError for error response', async () => { endpointMock.replyOnce(() => { expect(dispatch.mock.calls).toEqual([['requestRenderedBadge']]); dispatch.mockClear(); return [500, '']; }); - actions - .renderBadge({ state, dispatch }) - .then(() => done.fail('Expected Ajax call to fail!')) - .catch(() => { - expect(dispatch.mock.calls).toEqual([['receiveRenderedBadgeError']]); - }) - .then(done) - .catch(done.fail); + await expect(actions.renderBadge({ state, dispatch })).rejects.toThrow(); + expect(dispatch.mock.calls).toEqual([['receiveRenderedBadgeError']]); }); }); describe('requestUpdatedBadge', () => { - it('commits REQUEST_UPDATED_BADGE', (done) => { - testAction( + it('commits REQUEST_UPDATED_BADGE', () => { + return testAction( actions.requestUpdatedBadge, null, state, [{ type: mutationTypes.REQUEST_UPDATED_BADGE }], [], - done, ); }); }); describe('receiveUpdatedBadge', () => { - it('commits RECEIVE_UPDATED_BADGE', (done) => { + it('commits RECEIVE_UPDATED_BADGE', () => { const updatedBadge = createDummyBadge(); - testAction( + return testAction( actions.receiveUpdatedBadge, updatedBadge, state, [{ type: mutationTypes.RECEIVE_UPDATED_BADGE, payload: updatedBadge }], [], - done, ); }); }); describe('receiveUpdatedBadgeError', () => { - it('commits RECEIVE_UPDATED_BADGE_ERROR', (done) => { - testAction( + it('commits RECEIVE_UPDATED_BADGE_ERROR', () => { + return testAction( actions.receiveUpdatedBadgeError, null, state, [{ type: mutationTypes.RECEIVE_UPDATED_BADGE_ERROR }], [], - done, ); }); }); @@ -529,7 +455,7 @@ describe('Badges store actions', () => { dispatch = jest.fn(); }); - it('dispatches requestUpdatedBadge and receiveUpdatedBadge for successful response', (done) => { + it('dispatches requestUpdatedBadge and receiveUpdatedBadge for successful response', async () => { const dummyResponse = createDummyBadgeResponse(); endpointMock.replyOnce((req) => { @@ -547,16 +473,11 @@ describe('Badges store actions', () => { }); const updatedBadge = transformBackendBadge(dummyResponse); - actions - .saveBadge({ state, dispatch }) - .then(() => { - expect(dispatch.mock.calls).toEqual([['receiveUpdatedBadge', updatedBadge]]); - }) - .then(done) - .catch(done.fail); + await actions.saveBadge({ state, dispatch }); + expect(dispatch.mock.calls).toEqual([['receiveUpdatedBadge', updatedBadge]]); }); - it('dispatches requestUpdatedBadge and receiveUpdatedBadgeError for error response', (done) => { + it('dispatches requestUpdatedBadge and receiveUpdatedBadgeError for error response', async () => { endpointMock.replyOnce((req) => { expect(req.data).toBe( JSON.stringify({ @@ -571,53 +492,44 @@ describe('Badges store actions', () => { return [500, '']; }); - actions - .saveBadge({ state, dispatch }) - .then(() => done.fail('Expected Ajax call to fail!')) - .catch(() => { - expect(dispatch.mock.calls).toEqual([['receiveUpdatedBadgeError']]); - }) - .then(done) - .catch(done.fail); + await expect(actions.saveBadge({ state, dispatch })).rejects.toThrow(); + expect(dispatch.mock.calls).toEqual([['receiveUpdatedBadgeError']]); }); }); describe('stopEditing', () => { - it('commits STOP_EDITING', (done) => { - testAction( + it('commits STOP_EDITING', () => { + return testAction( actions.stopEditing, null, state, [{ type: mutationTypes.STOP_EDITING }], [], - done, ); }); }); describe('updateBadgeInForm', () => { - it('commits UPDATE_BADGE_IN_FORM', (done) => { + it('commits UPDATE_BADGE_IN_FORM', () => { const dummyBadge = createDummyBadge(); - testAction( + return testAction( actions.updateBadgeInForm, dummyBadge, state, [{ type: mutationTypes.UPDATE_BADGE_IN_FORM, payload: dummyBadge }], [], - done, ); }); describe('updateBadgeInModal', () => { - it('commits UPDATE_BADGE_IN_MODAL', (done) => { + it('commits UPDATE_BADGE_IN_MODAL', () => { const dummyBadge = createDummyBadge(); - testAction( + return testAction( actions.updateBadgeInModal, dummyBadge, state, [{ type: mutationTypes.UPDATE_BADGE_IN_MODAL, payload: dummyBadge }], [], - done, ); }); }); |