debian-mirror-gitlab/spec/frontend/ide/components/jobs/detail_spec.js

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

149 lines
4.9 KiB
JavaScript
Raw Normal View History

2022-11-25 23:54:43 +05:30
import { nextTick } from 'vue';
import { mount } from '@vue/test-utils';
2020-10-24 23:57:45 +05:30
import { TEST_HOST } from 'helpers/test_constants';
2020-06-23 00:09:42 +05:30
import JobDetail from '~/ide/components/jobs/detail.vue';
import { createStore } from '~/ide/stores';
import { jobs } from '../../mock_data';
describe('IDE jobs detail view', () => {
2022-11-25 23:54:43 +05:30
let wrapper;
let store;
2020-06-23 00:09:42 +05:30
const createComponent = () => {
2022-11-25 23:54:43 +05:30
store = createStore();
2020-06-23 00:09:42 +05:30
store.state.pipelines.detailJob = {
...jobs[0],
isLoading: true,
output: 'testing',
rawPath: `${TEST_HOST}/raw`,
};
2022-11-25 23:54:43 +05:30
jest.spyOn(store, 'dispatch');
store.dispatch.mockResolvedValue();
wrapper = mount(JobDetail, { store });
2020-06-23 00:09:42 +05:30
};
2022-11-25 23:54:43 +05:30
const findBuildJobLog = () => wrapper.find('pre');
const findScrollToBottomButton = () => wrapper.find('button[aria-label="Scroll to bottom"]');
const findScrollToTopButton = () => wrapper.find('button[aria-label="Scroll to top"]');
2020-06-23 00:09:42 +05:30
2022-11-25 23:54:43 +05:30
beforeEach(() => {
createComponent();
2020-06-23 00:09:42 +05:30
});
afterEach(() => {
2022-11-25 23:54:43 +05:30
wrapper.destroy();
2020-06-23 00:09:42 +05:30
});
describe('mounted', () => {
2022-11-25 23:54:43 +05:30
const findJobOutput = () => wrapper.find('.bash');
const findBuildLoaderAnimation = () => wrapper.find('.build-loader-animation');
2020-06-23 00:09:42 +05:30
2020-11-24 15:15:51 +05:30
it('calls fetchJobLogs', () => {
2022-11-25 23:54:43 +05:30
expect(store.dispatch).toHaveBeenCalledWith('pipelines/fetchJobLogs', undefined);
2020-06-23 00:09:42 +05:30
});
it('scrolls to bottom', () => {
2022-11-25 23:54:43 +05:30
expect(findBuildJobLog().element.scrollTo).toHaveBeenCalled();
2020-06-23 00:09:42 +05:30
});
it('renders job output', () => {
2022-11-25 23:54:43 +05:30
expect(findJobOutput().text()).toContain('testing');
2020-06-23 00:09:42 +05:30
});
2022-04-04 11:22:00 +05:30
it('renders empty message output', async () => {
2022-11-25 23:54:43 +05:30
store.state.pipelines.detailJob.output = '';
2022-04-04 11:22:00 +05:30
await nextTick();
2022-11-25 23:54:43 +05:30
expect(findJobOutput().text()).toContain('No messages were logged');
2020-06-23 00:09:42 +05:30
});
it('renders loading icon', () => {
2022-11-25 23:54:43 +05:30
expect(findBuildLoaderAnimation().exists()).toBe(true);
expect(findBuildLoaderAnimation().isVisible()).toBe(true);
2020-06-23 00:09:42 +05:30
});
it('hides output when loading', () => {
2022-11-25 23:54:43 +05:30
expect(findJobOutput().exists()).toBe(true);
expect(findJobOutput().isVisible()).toBe(false);
2020-06-23 00:09:42 +05:30
});
2022-04-04 11:22:00 +05:30
it('hide loading icon when isLoading is false', async () => {
2022-11-25 23:54:43 +05:30
store.state.pipelines.detailJob.isLoading = false;
2022-04-04 11:22:00 +05:30
await nextTick();
2020-06-23 00:09:42 +05:30
2022-11-25 23:54:43 +05:30
expect(findBuildLoaderAnimation().isVisible()).toBe(false);
});
2020-06-23 00:09:42 +05:30
2022-11-25 23:54:43 +05:30
it('resets detailJob when clicking header button', async () => {
await wrapper.find('.btn').trigger('click');
2020-06-23 00:09:42 +05:30
2022-11-25 23:54:43 +05:30
expect(store.dispatch).toHaveBeenCalledWith('pipelines/setDetailJob', null);
2020-06-23 00:09:42 +05:30
});
it('renders raw path link', () => {
2022-11-25 23:54:43 +05:30
expect(wrapper.find('.controllers-buttons').attributes('href')).toBe(`${TEST_HOST}/raw`);
2020-06-23 00:09:42 +05:30
});
});
describe('scroll buttons', () => {
beforeEach(() => {
2022-11-25 23:54:43 +05:30
createComponent();
2020-06-23 00:09:42 +05:30
});
it.each`
2022-11-25 23:54:43 +05:30
fnName | btnName | scrollPos | targetScrollPos
${'scroll down'} | ${'down'} | ${0} | ${200}
${'scroll up'} | ${'up'} | ${200} | ${0}
`('triggers $fnName when clicking $btnName button', async ({ scrollPos, targetScrollPos }) => {
jest.spyOn(findBuildJobLog().element, 'offsetHeight', 'get').mockReturnValue(0);
jest.spyOn(findBuildJobLog().element, 'scrollHeight', 'get').mockReturnValue(200);
jest.spyOn(findBuildJobLog().element, 'scrollTop', 'get').mockReturnValue(scrollPos);
findBuildJobLog().element.scrollTo.mockReset();
2020-06-23 00:09:42 +05:30
2022-11-25 23:54:43 +05:30
await findBuildJobLog().trigger('scroll'); // trigger button updates
2020-06-23 00:09:42 +05:30
2022-11-25 23:54:43 +05:30
await wrapper.find('.controllers button:not(:disabled)').trigger('click');
2020-06-23 00:09:42 +05:30
2022-11-25 23:54:43 +05:30
expect(findBuildJobLog().element.scrollTo).toHaveBeenCalledWith(0, targetScrollPos);
2020-06-23 00:09:42 +05:30
});
});
2022-11-25 23:54:43 +05:30
describe('scrolling build log', () => {
2020-06-23 00:09:42 +05:30
beforeEach(() => {
2022-11-25 23:54:43 +05:30
jest.spyOn(findBuildJobLog().element, 'offsetHeight', 'get').mockReturnValue(100);
jest.spyOn(findBuildJobLog().element, 'scrollHeight', 'get').mockReturnValue(200);
2020-06-23 00:09:42 +05:30
});
2022-11-25 23:54:43 +05:30
it('keeps scroll at bottom when already at the bottom', async () => {
jest.spyOn(findBuildJobLog().element, 'scrollTop', 'get').mockReturnValue(100);
2020-06-23 00:09:42 +05:30
2022-11-25 23:54:43 +05:30
await findBuildJobLog().trigger('scroll');
2020-06-23 00:09:42 +05:30
2022-11-25 23:54:43 +05:30
expect(findScrollToBottomButton().attributes('disabled')).toBe('disabled');
expect(findScrollToTopButton().attributes('disabled')).not.toBe('disabled');
2020-06-23 00:09:42 +05:30
});
2022-11-25 23:54:43 +05:30
it('keeps scroll at top when already at top', async () => {
jest.spyOn(findBuildJobLog().element, 'scrollTop', 'get').mockReturnValue(0);
2020-06-23 00:09:42 +05:30
2022-11-25 23:54:43 +05:30
await findBuildJobLog().trigger('scroll');
2020-06-23 00:09:42 +05:30
2022-11-25 23:54:43 +05:30
expect(findScrollToBottomButton().attributes('disabled')).not.toBe('disabled');
expect(findScrollToTopButton().attributes('disabled')).toBe('disabled');
2020-06-23 00:09:42 +05:30
});
2022-11-25 23:54:43 +05:30
it('resets scroll when not at top or bottom', async () => {
jest.spyOn(findBuildJobLog().element, 'scrollTop', 'get').mockReturnValue(10);
2020-06-23 00:09:42 +05:30
2022-11-25 23:54:43 +05:30
await findBuildJobLog().trigger('scroll');
2020-06-23 00:09:42 +05:30
2022-11-25 23:54:43 +05:30
expect(findScrollToBottomButton().attributes('disabled')).not.toBe('disabled');
expect(findScrollToTopButton().attributes('disabled')).not.toBe('disabled');
2020-06-23 00:09:42 +05:30
});
});
});