debian-mirror-gitlab/spec/frontend/jobs/components/job_log_controllers_spec.js

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

183 lines
4.9 KiB
JavaScript
Raw Normal View History

2020-10-24 23:57:45 +05:30
import { mount } from '@vue/test-utils';
2022-04-04 11:22:00 +05:30
import { nextTick } from 'vue';
2020-10-24 23:57:45 +05:30
import JobLogControllers from '~/jobs/components/job_log_controllers.vue';
2018-11-20 20:47:30 +05:30
describe('Job log controllers', () => {
2020-10-24 23:57:45 +05:30
let wrapper;
2018-11-20 20:47:30 +05:30
afterEach(() => {
2020-10-24 23:57:45 +05:30
if (wrapper?.destroy) {
wrapper.destroy();
}
2018-11-20 20:47:30 +05:30
});
2020-10-24 23:57:45 +05:30
const defaultProps = {
2018-12-05 23:21:45 +05:30
rawPath: '/raw',
erasePath: '/erase',
size: 511952,
isScrollTopDisabled: false,
isScrollBottomDisabled: false,
isScrollingDown: true,
2021-11-18 22:05:49 +05:30
isJobLogSizeVisible: true,
2018-12-05 23:21:45 +05:30
};
2018-11-20 20:47:30 +05:30
2021-03-08 18:12:59 +05:30
const createWrapper = (props) => {
2020-10-24 23:57:45 +05:30
wrapper = mount(JobLogControllers, {
propsData: {
...defaultProps,
...props,
},
});
};
const findTruncatedInfo = () => wrapper.find('[data-testid="log-truncated-info"]');
const findRawLink = () => wrapper.find('[data-testid="raw-link"]');
const findRawLinkController = () => wrapper.find('[data-testid="job-raw-link-controller"]');
const findScrollTop = () => wrapper.find('[data-testid="job-controller-scroll-top"]');
const findScrollBottom = () => wrapper.find('[data-testid="job-controller-scroll-bottom"]');
2018-12-05 23:21:45 +05:30
describe('Truncate information', () => {
2021-11-18 22:05:49 +05:30
describe('with isJobLogSizeVisible', () => {
2018-12-05 23:21:45 +05:30
beforeEach(() => {
2020-10-24 23:57:45 +05:30
createWrapper();
2018-12-05 23:21:45 +05:30
});
2018-12-13 13:39:08 +05:30
2018-12-05 23:21:45 +05:30
it('renders size information', () => {
2020-10-24 23:57:45 +05:30
expect(findTruncatedInfo().text()).toMatch('499.95 KiB');
2018-11-20 20:47:30 +05:30
});
2021-11-18 22:05:49 +05:30
it('renders link to raw job log', () => {
2020-10-24 23:57:45 +05:30
expect(findRawLink().attributes('href')).toBe(defaultProps.rawPath);
2018-12-05 23:21:45 +05:30
});
2018-11-20 20:47:30 +05:30
});
});
describe('links section', () => {
2021-11-18 22:05:49 +05:30
describe('with raw job log path', () => {
2020-10-24 23:57:45 +05:30
beforeEach(() => {
createWrapper();
});
2018-11-20 20:47:30 +05:30
2021-11-18 22:05:49 +05:30
it('renders raw job log link', () => {
2020-10-24 23:57:45 +05:30
expect(findRawLinkController().attributes('href')).toBe(defaultProps.rawPath);
2018-11-20 20:47:30 +05:30
});
});
2021-11-18 22:05:49 +05:30
describe('without raw job log path', () => {
2020-10-24 23:57:45 +05:30
beforeEach(() => {
createWrapper({
rawPath: null,
2018-11-20 20:47:30 +05:30
});
2020-10-24 23:57:45 +05:30
});
2018-11-20 20:47:30 +05:30
2021-11-18 22:05:49 +05:30
it('does not render raw job log link', () => {
2020-10-24 23:57:45 +05:30
expect(findRawLinkController().exists()).toBe(false);
2018-11-20 20:47:30 +05:30
});
});
});
describe('scroll buttons', () => {
describe('scroll top button', () => {
describe('when user can scroll top', () => {
beforeEach(() => {
2020-10-24 23:57:45 +05:30
createWrapper({
isScrollTopDisabled: false,
});
2018-11-20 20:47:30 +05:30
});
2020-10-24 23:57:45 +05:30
it('emits scrollJobLogTop event on click', async () => {
findScrollTop().trigger('click');
2018-11-20 20:47:30 +05:30
2022-04-04 11:22:00 +05:30
await nextTick();
2018-11-20 20:47:30 +05:30
2020-10-24 23:57:45 +05:30
expect(wrapper.emitted().scrollJobLogTop).toHaveLength(1);
2018-11-20 20:47:30 +05:30
});
});
describe('when user can not scroll top', () => {
beforeEach(() => {
2020-10-24 23:57:45 +05:30
createWrapper({
2018-12-05 23:21:45 +05:30
isScrollTopDisabled: true,
isScrollBottomDisabled: false,
isScrollingDown: false,
2018-11-20 20:47:30 +05:30
});
});
it('renders disabled scroll top button', () => {
2020-10-24 23:57:45 +05:30
expect(findScrollTop().attributes('disabled')).toBe('disabled');
2018-11-20 20:47:30 +05:30
});
2020-10-24 23:57:45 +05:30
it('does not emit scrollJobLogTop event on click', async () => {
findScrollTop().trigger('click');
2018-11-20 20:47:30 +05:30
2022-04-04 11:22:00 +05:30
await nextTick();
2020-10-24 23:57:45 +05:30
expect(wrapper.emitted().scrollJobLogTop).toBeUndefined();
2018-11-20 20:47:30 +05:30
});
});
});
describe('scroll bottom button', () => {
describe('when user can scroll bottom', () => {
beforeEach(() => {
2020-10-24 23:57:45 +05:30
createWrapper();
2018-11-20 20:47:30 +05:30
});
2020-10-24 23:57:45 +05:30
it('emits scrollJobLogBottom event on click', async () => {
findScrollBottom().trigger('click');
2018-11-20 20:47:30 +05:30
2022-04-04 11:22:00 +05:30
await nextTick();
2018-11-20 20:47:30 +05:30
2020-10-24 23:57:45 +05:30
expect(wrapper.emitted().scrollJobLogBottom).toHaveLength(1);
2018-11-20 20:47:30 +05:30
});
});
describe('when user can not scroll bottom', () => {
beforeEach(() => {
2020-10-24 23:57:45 +05:30
createWrapper({
2018-12-05 23:21:45 +05:30
isScrollTopDisabled: false,
isScrollBottomDisabled: true,
isScrollingDown: false,
2018-11-20 20:47:30 +05:30
});
});
it('renders disabled scroll bottom button', () => {
2020-10-24 23:57:45 +05:30
expect(findScrollBottom().attributes('disabled')).toEqual('disabled');
2018-11-20 20:47:30 +05:30
});
2020-10-24 23:57:45 +05:30
it('does not emit scrollJobLogBottom event on click', async () => {
findScrollBottom().trigger('click');
2018-11-20 20:47:30 +05:30
2022-04-04 11:22:00 +05:30
await nextTick();
2020-10-24 23:57:45 +05:30
expect(wrapper.emitted().scrollJobLogBottom).toBeUndefined();
2018-11-20 20:47:30 +05:30
});
});
2018-12-05 23:21:45 +05:30
describe('while isScrollingDown is true', () => {
2020-10-24 23:57:45 +05:30
beforeEach(() => {
createWrapper();
});
2018-12-05 23:21:45 +05:30
2020-10-24 23:57:45 +05:30
it('renders animate class for the scroll down button', () => {
expect(findScrollBottom().classes()).toContain('animate');
2018-12-05 23:21:45 +05:30
});
});
describe('while isScrollingDown is false', () => {
2020-10-24 23:57:45 +05:30
beforeEach(() => {
createWrapper({
2018-12-05 23:21:45 +05:30
isScrollTopDisabled: true,
isScrollBottomDisabled: false,
isScrollingDown: false,
});
2020-10-24 23:57:45 +05:30
});
2018-12-13 13:39:08 +05:30
2020-10-24 23:57:45 +05:30
it('does not render animate class for the scroll down button', () => {
expect(findScrollBottom().classes()).not.toContain('animate');
2018-12-05 23:21:45 +05:30
});
});
2018-11-20 20:47:30 +05:30
});
});
});