2019-09-19 14:06:18 -04:00
|
|
|
import { mount } from '@vue/test-utils';
|
|
|
|
import CollpasibleSection from '~/jobs/components/log/collapsible_section.vue';
|
2019-09-24 05:06:04 -04:00
|
|
|
import { collapsibleSectionClosed, collapsibleSectionOpened } from './mock_data';
|
2019-09-19 14:06:18 -04:00
|
|
|
|
|
|
|
describe('Job Log Collapsible Section', () => {
|
|
|
|
let wrapper;
|
|
|
|
|
|
|
|
const traceEndpoint = 'jobs/335';
|
|
|
|
|
|
|
|
const findCollapsibleLine = () => wrapper.find('.collapsible-line');
|
2019-09-24 05:06:04 -04:00
|
|
|
const findCollapsibleLineSvg = () => wrapper.find('.collapsible-line svg');
|
2019-09-19 14:06:18 -04:00
|
|
|
|
|
|
|
const createComponent = (props = {}) => {
|
|
|
|
wrapper = mount(CollpasibleSection, {
|
|
|
|
sync: true,
|
|
|
|
propsData: {
|
|
|
|
...props,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
wrapper.destroy();
|
|
|
|
});
|
|
|
|
|
2019-09-24 05:06:04 -04:00
|
|
|
describe('with closed section', () => {
|
2019-09-19 14:06:18 -04:00
|
|
|
beforeEach(() => {
|
|
|
|
createComponent({
|
2019-09-24 05:06:04 -04:00
|
|
|
section: collapsibleSectionClosed,
|
2019-09-19 14:06:18 -04:00
|
|
|
traceEndpoint,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('renders clickable header line', () => {
|
|
|
|
expect(findCollapsibleLine().attributes('role')).toBe('button');
|
|
|
|
});
|
2019-09-24 05:06:04 -04:00
|
|
|
|
|
|
|
it('renders an icon with the closed state', () => {
|
|
|
|
expect(findCollapsibleLineSvg().classes()).toContain('ic-angle-right');
|
|
|
|
});
|
2019-09-19 14:06:18 -04:00
|
|
|
});
|
|
|
|
|
2019-09-24 05:06:04 -04:00
|
|
|
describe('with opened section', () => {
|
2019-09-19 14:06:18 -04:00
|
|
|
beforeEach(() => {
|
|
|
|
createComponent({
|
2019-09-24 05:06:04 -04:00
|
|
|
section: collapsibleSectionOpened,
|
2019-09-19 14:06:18 -04:00
|
|
|
traceEndpoint,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2019-09-24 05:06:04 -04:00
|
|
|
it('renders clickable header line', () => {
|
|
|
|
expect(findCollapsibleLine().attributes('role')).toBe('button');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('renders an icon with the open state', () => {
|
|
|
|
expect(findCollapsibleLineSvg().classes()).toContain('ic-angle-down');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('renders collapsible lines content', () => {
|
|
|
|
expect(wrapper.findAll('.js-line').length).toEqual(collapsibleSectionOpened.lines.length);
|
2019-09-19 14:06:18 -04:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('emits onClickCollapsibleLine on click', () => {
|
|
|
|
createComponent({
|
2019-09-24 05:06:04 -04:00
|
|
|
section: collapsibleSectionOpened,
|
2019-09-19 14:06:18 -04:00
|
|
|
traceEndpoint,
|
|
|
|
});
|
|
|
|
|
|
|
|
findCollapsibleLine().trigger('click');
|
|
|
|
expect(wrapper.emitted('onClickCollapsibleLine').length).toBe(1);
|
|
|
|
});
|
|
|
|
});
|