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-04-15 18:42:17 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2020-04-15 18:42:17 +0300
commit44fdf983bd35328dd577d3d3650d14163ef3e2b6 (patch)
tree84ff300d056cfbabb5a0fe2a9cbaa80aaeab1cc5 /spec/frontend
parentbc9fa07b26184b5c94808f704db6ea1ac81bf4de (diff)
Add latest changes from gitlab-org/gitlab@12-10-stable-ee
Diffstat (limited to 'spec/frontend')
-rw-r--r--spec/frontend/registry/settings/components/registry_settings_app_spec.js50
-rw-r--r--spec/frontend/registry/settings/store/actions_spec.js11
-rw-r--r--spec/frontend/registry/settings/store/getters_spec.js16
-rw-r--r--spec/frontend/registry/settings/store/mutations_spec.js34
4 files changed, 77 insertions, 34 deletions
diff --git a/spec/frontend/registry/settings/components/registry_settings_app_spec.js b/spec/frontend/registry/settings/components/registry_settings_app_spec.js
index c83cc0c00dd..95f784c9727 100644
--- a/spec/frontend/registry/settings/components/registry_settings_app_spec.js
+++ b/spec/frontend/registry/settings/components/registry_settings_app_spec.js
@@ -1,10 +1,11 @@
import { shallowMount } from '@vue/test-utils';
-import { GlAlert } from '@gitlab/ui';
+import { GlAlert, GlSprintf, GlLink } from '@gitlab/ui';
import component from '~/registry/settings/components/registry_settings_app.vue';
import SettingsForm from '~/registry/settings/components/settings_form.vue';
import { createStore } from '~/registry/settings/store/';
-import { SET_IS_DISABLED } from '~/registry/settings/store/mutation_types';
+import { SET_SETTINGS, SET_INITIAL_STATE } from '~/registry/settings/store/mutation_types';
import { FETCH_SETTINGS_ERROR_MESSAGE } from '~/registry/shared/constants';
+import { stringifiedFormOptions } from '../../shared/mock_data';
describe('Registry Settings App', () => {
let wrapper;
@@ -13,14 +14,14 @@ describe('Registry Settings App', () => {
const findSettingsComponent = () => wrapper.find(SettingsForm);
const findAlert = () => wrapper.find(GlAlert);
- const mountComponent = ({ dispatchMock = 'mockResolvedValue', isDisabled = false } = {}) => {
- store = createStore();
- store.commit(SET_IS_DISABLED, isDisabled);
+ const mountComponent = ({ dispatchMock = 'mockResolvedValue' } = {}) => {
const dispatchSpy = jest.spyOn(store, 'dispatch');
- if (dispatchMock) {
- dispatchSpy[dispatchMock]();
- }
+ dispatchSpy[dispatchMock]();
+
wrapper = shallowMount(component, {
+ stubs: {
+ GlSprintf,
+ },
mocks: {
$toast: {
show: jest.fn(),
@@ -30,11 +31,16 @@ describe('Registry Settings App', () => {
});
};
+ beforeEach(() => {
+ store = createStore();
+ });
+
afterEach(() => {
wrapper.destroy();
});
it('renders', () => {
+ store.commit(SET_SETTINGS, { foo: 'bar' });
mountComponent();
expect(wrapper.element).toMatchSnapshot();
});
@@ -45,13 +51,15 @@ describe('Registry Settings App', () => {
});
it('renders the setting form', () => {
+ store.commit(SET_SETTINGS, { foo: 'bar' });
mountComponent();
expect(findSettingsComponent().exists()).toBe(true);
});
- describe('isDisabled', () => {
+ describe('the form is disabled', () => {
beforeEach(() => {
- mountComponent({ isDisabled: true });
+ store.commit(SET_SETTINGS, undefined);
+ mountComponent();
});
it('the form is hidden', () => {
@@ -59,9 +67,27 @@ describe('Registry Settings App', () => {
});
it('shows an alert', () => {
- expect(findAlert().html()).toContain(
- 'Currently, the Container Registry tag expiration feature is not available',
+ const text = findAlert().text();
+ expect(text).toContain(
+ 'The Container Registry tag expiration and retention policies for this project have not been enabled.',
);
+ expect(text).toContain('Please contact your administrator.');
+ });
+
+ describe('an admin is visiting the page', () => {
+ beforeEach(() => {
+ store.commit(SET_INITIAL_STATE, {
+ ...stringifiedFormOptions,
+ isAdmin: true,
+ adminSettingsPath: 'foo',
+ });
+ });
+
+ it('shows the admin part of the alert message', () => {
+ const sprintf = findAlert().find(GlSprintf);
+ expect(sprintf.text()).toBe('administration settings');
+ expect(sprintf.find(GlLink).attributes('href')).toBe('foo');
+ });
});
});
diff --git a/spec/frontend/registry/settings/store/actions_spec.js b/spec/frontend/registry/settings/store/actions_spec.js
index 5038dc82416..f92d10d087f 100644
--- a/spec/frontend/registry/settings/store/actions_spec.js
+++ b/spec/frontend/registry/settings/store/actions_spec.js
@@ -20,7 +20,7 @@ describe('Actions Registry Store', () => {
);
describe('receiveSettingsSuccess', () => {
- it('calls SET_SETTINGS when data is present', () => {
+ it('calls SET_SETTINGS', () => {
testAction(
actions.receiveSettingsSuccess,
'foo',
@@ -29,15 +29,6 @@ describe('Actions Registry Store', () => {
[],
);
});
- it('calls SET_IS_DISABLED when data is not present', () => {
- testAction(
- actions.receiveSettingsSuccess,
- null,
- {},
- [{ type: types.SET_IS_DISABLED, payload: true }],
- [],
- );
- });
});
describe('fetchSettings', () => {
diff --git a/spec/frontend/registry/settings/store/getters_spec.js b/spec/frontend/registry/settings/store/getters_spec.js
index 44631b97a39..944057ebc9f 100644
--- a/spec/frontend/registry/settings/store/getters_spec.js
+++ b/spec/frontend/registry/settings/store/getters_spec.js
@@ -29,7 +29,7 @@ describe('Getters registry settings store', () => {
});
});
- describe('getIsDisabled', () => {
+ describe('getIsEdited', () => {
it('returns false when original is equal to settings', () => {
const same = { foo: 'bar' };
expect(getters.getIsEdited({ original: same, settings: same })).toBe(false);
@@ -41,4 +41,18 @@ describe('Getters registry settings store', () => {
);
});
});
+
+ describe('getIsDisabled', () => {
+ it.each`
+ original | enableHistoricEntries | result
+ ${undefined} | ${false} | ${true}
+ ${{ foo: 'bar' }} | ${undefined} | ${false}
+ ${{}} | ${false} | ${false}
+ `(
+ 'returns $result when original is $original and enableHistoricEntries is $enableHistoricEntries',
+ ({ original, enableHistoricEntries, result }) => {
+ expect(getters.getIsDisabled({ original, enableHistoricEntries })).toBe(result);
+ },
+ );
+ });
});
diff --git a/spec/frontend/registry/settings/store/mutations_spec.js b/spec/frontend/registry/settings/store/mutations_spec.js
index 8ab0196fd4d..1d85e38eb36 100644
--- a/spec/frontend/registry/settings/store/mutations_spec.js
+++ b/spec/frontend/registry/settings/store/mutations_spec.js
@@ -12,14 +12,19 @@ describe('Mutations Registry Store', () => {
describe('SET_INITIAL_STATE', () => {
it('should set the initial state', () => {
- const expectedState = { ...mockState, projectId: 'foo', formOptions };
- mutations[types.SET_INITIAL_STATE](mockState, {
+ const payload = {
projectId: 'foo',
+ enableHistoricEntries: false,
+ adminSettingsPath: 'foo',
+ isAdmin: true,
+ };
+ const expectedState = { ...mockState, ...payload, formOptions };
+ mutations[types.SET_INITIAL_STATE](mockState, {
+ ...payload,
...stringifiedFormOptions,
});
- expect(mockState.projectId).toEqual(expectedState.projectId);
- expect(mockState.formOptions).toEqual(expectedState.formOptions);
+ expect(mockState).toEqual(expectedState);
});
});
@@ -41,6 +46,13 @@ describe('Mutations Registry Store', () => {
expect(mockState.settings).toEqual(expectedState.settings);
expect(mockState.original).toEqual(expectedState.settings);
});
+
+ it('should keep the default state when settings is not present', () => {
+ const originalSettings = { ...mockState.settings };
+ mutations[types.SET_SETTINGS](mockState);
+ expect(mockState.settings).toEqual(originalSettings);
+ expect(mockState.original).toEqual(undefined);
+ });
});
describe('RESET_SETTINGS', () => {
@@ -50,6 +62,13 @@ describe('Mutations Registry Store', () => {
mutations[types.RESET_SETTINGS](mockState);
expect(mockState.settings).toEqual(mockState.original);
});
+
+ it('if original is undefined it should initialize to empty object', () => {
+ mockState.settings = { foo: 'bar' };
+ mockState.original = undefined;
+ mutations[types.RESET_SETTINGS](mockState);
+ expect(mockState.settings).toEqual({});
+ });
});
describe('TOGGLE_LOADING', () => {
@@ -58,11 +77,4 @@ describe('Mutations Registry Store', () => {
expect(mockState.isLoading).toEqual(true);
});
});
-
- describe('SET_IS_DISABLED', () => {
- it('should set isDisabled', () => {
- mutations[types.SET_IS_DISABLED](mockState, true);
- expect(mockState.isDisabled).toEqual(true);
- });
- });
});