84 lines
2.3 KiB
JavaScript
84 lines
2.3 KiB
JavaScript
import { shallowMount } from '@vue/test-utils';
|
|
import { GlButton, GlLoadingIcon } from '@gitlab/ui';
|
|
|
|
import PublishToolbar from '~/static_site_editor/components/publish_toolbar.vue';
|
|
|
|
import { returnUrl } from '../mock_data';
|
|
|
|
describe('Static Site Editor Toolbar', () => {
|
|
let wrapper;
|
|
|
|
const buildWrapper = (propsData = {}) => {
|
|
wrapper = shallowMount(PublishToolbar, {
|
|
propsData: {
|
|
saveable: false,
|
|
...propsData,
|
|
},
|
|
});
|
|
};
|
|
|
|
const findReturnUrlLink = () => wrapper.find({ ref: 'returnUrlLink' });
|
|
const findSaveChangesButton = () => wrapper.find(GlButton);
|
|
const findLoadingIndicator = () => wrapper.find(GlLoadingIcon);
|
|
|
|
beforeEach(() => {
|
|
buildWrapper();
|
|
});
|
|
|
|
afterEach(() => {
|
|
wrapper.destroy();
|
|
});
|
|
|
|
it('renders Submit Changes button', () => {
|
|
expect(findSaveChangesButton().exists()).toBe(true);
|
|
});
|
|
|
|
it('disables Submit Changes button', () => {
|
|
expect(findSaveChangesButton().attributes('disabled')).toBe('true');
|
|
});
|
|
|
|
it('does not display saving changes indicator', () => {
|
|
expect(findLoadingIndicator().classes()).toContain('invisible');
|
|
});
|
|
|
|
it('does not render returnUrl link', () => {
|
|
expect(findReturnUrlLink().exists()).toBe(false);
|
|
});
|
|
|
|
it('renders returnUrl link when returnUrl prop exists', () => {
|
|
buildWrapper({ returnUrl });
|
|
|
|
expect(findReturnUrlLink().exists()).toBe(true);
|
|
expect(findReturnUrlLink().attributes('href')).toBe(returnUrl);
|
|
});
|
|
|
|
describe('when saveable', () => {
|
|
it('enables Submit Changes button', () => {
|
|
buildWrapper({ saveable: true });
|
|
|
|
expect(findSaveChangesButton().attributes('disabled')).toBeFalsy();
|
|
});
|
|
});
|
|
|
|
describe('when saving changes', () => {
|
|
beforeEach(() => {
|
|
buildWrapper({ saveable: true, savingChanges: true });
|
|
});
|
|
|
|
it('disables Submit Changes button', () => {
|
|
expect(findSaveChangesButton().attributes('disabled')).toBe('true');
|
|
});
|
|
|
|
it('displays saving changes indicator', () => {
|
|
expect(findLoadingIndicator().classes()).not.toContain('invisible');
|
|
});
|
|
});
|
|
|
|
it('emits submit event when submit button is clicked', () => {
|
|
buildWrapper({ saveable: true });
|
|
|
|
findSaveChangesButton().vm.$emit('click');
|
|
|
|
expect(wrapper.emitted('submit')).toHaveLength(1);
|
|
});
|
|
});
|