Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2019-10-01 18:06:05 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2019-10-01 18:06:05 +0300
commit05f4b2fb34dbb051b2ce5ddbc801ec42998c019c (patch)
tree0fd7a153f3ed7d00d40e428c08ab81ae3d863afe /spec/frontend/sidebar
parent9e27f0d920cc3891fa7644c5cc0bc280c519fb20 (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/frontend/sidebar')
-rw-r--r--spec/frontend/sidebar/__snapshots__/confidential_issue_sidebar_spec.js.snap8
-rw-r--r--spec/frontend/sidebar/confidential_issue_sidebar_spec.js98
2 files changed, 98 insertions, 8 deletions
diff --git a/spec/frontend/sidebar/__snapshots__/confidential_issue_sidebar_spec.js.snap b/spec/frontend/sidebar/__snapshots__/confidential_issue_sidebar_spec.js.snap
index 32d67120183..fd1cfdb1b04 100644
--- a/spec/frontend/sidebar/__snapshots__/confidential_issue_sidebar_spec.js.snap
+++ b/spec/frontend/sidebar/__snapshots__/confidential_issue_sidebar_spec.js.snap
@@ -49,6 +49,8 @@ exports[`Confidential Issue Sidebar Block renders for isConfidential = false and
</div>
</div>
+
+ <!---->
</div>
`;
@@ -111,6 +113,8 @@ exports[`Confidential Issue Sidebar Block renders for isConfidential = false and
</div>
</div>
+
+ <!---->
</div>
`;
@@ -163,6 +167,8 @@ exports[`Confidential Issue Sidebar Block renders for isConfidential = true and
</div>
</div>
+
+ <!---->
</div>
`;
@@ -225,5 +231,7 @@ exports[`Confidential Issue Sidebar Block renders for isConfidential = true and
</div>
</div>
+
+ <!---->
</div>
`;
diff --git a/spec/frontend/sidebar/confidential_issue_sidebar_spec.js b/spec/frontend/sidebar/confidential_issue_sidebar_spec.js
index 0fd50c0e989..1ec5a94ba68 100644
--- a/spec/frontend/sidebar/confidential_issue_sidebar_spec.js
+++ b/spec/frontend/sidebar/confidential_issue_sidebar_spec.js
@@ -2,15 +2,36 @@ import { shallowMount } from '@vue/test-utils';
import ConfidentialIssueSidebar from '~/sidebar/components/confidential/confidential_issue_sidebar.vue';
import { mockTracking, triggerEvent } from 'helpers/tracking_helper';
import EditForm from '~/sidebar/components/confidential/edit_form.vue';
+import SidebarService from '~/sidebar/services/sidebar_service';
+import createFlash from '~/flash';
+import RecaptchaModal from '~/vue_shared/components/recaptcha_modal';
+
+jest.mock('~/flash');
+jest.mock('~/sidebar/services/sidebar_service');
describe('Confidential Issue Sidebar Block', () => {
let wrapper;
- const createComponent = propsData => {
- const service = {
- update: () => Promise.resolve(true),
- };
+ const findRecaptchaModal = () => wrapper.find(RecaptchaModal);
+
+ const triggerUpdateConfidentialAttribute = () => {
+ wrapper.setData({ edit: true });
+ return (
+ // wait for edit form to become visible
+ wrapper.vm
+ .$nextTick()
+ .then(() => {
+ const editForm = wrapper.find(EditForm);
+ const { updateConfidentialAttribute } = editForm.props();
+ updateConfidentialAttribute();
+ })
+ // wait for reCAPTCHA modal to render
+ .then(() => wrapper.vm.$nextTick())
+ );
+ };
+ const createComponent = propsData => {
+ const service = new SidebarService();
wrapper = shallowMount(ConfidentialIssueSidebar, {
propsData: {
service,
@@ -20,6 +41,15 @@ describe('Confidential Issue Sidebar Block', () => {
});
};
+ beforeEach(() => {
+ jest.clearAllMocks();
+ jest.spyOn(window.location, 'reload').mockImplementation();
+ });
+
+ afterEach(() => {
+ wrapper.destroy();
+ });
+
it.each`
isConfidential | isEditable
${false} | ${false}
@@ -38,10 +68,6 @@ describe('Confidential Issue Sidebar Block', () => {
},
);
- afterEach(() => {
- wrapper.destroy();
- });
-
describe('if editable', () => {
beforeEach(() => {
createComponent({
@@ -81,5 +107,61 @@ describe('Confidential Issue Sidebar Block', () => {
property: 'confidentiality',
});
});
+
+ describe('for successful update', () => {
+ beforeEach(() => {
+ SidebarService.prototype.update.mockResolvedValue({ data: 'irrelevant' });
+ });
+
+ it('reloads the page', () =>
+ triggerUpdateConfidentialAttribute().then(() => {
+ expect(window.location.reload).toHaveBeenCalled();
+ }));
+
+ it('does not show an error message', () =>
+ triggerUpdateConfidentialAttribute().then(() => {
+ expect(createFlash).not.toHaveBeenCalled();
+ }));
+ });
+
+ describe('for update error', () => {
+ beforeEach(() => {
+ SidebarService.prototype.update.mockRejectedValue(new Error('updating failed!'));
+ });
+
+ it('does not reload the page', () =>
+ triggerUpdateConfidentialAttribute().then(() => {
+ expect(window.location.reload).not.toHaveBeenCalled();
+ }));
+
+ it('shows an error message', () =>
+ triggerUpdateConfidentialAttribute().then(() => {
+ expect(createFlash).toHaveBeenCalled();
+ }));
+ });
+
+ describe('for spam error', () => {
+ beforeEach(() => {
+ SidebarService.prototype.update.mockRejectedValue({ name: 'SpamError' });
+ });
+
+ it('does not reload the page', () =>
+ triggerUpdateConfidentialAttribute().then(() => {
+ expect(window.location.reload).not.toHaveBeenCalled();
+ }));
+
+ it('does not show an error message', () =>
+ triggerUpdateConfidentialAttribute().then(() => {
+ expect(createFlash).not.toHaveBeenCalled();
+ }));
+
+ it('shows a reCAPTCHA modal', () => {
+ expect(findRecaptchaModal().exists()).toBe(false);
+
+ return triggerUpdateConfidentialAttribute().then(() => {
+ expect(findRecaptchaModal().exists()).toBe(true);
+ });
+ });
+ });
});
});