debian-mirror-gitlab/spec/frontend/logs/components/log_control_buttons_spec.js

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

89 lines
2.5 KiB
JavaScript
Raw Normal View History

2020-07-28 23:09:34 +05:30
import { GlButton } from '@gitlab/ui';
2021-03-11 19:13:27 +05:30
import { shallowMount } from '@vue/test-utils';
2022-04-04 11:22:00 +05:30
import { nextTick } from 'vue';
2020-04-08 14:13:33 +05:30
import LogControlButtons from '~/logs/components/log_control_buttons.vue';
describe('LogControlButtons', () => {
let wrapper;
const findScrollToTop = () => wrapper.find('.js-scroll-to-top');
const findScrollToBottom = () => wrapper.find('.js-scroll-to-bottom');
const findRefreshBtn = () => wrapper.find('.js-refresh-log');
2021-03-08 18:12:59 +05:30
const initWrapper = (opts) => {
2020-04-08 14:13:33 +05:30
wrapper = shallowMount(LogControlButtons, {
listeners: {
scrollUp: () => {},
scrollDown: () => {},
},
...opts,
});
};
afterEach(() => {
if (wrapper) {
wrapper.destroy();
}
});
it('displays UI elements', () => {
initWrapper();
2020-07-28 23:09:34 +05:30
expect(findScrollToTop().is(GlButton)).toBe(true);
expect(findScrollToBottom().is(GlButton)).toBe(true);
expect(findRefreshBtn().is(GlButton)).toBe(true);
2020-04-08 14:13:33 +05:30
});
2022-04-04 11:22:00 +05:30
it('emits a `refresh` event on click on `refresh` button', async () => {
2020-04-08 14:13:33 +05:30
initWrapper();
// An `undefined` value means no event was emitted
expect(wrapper.emitted('refresh')).toBe(undefined);
findRefreshBtn().vm.$emit('click');
2022-04-04 11:22:00 +05:30
await nextTick();
expect(wrapper.emitted('refresh')).toHaveLength(1);
2020-04-08 14:13:33 +05:30
});
describe('when scrolling actions are enabled', () => {
2022-04-04 11:22:00 +05:30
beforeEach(async () => {
2020-04-08 14:13:33 +05:30
// mock scrolled to the middle of a long page
initWrapper();
2022-04-04 11:22:00 +05:30
await nextTick();
2020-04-08 14:13:33 +05:30
});
it('click on "scroll to top" scrolls up', () => {
2020-11-24 15:15:51 +05:30
expect(findScrollToTop().attributes('disabled')).toBeUndefined();
2020-04-08 14:13:33 +05:30
findScrollToTop().vm.$emit('click');
expect(wrapper.emitted('scrollUp')).toHaveLength(1);
});
it('click on "scroll to bottom" scrolls down', () => {
2020-11-24 15:15:51 +05:30
expect(findScrollToBottom().attributes('disabled')).toBeUndefined();
2020-04-08 14:13:33 +05:30
findScrollToBottom().vm.$emit('click');
expect(wrapper.emitted('scrollDown')).toHaveLength(1);
});
});
describe('when scrolling actions are disabled', () => {
2022-04-04 11:22:00 +05:30
beforeEach(async () => {
2020-04-08 14:13:33 +05:30
initWrapper({ listeners: {} });
2022-04-04 11:22:00 +05:30
await nextTick();
2020-04-08 14:13:33 +05:30
});
2022-04-04 11:22:00 +05:30
it('buttons are disabled', async () => {
await nextTick();
expect(findScrollToTop().exists()).toBe(false);
expect(findScrollToBottom().exists()).toBe(false);
// This should be enabled when gitlab-ui contains:
// https://gitlab.com/gitlab-org/gitlab-ui/-/merge_requests/1149
// expect(findScrollToBottom().is('[disabled]')).toBe(true);
2020-04-08 14:13:33 +05:30
});
});
});