debian-mirror-gitlab/spec/frontend/jobs/components/log/collapsible_section_spec.js

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

72 lines
2 KiB
JavaScript
Raw Normal View History

2019-12-21 20:55:43 +05:30
import { mount } from '@vue/test-utils';
2022-04-04 11:22:00 +05:30
import { nextTick } from 'vue';
2020-07-28 23:09:34 +05:30
import CollapsibleSection from '~/jobs/components/log/collapsible_section.vue';
2019-12-21 20:55:43 +05:30
import { collapsibleSectionClosed, collapsibleSectionOpened } from './mock_data';
describe('Job Log Collapsible Section', () => {
let wrapper;
2021-11-18 22:05:49 +05:30
const jobLogEndpoint = 'jobs/335';
2019-12-21 20:55:43 +05:30
const findCollapsibleLine = () => wrapper.find('.collapsible-line');
const findCollapsibleLineSvg = () => wrapper.find('.collapsible-line svg');
const createComponent = (props = {}) => {
2020-07-28 23:09:34 +05:30
wrapper = mount(CollapsibleSection, {
2019-12-21 20:55:43 +05:30
propsData: {
...props,
},
});
};
describe('with closed section', () => {
beforeEach(() => {
createComponent({
section: collapsibleSectionClosed,
2021-11-18 22:05:49 +05:30
jobLogEndpoint,
2019-12-21 20:55:43 +05:30
});
});
it('renders clickable header line', () => {
expect(findCollapsibleLine().attributes('role')).toBe('button');
});
it('renders an icon with the closed state', () => {
2022-07-23 23:45:48 +05:30
expect(findCollapsibleLineSvg().attributes('data-testid')).toBe('chevron-lg-right-icon');
2019-12-21 20:55:43 +05:30
});
});
describe('with opened section', () => {
beforeEach(() => {
createComponent({
section: collapsibleSectionOpened,
2021-11-18 22:05:49 +05:30
jobLogEndpoint,
2019-12-21 20:55:43 +05:30
});
});
it('renders clickable header line', () => {
expect(findCollapsibleLine().attributes('role')).toBe('button');
});
it('renders an icon with the open state', () => {
2022-07-23 23:45:48 +05:30
expect(findCollapsibleLineSvg().attributes('data-testid')).toBe('chevron-lg-down-icon');
2019-12-21 20:55:43 +05:30
});
it('renders collapsible lines content', () => {
expect(wrapper.findAll('.js-line').length).toEqual(collapsibleSectionOpened.lines.length);
});
});
2022-04-04 11:22:00 +05:30
it('emits onClickCollapsibleLine on click', async () => {
2019-12-21 20:55:43 +05:30
createComponent({
section: collapsibleSectionOpened,
2021-11-18 22:05:49 +05:30
jobLogEndpoint,
2019-12-21 20:55:43 +05:30
});
findCollapsibleLine().trigger('click');
2020-03-13 15:44:24 +05:30
2022-04-04 11:22:00 +05:30
await nextTick();
expect(wrapper.emitted('onClickCollapsibleLine').length).toBe(1);
2019-12-21 20:55:43 +05:30
});
});