2021-03-11 19:13:27 +05:30
|
|
|
import { GlButton } from '@gitlab/ui';
|
2021-12-11 22:18:48 +05:30
|
|
|
import { shallowMountExtended } from 'helpers/vue_test_utils_helper';
|
2021-11-11 11:23:49 +05:30
|
|
|
import SettingsBlock from '~/vue_shared/components/settings/settings_block.vue';
|
2021-03-11 19:13:27 +05:30
|
|
|
|
|
|
|
describe('Settings Block', () => {
|
|
|
|
let wrapper;
|
|
|
|
|
|
|
|
const mountComponent = (propsData) => {
|
2021-12-11 22:18:48 +05:30
|
|
|
wrapper = shallowMountExtended(SettingsBlock, {
|
2021-03-11 19:13:27 +05:30
|
|
|
propsData,
|
|
|
|
slots: {
|
|
|
|
title: '<div data-testid="title-slot"></div>',
|
|
|
|
description: '<div data-testid="description-slot"></div>',
|
|
|
|
default: '<div data-testid="default-slot"></div>',
|
|
|
|
},
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
wrapper.destroy();
|
|
|
|
});
|
|
|
|
|
2021-12-11 22:18:48 +05:30
|
|
|
const findDefaultSlot = () => wrapper.findByTestId('default-slot');
|
|
|
|
const findTitleSlot = () => wrapper.findByTestId('title-slot');
|
|
|
|
const findDescriptionSlot = () => wrapper.findByTestId('description-slot');
|
2021-11-11 11:23:49 +05:30
|
|
|
const findExpandButton = () => wrapper.findComponent(GlButton);
|
2021-12-11 22:18:48 +05:30
|
|
|
const findSectionTitleButton = () => wrapper.findByTestId('section-title-button');
|
|
|
|
// we are using a non js class for this finder because this class determine the component structure
|
|
|
|
const findSettingsContent = () => wrapper.find('.settings-content');
|
2021-11-11 11:23:49 +05:30
|
|
|
|
|
|
|
const expectExpandedState = ({ expanded = true } = {}) => {
|
|
|
|
const settingsExpandButton = findExpandButton();
|
|
|
|
|
|
|
|
expect(wrapper.classes('expanded')).toBe(expanded);
|
|
|
|
expect(settingsExpandButton.text()).toBe(
|
|
|
|
expanded ? SettingsBlock.i18n.collapseText : SettingsBlock.i18n.expandText,
|
|
|
|
);
|
|
|
|
expect(settingsExpandButton.attributes('aria-label')).toBe(
|
|
|
|
expanded ? SettingsBlock.i18n.collapseAriaLabel : SettingsBlock.i18n.expandAriaLabel,
|
|
|
|
);
|
|
|
|
};
|
2021-03-11 19:13:27 +05:30
|
|
|
|
|
|
|
it('renders the correct markup', () => {
|
|
|
|
mountComponent();
|
|
|
|
|
|
|
|
expect(wrapper.element).toMatchSnapshot();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('has a default slot', () => {
|
|
|
|
mountComponent();
|
|
|
|
|
|
|
|
expect(findDefaultSlot().exists()).toBe(true);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('has a title slot', () => {
|
|
|
|
mountComponent();
|
|
|
|
|
|
|
|
expect(findTitleSlot().exists()).toBe(true);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('has a description slot', () => {
|
|
|
|
mountComponent();
|
|
|
|
|
|
|
|
expect(findDescriptionSlot().exists()).toBe(true);
|
|
|
|
});
|
|
|
|
|
2021-12-11 22:18:48 +05:30
|
|
|
it('content is hidden before first expansion', async () => {
|
|
|
|
// this is a regression test for the bug described here: https://gitlab.com/gitlab-org/gitlab/-/issues/331774
|
|
|
|
mountComponent();
|
|
|
|
|
|
|
|
// content is hidden
|
|
|
|
expect(findDefaultSlot().isVisible()).toBe(false);
|
|
|
|
|
|
|
|
// expand
|
|
|
|
await findSectionTitleButton().trigger('click');
|
|
|
|
|
|
|
|
// content is visible
|
|
|
|
expect(findDefaultSlot().isVisible()).toBe(true);
|
|
|
|
|
|
|
|
// collapse
|
|
|
|
await findSectionTitleButton().trigger('click');
|
|
|
|
|
|
|
|
// content is still visible (and we have a closing animation)
|
|
|
|
expect(findDefaultSlot().isVisible()).toBe(true);
|
|
|
|
});
|
|
|
|
|
2021-04-17 20:07:23 +05:30
|
|
|
describe('slide animation behaviour', () => {
|
|
|
|
it('is animated by default', () => {
|
|
|
|
mountComponent();
|
|
|
|
|
|
|
|
expect(wrapper.classes('no-animate')).toBe(false);
|
|
|
|
});
|
|
|
|
|
|
|
|
it.each`
|
|
|
|
slideAnimated | noAnimatedClass
|
|
|
|
${true} | ${false}
|
|
|
|
${false} | ${true}
|
|
|
|
`(
|
|
|
|
'sets the correct state when slideAnimated is $slideAnimated',
|
|
|
|
({ slideAnimated, noAnimatedClass }) => {
|
|
|
|
mountComponent({ slideAnimated });
|
|
|
|
|
|
|
|
expect(wrapper.classes('no-animate')).toBe(noAnimatedClass);
|
|
|
|
},
|
|
|
|
);
|
2021-12-11 22:18:48 +05:30
|
|
|
|
|
|
|
it('sets the animating class only during the animation', async () => {
|
|
|
|
mountComponent();
|
|
|
|
|
|
|
|
expect(wrapper.classes('animating')).toBe(false);
|
|
|
|
|
|
|
|
await findSectionTitleButton().trigger('click');
|
|
|
|
|
|
|
|
expect(wrapper.classes('animating')).toBe(true);
|
|
|
|
|
|
|
|
await findSettingsContent().trigger('animationend');
|
|
|
|
|
|
|
|
expect(wrapper.classes('animating')).toBe(false);
|
|
|
|
});
|
2021-04-17 20:07:23 +05:30
|
|
|
});
|
|
|
|
|
2021-03-11 19:13:27 +05:30
|
|
|
describe('expanded behaviour', () => {
|
|
|
|
it('is collapsed by default', () => {
|
|
|
|
mountComponent();
|
|
|
|
|
2021-11-11 11:23:49 +05:30
|
|
|
expectExpandedState({ expanded: false });
|
2021-03-11 19:13:27 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
it('adds expanded class when the expand button is clicked', async () => {
|
|
|
|
mountComponent();
|
|
|
|
|
|
|
|
await findExpandButton().vm.$emit('click');
|
|
|
|
|
2021-11-11 11:23:49 +05:30
|
|
|
expectExpandedState({ expanded: true });
|
2021-03-11 19:13:27 +05:30
|
|
|
});
|
|
|
|
|
2021-11-11 11:23:49 +05:30
|
|
|
it('adds expanded class when the section title is clicked', async () => {
|
|
|
|
mountComponent();
|
2021-03-11 19:13:27 +05:30
|
|
|
|
2021-11-11 11:23:49 +05:30
|
|
|
await findSectionTitleButton().trigger('click');
|
2021-03-11 19:13:27 +05:30
|
|
|
|
2021-11-11 11:23:49 +05:30
|
|
|
expectExpandedState({ expanded: true });
|
|
|
|
});
|
2021-03-11 19:13:27 +05:30
|
|
|
|
2021-11-11 11:23:49 +05:30
|
|
|
describe('when `collapsible` is `false`', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
mountComponent({ collapsible: false });
|
|
|
|
});
|
2021-03-11 19:13:27 +05:30
|
|
|
|
2021-11-11 11:23:49 +05:30
|
|
|
it('does not render clickable section title', () => {
|
|
|
|
expect(findSectionTitleButton().exists()).toBe(false);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('contains expanded class', () => {
|
|
|
|
expect(wrapper.classes('expanded')).toBe(true);
|
|
|
|
});
|
2021-03-11 19:13:27 +05:30
|
|
|
|
2021-11-11 11:23:49 +05:30
|
|
|
it('does not render expand toggle button', () => {
|
|
|
|
expect(findExpandButton().exists()).toBe(false);
|
|
|
|
});
|
2021-03-11 19:13:27 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|