summaryrefslogtreecommitdiff
path: root/spec/frontend/registry/settings/components
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-02-04 12:09:00 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2020-02-04 12:09:00 +0000
commit88a0824944720b6edaaef56376713541b9a02118 (patch)
treef5fcc4f9755f249779cda9a8f02902d734af6e7e /spec/frontend/registry/settings/components
parent7d19df2d34a9803d9f077c16315ba919b7ae2aa2 (diff)
downloadgitlab-ce-88a0824944720b6edaaef56376713541b9a02118.tar.gz
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/frontend/registry/settings/components')
-rw-r--r--spec/frontend/registry/settings/components/settings_form_spec.js96
1 files changed, 84 insertions, 12 deletions
diff --git a/spec/frontend/registry/settings/components/settings_form_spec.js b/spec/frontend/registry/settings/components/settings_form_spec.js
index eefb0313a0b..2b3e529b283 100644
--- a/spec/frontend/registry/settings/components/settings_form_spec.js
+++ b/spec/frontend/registry/settings/components/settings_form_spec.js
@@ -1,7 +1,7 @@
import { shallowMount } from '@vue/test-utils';
import Tracking from '~/tracking';
import component from '~/registry/settings/components/settings_form.vue';
-import expirationPolicyForm from '~/registry/shared/components/expiration_policy_form.vue';
+import expirationPolicyFields from '~/registry/shared/components/expiration_policy_fields.vue';
import { createStore } from '~/registry/settings/store/';
import {
UPDATE_SETTINGS_ERROR_MESSAGE,
@@ -14,14 +14,34 @@ describe('Settings Form', () => {
let store;
let dispatchSpy;
+ const GlLoadingIcon = { name: 'gl-loading-icon-stub', template: '<svg></svg>' };
+ const GlCard = {
+ name: 'gl-card-stub',
+ template: `
+ <div>
+ <slot name="header"></slot>
+ <slot></slot>
+ <slot name="footer"></slot>
+ </div>
+ `,
+ };
+
const trackingPayload = {
label: 'docker_container_retention_and_expiration_policies',
};
- const findForm = () => wrapper.find(expirationPolicyForm);
+ const findForm = () => wrapper.find({ ref: 'form-element' });
+ const findFields = () => wrapper.find(expirationPolicyFields);
+ const findCancelButton = () => wrapper.find({ ref: 'cancel-button' });
+ const findSaveButton = () => wrapper.find({ ref: 'save-button' });
+ const findLoadingIcon = (parent = wrapper) => parent.find(GlLoadingIcon);
const mountComponent = () => {
wrapper = shallowMount(component, {
+ stubs: {
+ GlCard,
+ GlLoadingIcon,
+ },
mocks: {
$toast: {
show: jest.fn(),
@@ -47,46 +67,50 @@ describe('Settings Form', () => {
let form;
beforeEach(() => {
form = findForm();
+ dispatchSpy.mockReturnValue();
});
describe('data binding', () => {
it('v-model change update the settings property', () => {
- dispatchSpy.mockReturnValue();
- form.vm.$emit('input', 'foo');
+ findFields().vm.$emit('input', 'foo');
expect(dispatchSpy).toHaveBeenCalledWith('updateSettings', { settings: 'foo' });
});
});
describe('form reset event', () => {
+ beforeEach(() => {
+ form.trigger('reset');
+ });
it('calls the appropriate function', () => {
- dispatchSpy.mockReturnValue();
- form.vm.$emit('reset');
expect(dispatchSpy).toHaveBeenCalledWith('resetSettings');
});
it('tracks the reset event', () => {
- dispatchSpy.mockReturnValue();
- form.vm.$emit('reset');
expect(Tracking.event).toHaveBeenCalledWith(undefined, 'reset_form', trackingPayload);
});
});
describe('form submit event ', () => {
+ it('save has type submit', () => {
+ mountComponent();
+ expect(findSaveButton().attributes('type')).toBe('submit');
+ });
+
it('dispatches the saveSettings action', () => {
dispatchSpy.mockResolvedValue();
- form.vm.$emit('submit');
+ form.trigger('submit');
expect(dispatchSpy).toHaveBeenCalledWith('saveSettings');
});
it('tracks the submit event', () => {
dispatchSpy.mockResolvedValue();
- form.vm.$emit('submit');
+ form.trigger('submit');
expect(Tracking.event).toHaveBeenCalledWith(undefined, 'submit_form', trackingPayload);
});
it('show a success toast when submit succeed', () => {
dispatchSpy.mockResolvedValue();
- form.vm.$emit('submit');
+ form.trigger('submit');
return wrapper.vm.$nextTick().then(() => {
expect(wrapper.vm.$toast.show).toHaveBeenCalledWith(UPDATE_SETTINGS_SUCCESS_MESSAGE, {
type: 'success',
@@ -96,7 +120,7 @@ describe('Settings Form', () => {
it('show an error toast when submit fails', () => {
dispatchSpy.mockRejectedValue();
- form.vm.$emit('submit');
+ form.trigger('submit');
return wrapper.vm.$nextTick().then(() => {
expect(wrapper.vm.$toast.show).toHaveBeenCalledWith(UPDATE_SETTINGS_ERROR_MESSAGE, {
type: 'error',
@@ -105,4 +129,52 @@ describe('Settings Form', () => {
});
});
});
+
+ describe('form actions', () => {
+ describe('cancel button', () => {
+ beforeEach(() => {
+ store.commit('SET_SETTINGS', { foo: 'bar' });
+ });
+
+ it('has type reset', () => {
+ expect(findCancelButton().attributes('type')).toBe('reset');
+ });
+
+ it('is disabled when isEdited is false', () =>
+ wrapper.vm.$nextTick().then(() => {
+ expect(findCancelButton().attributes('disabled')).toBe('true');
+ }));
+
+ it('is disabled isLoading is true', () => {
+ store.commit('TOGGLE_LOADING');
+ store.commit('UPDATE_SETTINGS', { settings: { foo: 'baz' } });
+ return wrapper.vm.$nextTick().then(() => {
+ expect(findCancelButton().attributes('disabled')).toBe('true');
+ store.commit('TOGGLE_LOADING');
+ });
+ });
+
+ it('is enabled when isLoading is false and isEdited is true', () => {
+ store.commit('UPDATE_SETTINGS', { settings: { foo: 'baz' } });
+ return wrapper.vm.$nextTick().then(() => {
+ expect(findCancelButton().attributes('disabled')).toBe(undefined);
+ });
+ });
+ });
+
+ describe('when isLoading is true', () => {
+ beforeEach(() => {
+ store.commit('TOGGLE_LOADING');
+ });
+ afterEach(() => {
+ store.commit('TOGGLE_LOADING');
+ });
+
+ it('submit button is disabled and shows a spinner', () => {
+ const button = findSaveButton();
+ expect(button.attributes('disabled')).toBeTruthy();
+ expect(findLoadingIcon(button).exists()).toBe(true);
+ });
+ });
+ });
});