debian-mirror-gitlab/spec/frontend/vue_shared/components/expand_button_spec.js

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

157 lines
4.2 KiB
JavaScript
Raw Normal View History

2020-03-13 15:44:24 +05:30
import { mount } from '@vue/test-utils';
2022-04-04 11:22:00 +05:30
import { nextTick } from 'vue';
2020-01-01 13:55:28 +05:30
import ExpandButton from '~/vue_shared/components/expand_button.vue';
const text = {
expanded: 'Expanded!',
short: 'Short',
};
describe('Expand button', () => {
let wrapper;
const expanderPrependEl = () => wrapper.find('.js-text-expander-prepend');
const expanderAppendEl = () => wrapper.find('.js-text-expander-append');
const factory = (options = {}) => {
2020-03-13 15:44:24 +05:30
wrapper = mount(ExpandButton, {
2020-01-01 13:55:28 +05:30
...options,
});
};
beforeEach(() => {
factory({
slots: {
expanded: `<p>${text.expanded}</p>`,
},
});
});
afterEach(() => {
wrapper.destroy();
});
it('renders the prepended collapse button', () => {
expect(expanderPrependEl().isVisible()).toBe(true);
expect(expanderAppendEl().isVisible()).toBe(false);
});
it('renders no text when short text is not provided', () => {
2022-08-27 11:52:29 +05:30
expect(wrapper.findComponent(ExpandButton).text()).toBe('');
2020-01-01 13:55:28 +05:30
});
it('does not render expanded text', () => {
2022-08-27 11:52:29 +05:30
expect(wrapper.findComponent(ExpandButton).text().trim()).not.toBe(text.short);
2020-01-01 13:55:28 +05:30
});
describe('when short text is provided', () => {
beforeEach(() => {
factory({
slots: {
expanded: `<p>${text.expanded}</p>`,
short: `<p>${text.short}</p>`,
},
});
});
it('renders short text', () => {
2022-08-27 11:52:29 +05:30
expect(wrapper.findComponent(ExpandButton).text().trim()).toBe(text.short);
2020-01-01 13:55:28 +05:30
});
it('renders button before text', () => {
expect(expanderPrependEl().isVisible()).toBe(true);
expect(expanderAppendEl().isVisible()).toBe(false);
2022-08-27 11:52:29 +05:30
expect(wrapper.findComponent(ExpandButton).element).toMatchSnapshot();
2020-01-01 13:55:28 +05:30
});
});
describe('on click', () => {
2022-04-04 11:22:00 +05:30
beforeEach(async () => {
2020-01-01 13:55:28 +05:30
expanderPrependEl().trigger('click');
2022-04-04 11:22:00 +05:30
await nextTick();
2020-01-01 13:55:28 +05:30
});
afterEach(() => {
expanderAppendEl().trigger('click');
});
it('renders only the append collapse button', () => {
expect(expanderAppendEl().isVisible()).toBe(true);
expect(expanderPrependEl().isVisible()).toBe(false);
});
it('renders the expanded text', () => {
2022-08-27 11:52:29 +05:30
expect(wrapper.findComponent(ExpandButton).text()).toContain(text.expanded);
2020-01-01 13:55:28 +05:30
});
describe('when short text is provided', () => {
2022-04-04 11:22:00 +05:30
beforeEach(async () => {
2020-01-01 13:55:28 +05:30
factory({
slots: {
expanded: `<p>${text.expanded}</p>`,
short: `<p>${text.short}</p>`,
},
});
expanderPrependEl().trigger('click');
2022-04-04 11:22:00 +05:30
await nextTick();
2020-01-01 13:55:28 +05:30
});
it('only renders expanded text', () => {
2022-08-27 11:52:29 +05:30
expect(wrapper.findComponent(ExpandButton).text().trim()).toBe(text.expanded);
2020-01-01 13:55:28 +05:30
});
it('renders button after text', () => {
expect(expanderPrependEl().isVisible()).toBe(false);
expect(expanderAppendEl().isVisible()).toBe(true);
2022-08-27 11:52:29 +05:30
expect(wrapper.findComponent(ExpandButton).element).toMatchSnapshot();
2020-01-01 13:55:28 +05:30
});
});
});
describe('append button', () => {
2022-04-04 11:22:00 +05:30
beforeEach(async () => {
2020-01-01 13:55:28 +05:30
expanderPrependEl().trigger('click');
2022-04-04 11:22:00 +05:30
await nextTick();
2020-01-01 13:55:28 +05:30
});
2022-04-04 11:22:00 +05:30
it('clicking hides itself and shows prepend', async () => {
2020-01-01 13:55:28 +05:30
expect(expanderAppendEl().isVisible()).toBe(true);
expanderAppendEl().trigger('click');
2020-03-13 15:44:24 +05:30
2022-04-04 11:22:00 +05:30
await nextTick();
expect(expanderPrependEl().isVisible()).toBe(true);
2020-01-01 13:55:28 +05:30
});
2022-04-04 11:22:00 +05:30
it('clicking hides expanded text', async () => {
2022-08-27 11:52:29 +05:30
expect(wrapper.findComponent(ExpandButton).text().trim()).toBe(text.expanded);
2020-01-01 13:55:28 +05:30
expanderAppendEl().trigger('click');
2020-03-13 15:44:24 +05:30
2022-04-04 11:22:00 +05:30
await nextTick();
2022-08-27 11:52:29 +05:30
expect(wrapper.findComponent(ExpandButton).text().trim()).not.toBe(text.expanded);
2020-01-01 13:55:28 +05:30
});
describe('when short text is provided', () => {
2022-04-04 11:22:00 +05:30
beforeEach(async () => {
2020-01-01 13:55:28 +05:30
factory({
slots: {
expanded: `<p>${text.expanded}</p>`,
short: `<p>${text.short}</p>`,
},
});
expanderPrependEl().trigger('click');
2022-04-04 11:22:00 +05:30
await nextTick();
2020-01-01 13:55:28 +05:30
});
2022-04-04 11:22:00 +05:30
it('clicking reveals short text', async () => {
2022-08-27 11:52:29 +05:30
expect(wrapper.findComponent(ExpandButton).text().trim()).toBe(text.expanded);
2020-01-01 13:55:28 +05:30
expanderAppendEl().trigger('click');
2020-03-13 15:44:24 +05:30
2022-04-04 11:22:00 +05:30
await nextTick();
2022-08-27 11:52:29 +05:30
expect(wrapper.findComponent(ExpandButton).text().trim()).toBe(text.short);
2020-01-01 13:55:28 +05:30
});
});
});
});