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>2020-05-13 12:08:37 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2020-05-13 12:08:37 +0300
commit0e65189f85bb393e16e60335a42933beb0834295 (patch)
treece5160a3dd1ec3c06999d847783f5372c7b312fb /spec/frontend
parent2c1525618498a2aab2eed6a36f5045ce3f93ac6f (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/frontend')
-rw-r--r--spec/frontend/alert_management/components/alert_management_detail_spec.js20
-rw-r--r--spec/frontend/ci_variable_list/components/ci_variable_modal_spec.js7
-rw-r--r--spec/frontend/ci_variable_list/store/actions_spec.js10
-rw-r--r--spec/frontend/ci_variable_list/store/mutations_spec.js8
-rw-r--r--spec/frontend/helpers/event_hub_factory_spec.js96
-rw-r--r--spec/frontend/issuables_list/components/issuable_list_root_app_spec.js71
-rw-r--r--spec/frontend/issue_show/components/app_spec.js13
7 files changed, 202 insertions, 23 deletions
diff --git a/spec/frontend/alert_management/components/alert_management_detail_spec.js b/spec/frontend/alert_management/components/alert_management_detail_spec.js
index fa32707ead5..af524619913 100644
--- a/spec/frontend/alert_management/components/alert_management_detail_spec.js
+++ b/spec/frontend/alert_management/components/alert_management_detail_spec.js
@@ -1,5 +1,5 @@
import { shallowMount } from '@vue/test-utils';
-import { GlLoadingIcon } from '@gitlab/ui';
+import { GlAlert, GlLoadingIcon } from '@gitlab/ui';
import AlertDetails from '~/alert_management/components/alert_details.vue';
describe('AlertDetails', () => {
@@ -7,7 +7,7 @@ describe('AlertDetails', () => {
const newIssuePath = 'root/alerts/-/issues/new';
function mountComponent({
- alert = {},
+ data = { alert: {} },
createIssueFromAlertEnabled = false,
loading = false,
} = {}) {
@@ -18,7 +18,7 @@ describe('AlertDetails', () => {
newIssuePath,
},
data() {
- return { alert };
+ return data;
},
provide: {
glFeatures: { createIssueFromAlertEnabled },
@@ -46,7 +46,7 @@ describe('AlertDetails', () => {
describe('Alert details', () => {
describe('when alert is null', () => {
beforeEach(() => {
- mountComponent({ alert: null });
+ mountComponent({ data: { alert: null } });
});
it('shows an empty state', () => {
@@ -102,5 +102,17 @@ describe('AlertDetails', () => {
expect(wrapper.find(GlLoadingIcon).exists()).toBe(true);
});
});
+
+ describe('error state', () => {
+ it('displays a error state correctly', () => {
+ mountComponent({ data: { errored: true } });
+ expect(wrapper.find(GlAlert).exists()).toBe(true);
+ });
+
+ it('does not display an error when dismissed', () => {
+ mountComponent({ data: { errored: true, isErrorDismissed: true } });
+ expect(wrapper.find(GlAlert).exists()).toBe(false);
+ });
+ });
});
});
diff --git a/spec/frontend/ci_variable_list/components/ci_variable_modal_spec.js b/spec/frontend/ci_variable_list/components/ci_variable_modal_spec.js
index 7b8d69df35e..9179302f786 100644
--- a/spec/frontend/ci_variable_list/components/ci_variable_modal_spec.js
+++ b/spec/frontend/ci_variable_list/components/ci_variable_modal_spec.js
@@ -96,6 +96,13 @@ describe('Ci variable modal', () => {
findModal().vm.$emit('hidden');
expect(store.dispatch).toHaveBeenCalledWith('clearModal');
});
+
+ it('should dispatch setVariableProtected when admin settings are configured to protect variables', () => {
+ store.state.isProtectedByDefault = true;
+ findModal().vm.$emit('shown');
+
+ expect(store.dispatch).toHaveBeenCalledWith('setVariableProtected');
+ });
});
describe('Editing a variable', () => {
diff --git a/spec/frontend/ci_variable_list/store/actions_spec.js b/spec/frontend/ci_variable_list/store/actions_spec.js
index 84455612f0c..12b4311d0f5 100644
--- a/spec/frontend/ci_variable_list/store/actions_spec.js
+++ b/spec/frontend/ci_variable_list/store/actions_spec.js
@@ -75,6 +75,16 @@ describe('CI variable list store actions', () => {
});
});
+ describe('setVariableProtected', () => {
+ it('commits SET_VARIABLE_PROTECTED mutation', () => {
+ testAction(actions.setVariableProtected, {}, {}, [
+ {
+ type: types.SET_VARIABLE_PROTECTED,
+ },
+ ]);
+ });
+ });
+
describe('deleteVariable', () => {
it('dispatch correct actions on successful deleted variable', done => {
mock.onPatch(state.endpoint).reply(200);
diff --git a/spec/frontend/ci_variable_list/store/mutations_spec.js b/spec/frontend/ci_variable_list/store/mutations_spec.js
index ce0792d0353..1934d108957 100644
--- a/spec/frontend/ci_variable_list/store/mutations_spec.js
+++ b/spec/frontend/ci_variable_list/store/mutations_spec.js
@@ -97,4 +97,12 @@ describe('CI variable list mutations', () => {
expect(stateCopy.environments).toEqual(['dev', 'production', 'staging']);
});
});
+
+ describe('SET_VARIABLE_PROTECTED', () => {
+ it('should set protected value to true', () => {
+ mutations[types.SET_VARIABLE_PROTECTED](stateCopy);
+
+ expect(stateCopy.variable.protected).toBe(true);
+ });
+ });
});
diff --git a/spec/frontend/helpers/event_hub_factory_spec.js b/spec/frontend/helpers/event_hub_factory_spec.js
index ff00e29a40a..dcfec6b836a 100644
--- a/spec/frontend/helpers/event_hub_factory_spec.js
+++ b/spec/frontend/helpers/event_hub_factory_spec.js
@@ -1,13 +1,4 @@
import createEventHub from '~/helpers/event_hub_factory';
-import mitt from 'mitt';
-
-jest.mock('mitt');
-
-mitt.mockReturnValue({
- on: () => {},
- off: () => {},
- emit: () => {},
-});
describe('event bus factory', () => {
let eventBus;
@@ -20,17 +11,84 @@ describe('event bus factory', () => {
eventBus = null;
});
- it('creates an emitter', () => {
- expect(mitt).toHaveBeenCalled();
+ describe('underlying module', () => {
+ let mitt;
+
+ beforeEach(() => {
+ jest.resetModules();
+ jest.mock('mitt');
+
+ // eslint-disable-next-line global-require
+ mitt = require('mitt');
+ mitt.mockReturnValue(() => ({}));
+
+ const createEventHubActual = jest.requireActual('~/helpers/event_hub_factory').default;
+ eventBus = createEventHubActual();
+ });
+
+ it('creates an emitter', () => {
+ expect(mitt).toHaveBeenCalled();
+ });
+ });
+
+ describe('instance', () => {
+ it.each`
+ method
+ ${'on'}
+ ${'once'}
+ ${'off'}
+ ${'emit'}
+ `('binds $$method to $method ', ({ method }) => {
+ expect(typeof eventBus[method]).toBe('function');
+ expect(eventBus[method]).toBe(eventBus[`$${method}`]);
+ });
});
- it.each`
- method
- ${'on'}
- ${'off'}
- ${'emit'}
- `('binds $$method to $method ', ({ method }) => {
- expect(typeof eventBus[method]).toBe('function');
- expect(eventBus[method]).toBe(eventBus[`$${method}`]);
+ describe('once', () => {
+ const event = 'foobar';
+ let handler;
+
+ beforeEach(() => {
+ jest.spyOn(eventBus, 'on');
+ jest.spyOn(eventBus, 'off');
+ handler = jest.fn();
+ eventBus.once(event, handler);
+ });
+
+ it('calls on internally', () => {
+ expect(eventBus.on).toHaveBeenCalled();
+ });
+
+ it('calls handler when event is emitted', () => {
+ eventBus.emit(event);
+ expect(handler).toHaveBeenCalled();
+ });
+
+ it('calls off when event is emitted', () => {
+ eventBus.emit(event);
+ expect(eventBus.off).toHaveBeenCalled();
+ });
+
+ it('calls the handler only once when event is emitted multiple times', () => {
+ eventBus.emit(event);
+ eventBus.emit(event);
+ expect(handler).toHaveBeenCalledTimes(1);
+ });
+
+ describe('when the handler thows an error', () => {
+ beforeEach(() => {
+ handler = jest.fn().mockImplementation(() => {
+ throw new Error();
+ });
+ eventBus.once(event, handler);
+ });
+
+ it('calls off when event is emitted', () => {
+ expect(() => {
+ eventBus.emit(event);
+ }).toThrow();
+ expect(eventBus.off).toHaveBeenCalled();
+ });
+ });
});
});
diff --git a/spec/frontend/issuables_list/components/issuable_list_root_app_spec.js b/spec/frontend/issuables_list/components/issuable_list_root_app_spec.js
new file mode 100644
index 00000000000..fbf411d97fc
--- /dev/null
+++ b/spec/frontend/issuables_list/components/issuable_list_root_app_spec.js
@@ -0,0 +1,71 @@
+import { GlAlert } from '@gitlab/ui';
+import { shallowMount } from '@vue/test-utils';
+import Vue from 'vue';
+import IssuableListRootApp from '~/issuables_list/components/issuable_list_root_app.vue';
+
+const mountComponent = ({
+ canEdit = true,
+ isAlertShowing = true,
+ isInProgress = false,
+ isJiraConfigured = true,
+} = {}) =>
+ shallowMount(IssuableListRootApp, {
+ propsData: {
+ canEdit,
+ isJiraConfigured,
+ projectPath: 'gitlab-org/gitlab-test',
+ },
+ data() {
+ return {
+ isAlertShowing,
+ jiraImport: {
+ isInProgress,
+ },
+ };
+ },
+ });
+
+describe('IssuableListRootApp', () => {
+ let wrapper;
+
+ afterEach(() => {
+ wrapper.destroy();
+ wrapper = null;
+ });
+
+ describe('when Jira import is in progress', () => {
+ it('shows an alert that tells the user a Jira import is in progress', () => {
+ wrapper = mountComponent({
+ isInProgress: true,
+ });
+
+ expect(wrapper.find(GlAlert).text()).toBe(
+ 'Import in progress. Refresh page to see newly added issues.',
+ );
+ });
+ });
+
+ describe('when Jira import is not in progress', () => {
+ it('does not show an alert', () => {
+ wrapper = mountComponent();
+
+ expect(wrapper.contains(GlAlert)).toBe(false);
+ });
+ });
+
+ describe('alert message', () => {
+ it('is hidden when dismissed', () => {
+ wrapper = mountComponent({
+ isInProgress: true,
+ });
+
+ expect(wrapper.contains(GlAlert)).toBe(true);
+
+ wrapper.find(GlAlert).vm.$emit('dismiss');
+
+ return Vue.nextTick(() => {
+ expect(wrapper.contains(GlAlert)).toBe(false);
+ });
+ });
+ });
+});
diff --git a/spec/frontend/issue_show/components/app_spec.js b/spec/frontend/issue_show/components/app_spec.js
index 42076e8da5c..a59d6d35ded 100644
--- a/spec/frontend/issue_show/components/app_spec.js
+++ b/spec/frontend/issue_show/components/app_spec.js
@@ -221,6 +221,19 @@ describe('Issuable output', () => {
});
});
+ it('does not redirect if issue has not moved and user has switched tabs', () => {
+ jest.spyOn(vm.service, 'updateIssuable').mockResolvedValue({
+ data: {
+ web_url: '',
+ confidential: vm.isConfidential,
+ },
+ });
+
+ return vm.updateIssuable().then(() => {
+ expect(visitUrl).not.toHaveBeenCalled();
+ });
+ });
+
it('redirects if returned web_url has changed', () => {
jest.spyOn(vm.service, 'updateIssuable').mockResolvedValue({
data: {