diff options
Diffstat (limited to 'spec/frontend/vue_mr_widget/components/approvals/approvals_summary_spec.js')
-rw-r--r-- | spec/frontend/vue_mr_widget/components/approvals/approvals_summary_spec.js | 53 |
1 files changed, 51 insertions, 2 deletions
diff --git a/spec/frontend/vue_mr_widget/components/approvals/approvals_summary_spec.js b/spec/frontend/vue_mr_widget/components/approvals/approvals_summary_spec.js index c9dea4394f9..c2606346292 100644 --- a/spec/frontend/vue_mr_widget/components/approvals/approvals_summary_spec.js +++ b/spec/frontend/vue_mr_widget/components/approvals/approvals_summary_spec.js @@ -1,14 +1,20 @@ import { shallowMount } from '@vue/test-utils'; import { toNounSeriesText } from '~/lib/utils/grammar'; import ApprovalsSummary from '~/vue_merge_request_widget/components/approvals/approvals_summary.vue'; -import { APPROVED_MESSAGE } from '~/vue_merge_request_widget/components/approvals/messages'; +import { + APPROVED_BY_OTHERS, + APPROVED_BY_YOU, + APPROVED_BY_YOU_AND_OTHERS, +} from '~/vue_merge_request_widget/components/approvals/messages'; import UserAvatarList from '~/vue_shared/components/user_avatar/user_avatar_list.vue'; +const exampleUserId = 1; const testApprovers = () => Array.from({ length: 5 }, (_, i) => i).map((id) => ({ id })); const testRulesLeft = () => ['Lorem', 'Ipsum', 'dolar & sit']; const TEST_APPROVALS_LEFT = 3; describe('MRWidget approvals summary', () => { + const originalUserId = gon.current_user_id; let wrapper; const createComponent = (props = {}) => { @@ -28,6 +34,7 @@ describe('MRWidget approvals summary', () => { afterEach(() => { wrapper.destroy(); wrapper = null; + gon.current_user_id = originalUserId; }); describe('when approved', () => { @@ -38,7 +45,7 @@ describe('MRWidget approvals summary', () => { }); it('shows approved message', () => { - expect(wrapper.text()).toContain(APPROVED_MESSAGE); + expect(wrapper.text()).toContain(APPROVED_BY_OTHERS); }); it('renders avatar list for approvers', () => { @@ -51,6 +58,48 @@ describe('MRWidget approvals summary', () => { }), ); }); + + describe('by the current user', () => { + beforeEach(() => { + gon.current_user_id = exampleUserId; + createComponent({ + approvers: [{ id: exampleUserId }], + approved: true, + }); + }); + + it('shows "Approved by you" message', () => { + expect(wrapper.text()).toContain(APPROVED_BY_YOU); + }); + }); + + describe('by the current user and others', () => { + beforeEach(() => { + gon.current_user_id = exampleUserId; + createComponent({ + approvers: [{ id: exampleUserId }, { id: exampleUserId + 1 }], + approved: true, + }); + }); + + it('shows "Approved by you and others" message', () => { + expect(wrapper.text()).toContain(APPROVED_BY_YOU_AND_OTHERS); + }); + }); + + describe('by other users than the current user', () => { + beforeEach(() => { + gon.current_user_id = exampleUserId; + createComponent({ + approvers: [{ id: exampleUserId + 1 }], + approved: true, + }); + }); + + it('shows "Approved by others" message', () => { + expect(wrapper.text()).toContain(APPROVED_BY_OTHERS); + }); + }); }); describe('when not approved', () => { |