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

90 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';
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
});
it('emits a `refresh` event on click on `refresh` button', () => {
initWrapper();
// An `undefined` value means no event was emitted
expect(wrapper.emitted('refresh')).toBe(undefined);
findRefreshBtn().vm.$emit('click');
return wrapper.vm.$nextTick().then(() => {
expect(wrapper.emitted('refresh')).toHaveLength(1);
});
});
describe('when scrolling actions are enabled', () => {
beforeEach(() => {
// mock scrolled to the middle of a long page
initWrapper();
return wrapper.vm.$nextTick();
});
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', () => {
beforeEach(() => {
initWrapper({ listeners: {} });
return wrapper.vm.$nextTick();
});
it('buttons are disabled', () => {
return wrapper.vm.$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);
});
});
});
});