diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-02-18 09:45:46 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-02-18 09:45:46 +0000 |
commit | a7b3560714b4d9cc4ab32dffcd1f74a284b93580 (patch) | |
tree | 7452bd5c3545c2fa67a28aa013835fb4fa071baf /spec/frontend/emoji/awards_app/store/actions_spec.js | |
parent | ee9173579ae56a3dbfe5afe9f9410c65bb327ca7 (diff) | |
download | gitlab-ce-a7b3560714b4d9cc4ab32dffcd1f74a284b93580.tar.gz |
Add latest changes from gitlab-org/gitlab@14-8-stable-eev14.8.0-rc42
Diffstat (limited to 'spec/frontend/emoji/awards_app/store/actions_spec.js')
-rw-r--r-- | spec/frontend/emoji/awards_app/store/actions_spec.js | 37 |
1 files changed, 31 insertions, 6 deletions
diff --git a/spec/frontend/emoji/awards_app/store/actions_spec.js b/spec/frontend/emoji/awards_app/store/actions_spec.js index 02b643244d2..0761256ed23 100644 --- a/spec/frontend/emoji/awards_app/store/actions_spec.js +++ b/spec/frontend/emoji/awards_app/store/actions_spec.js @@ -87,6 +87,26 @@ describe('Awards app actions', () => { describe('toggleAward', () => { let mock; + const optimisticAwardId = Number.MAX_SAFE_INTEGER - 1; + const makeOptimisticAddMutation = ( + id = optimisticAwardId, + name = null, + userId = window.gon.current_user_id, + ) => ({ + type: 'ADD_NEW_AWARD', + payload: { + id, + name, + user: { + id: userId, + }, + }, + }); + const makeOptimisticRemoveMutation = (id = optimisticAwardId) => ({ + type: 'REMOVE_AWARD', + payload: id, + }); + beforeEach(() => { mock = new MockAdapter(axios); }); @@ -110,8 +130,10 @@ describe('Awards app actions', () => { mock.onPost(`${relativeRootUrl || ''}/awards`).reply(200, { id: 1 }); }); - it('commits ADD_NEW_AWARD', async () => { + it('adds an optimistic award, removes it, and then commits ADD_NEW_AWARD', async () => { testAction(actions.toggleAward, null, { path: '/awards', awards: [] }, [ + makeOptimisticAddMutation(), + makeOptimisticRemoveMutation(), { type: 'ADD_NEW_AWARD', payload: { id: 1 } }, ]); }); @@ -127,7 +149,7 @@ describe('Awards app actions', () => { actions.toggleAward, null, { path: '/awards', awards: [] }, - [], + [makeOptimisticAddMutation(), makeOptimisticRemoveMutation()], [], () => { expect(Sentry.captureException).toHaveBeenCalled(); @@ -137,7 +159,7 @@ describe('Awards app actions', () => { }); }); - describe('removing a award', () => { + describe('removing an award', () => { const mockData = { id: 1, name: 'thumbsup', user: { id: 1 } }; describe('success', () => { @@ -160,6 +182,9 @@ describe('Awards app actions', () => { }); describe('error', () => { + const currentUserId = 1; + const name = 'thumbsup'; + beforeEach(() => { mock.onDelete(`${relativeRootUrl || ''}/awards/1`).reply(500); }); @@ -167,13 +192,13 @@ describe('Awards app actions', () => { it('calls Sentry.captureException', async () => { await testAction( actions.toggleAward, - 'thumbsup', + name, { path: '/awards', - currentUserId: 1, + currentUserId, awards: [mockData], }, - [], + [makeOptimisticRemoveMutation(1), makeOptimisticAddMutation(1, name, currentUserId)], [], () => { expect(Sentry.captureException).toHaveBeenCalled(); |