summaryrefslogtreecommitdiff
path: root/spec/frontend/vue_mr_widget/components/approvals/approvals_spec.js
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2022-04-20 10:00:54 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2022-04-20 10:00:54 +0000
commit3cccd102ba543e02725d247893729e5c73b38295 (patch)
treef36a04ec38517f5deaaacb5acc7d949688d1e187 /spec/frontend/vue_mr_widget/components/approvals/approvals_spec.js
parent205943281328046ef7b4528031b90fbda70c75ac (diff)
downloadgitlab-ce-3cccd102ba543e02725d247893729e5c73b38295.tar.gz
Add latest changes from gitlab-org/gitlab@14-10-stable-eev14.10.0-rc42
Diffstat (limited to 'spec/frontend/vue_mr_widget/components/approvals/approvals_spec.js')
-rw-r--r--spec/frontend/vue_mr_widget/components/approvals/approvals_spec.js70
1 files changed, 33 insertions, 37 deletions
diff --git a/spec/frontend/vue_mr_widget/components/approvals/approvals_spec.js b/spec/frontend/vue_mr_widget/components/approvals/approvals_spec.js
index 36850e623c7..4985417ad99 100644
--- a/spec/frontend/vue_mr_widget/components/approvals/approvals_spec.js
+++ b/spec/frontend/vue_mr_widget/components/approvals/approvals_spec.js
@@ -1,3 +1,4 @@
+import { nextTick } from 'vue';
import { GlButton } from '@gitlab/ui';
import { shallowMount } from '@vue/test-utils';
import createFlash from '~/flash';
@@ -28,11 +29,6 @@ const testApprovals = () => ({
});
const testApprovalRulesResponse = () => ({ rules: [{ id: 2 }] });
-// For some reason, the `Promise.resolve()` needs to be deferred
-// or the timing doesn't work.
-const tick = () => Promise.resolve();
-const waitForTick = (done) => tick().then(done).catch(done.fail);
-
describe('MRWidget approvals', () => {
let wrapper;
let service;
@@ -105,7 +101,7 @@ describe('MRWidget approvals', () => {
// eslint-disable-next-line no-restricted-syntax
wrapper.setData({ fetchingApprovals: true });
- return tick().then(() => {
+ return nextTick().then(() => {
expect(wrapper.text()).toContain(FETCH_LOADING);
});
});
@@ -116,10 +112,10 @@ describe('MRWidget approvals', () => {
});
describe('when fetch approvals error', () => {
- beforeEach((done) => {
+ beforeEach(() => {
jest.spyOn(service, 'fetchApprovals').mockReturnValue(Promise.reject());
createComponent();
- waitForTick(done);
+ return nextTick();
});
it('still shows loading message', () => {
@@ -133,13 +129,13 @@ describe('MRWidget approvals', () => {
describe('action button', () => {
describe('when mr is closed', () => {
- beforeEach((done) => {
+ beforeEach(() => {
mr.isOpen = false;
mr.approvals.user_has_approved = false;
mr.approvals.user_can_approve = true;
createComponent();
- waitForTick(done);
+ return nextTick();
});
it('action is not rendered', () => {
@@ -148,12 +144,12 @@ describe('MRWidget approvals', () => {
});
describe('when user cannot approve', () => {
- beforeEach((done) => {
+ beforeEach(() => {
mr.approvals.user_has_approved = false;
mr.approvals.user_can_approve = false;
createComponent();
- waitForTick(done);
+ return nextTick();
});
it('action is not rendered', () => {
@@ -168,9 +164,9 @@ describe('MRWidget approvals', () => {
});
describe('and MR is unapproved', () => {
- beforeEach((done) => {
+ beforeEach(() => {
createComponent();
- waitForTick(done);
+ return nextTick();
});
it('approve action is rendered', () => {
@@ -188,10 +184,10 @@ describe('MRWidget approvals', () => {
});
describe('with no approvers', () => {
- beforeEach((done) => {
+ beforeEach(() => {
mr.approvals.approved_by = [];
createComponent();
- waitForTick(done);
+ return nextTick();
});
it('approve action (with inverted style) is rendered', () => {
@@ -204,10 +200,10 @@ describe('MRWidget approvals', () => {
});
describe('with approvers', () => {
- beforeEach((done) => {
+ beforeEach(() => {
mr.approvals.approved_by = [{ user: { id: 7 } }];
createComponent();
- waitForTick(done);
+ return nextTick();
});
it('approve additionally action is rendered', () => {
@@ -221,9 +217,9 @@ describe('MRWidget approvals', () => {
});
describe('when approve action is clicked', () => {
- beforeEach((done) => {
+ beforeEach(() => {
createComponent();
- waitForTick(done);
+ return nextTick();
});
it('shows loading icon', () => {
@@ -234,15 +230,15 @@ describe('MRWidget approvals', () => {
action.vm.$emit('click');
- return tick().then(() => {
+ return nextTick().then(() => {
expect(action.props('loading')).toBe(true);
});
});
describe('and after loading', () => {
- beforeEach((done) => {
+ beforeEach(() => {
findAction().vm.$emit('click');
- waitForTick(done);
+ return nextTick();
});
it('calls service approve', () => {
@@ -259,10 +255,10 @@ describe('MRWidget approvals', () => {
});
describe('and error', () => {
- beforeEach((done) => {
+ beforeEach(() => {
jest.spyOn(service, 'approveMergeRequest').mockReturnValue(Promise.reject());
findAction().vm.$emit('click');
- waitForTick(done);
+ return nextTick();
});
it('flashes error message', () => {
@@ -273,12 +269,12 @@ describe('MRWidget approvals', () => {
});
describe('when user has approved', () => {
- beforeEach((done) => {
+ beforeEach(() => {
mr.approvals.user_has_approved = true;
mr.approvals.user_can_approve = false;
createComponent();
- waitForTick(done);
+ return nextTick();
});
it('revoke action is rendered', () => {
@@ -291,9 +287,9 @@ describe('MRWidget approvals', () => {
describe('when revoke action is clicked', () => {
describe('and successful', () => {
- beforeEach((done) => {
+ beforeEach(() => {
findAction().vm.$emit('click');
- waitForTick(done);
+ return nextTick();
});
it('calls service unapprove', () => {
@@ -310,10 +306,10 @@ describe('MRWidget approvals', () => {
});
describe('and error', () => {
- beforeEach((done) => {
+ beforeEach(() => {
jest.spyOn(service, 'unapproveMergeRequest').mockReturnValue(Promise.reject());
findAction().vm.$emit('click');
- waitForTick(done);
+ return nextTick();
});
it('flashes error message', () => {
@@ -333,11 +329,11 @@ describe('MRWidget approvals', () => {
});
describe('and can approve', () => {
- beforeEach((done) => {
+ beforeEach(() => {
mr.approvals.user_can_approve = true;
createComponent();
- waitForTick(done);
+ return nextTick();
});
it('is shown', () => {
@@ -350,11 +346,11 @@ describe('MRWidget approvals', () => {
});
describe('and cannot approve', () => {
- beforeEach((done) => {
+ beforeEach(() => {
mr.approvals.user_can_approve = false;
createComponent();
- waitForTick(done);
+ return nextTick();
});
it('is shown', () => {
@@ -369,9 +365,9 @@ describe('MRWidget approvals', () => {
});
describe('approvals summary', () => {
- beforeEach((done) => {
+ beforeEach(() => {
createComponent();
- waitForTick(done);
+ return nextTick();
});
it('is rendered with props', () => {