2020-07-28 23:09:34 +05:30
|
|
|
import { GlLoadingIcon, GlIcon } 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-10-24 23:57:45 +05:30
|
|
|
import GraphGroup from '~/monitoring/components/graph_group.vue';
|
2020-01-01 13:55:28 +05:30
|
|
|
|
2019-12-04 20:38:33 +05:30
|
|
|
describe('Graph group component', () => {
|
2020-01-01 13:55:28 +05:30
|
|
|
let wrapper;
|
|
|
|
|
|
|
|
const findGroup = () => wrapper.find({ ref: 'graph-group' });
|
|
|
|
const findContent = () => wrapper.find({ ref: 'graph-group-content' });
|
2020-07-28 23:09:34 +05:30
|
|
|
const findLoadingIcon = () => wrapper.find(GlLoadingIcon);
|
|
|
|
const findCaretIcon = () => wrapper.find(GlIcon);
|
2020-06-23 00:09:42 +05:30
|
|
|
const findToggleButton = () => wrapper.find('[data-testid="group-toggle-button"]');
|
2020-01-01 13:55:28 +05:30
|
|
|
|
2021-03-08 18:12:59 +05:30
|
|
|
const createComponent = (propsData) => {
|
2020-03-13 15:44:24 +05:30
|
|
|
wrapper = shallowMount(GraphGroup, {
|
2020-01-01 13:55:28 +05:30
|
|
|
propsData,
|
|
|
|
});
|
|
|
|
};
|
2019-12-04 20:38:33 +05:30
|
|
|
|
|
|
|
afterEach(() => {
|
2020-01-01 13:55:28 +05:30
|
|
|
wrapper.destroy();
|
2019-12-04 20:38:33 +05:30
|
|
|
});
|
|
|
|
|
2020-01-01 13:55:28 +05:30
|
|
|
describe('When group is not collapsed', () => {
|
2019-12-04 20:38:33 +05:30
|
|
|
beforeEach(() => {
|
2020-01-01 13:55:28 +05:30
|
|
|
createComponent({
|
|
|
|
name: 'panel',
|
|
|
|
collapseGroup: false,
|
2019-12-04 20:38:33 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2020-07-28 23:09:34 +05:30
|
|
|
it('should not show a loading icon', () => {
|
|
|
|
expect(findLoadingIcon().exists()).toBe(false);
|
|
|
|
});
|
|
|
|
|
2020-01-01 13:55:28 +05:30
|
|
|
it('should show the angle-down caret icon', () => {
|
|
|
|
expect(findContent().isVisible()).toBe(true);
|
|
|
|
expect(findCaretIcon().props('name')).toBe('angle-down');
|
2019-12-04 20:38:33 +05:30
|
|
|
});
|
|
|
|
|
2022-04-04 11:22:00 +05:30
|
|
|
it('should show the angle-right caret icon when the user collapses the group', async () => {
|
2020-07-28 23:09:34 +05:30
|
|
|
findToggleButton().trigger('click');
|
2019-12-04 20:38:33 +05:30
|
|
|
|
2022-04-04 11:22:00 +05:30
|
|
|
await nextTick();
|
|
|
|
expect(findContent().isVisible()).toBe(false);
|
|
|
|
expect(findCaretIcon().props('name')).toBe('angle-right');
|
2019-12-04 20:38:33 +05:30
|
|
|
});
|
|
|
|
|
2020-06-23 00:09:42 +05:30
|
|
|
it('should contain a tab index for the collapse button', () => {
|
|
|
|
const groupToggle = findToggleButton();
|
|
|
|
|
2020-11-24 15:15:51 +05:30
|
|
|
expect(groupToggle.attributes('tabindex')).toBeDefined();
|
2020-06-23 00:09:42 +05:30
|
|
|
});
|
|
|
|
|
2022-04-04 11:22:00 +05:30
|
|
|
it('should show the open the group when collapseGroup is set to true', async () => {
|
2020-01-01 13:55:28 +05:30
|
|
|
wrapper.setProps({
|
|
|
|
collapseGroup: true,
|
|
|
|
});
|
|
|
|
|
2022-04-04 11:22:00 +05:30
|
|
|
await nextTick();
|
|
|
|
expect(findContent().isVisible()).toBe(true);
|
|
|
|
expect(findCaretIcon().props('name')).toBe('angle-down');
|
2020-01-01 13:55:28 +05:30
|
|
|
});
|
2020-07-28 23:09:34 +05:30
|
|
|
});
|
2020-01-01 13:55:28 +05:30
|
|
|
|
2020-07-28 23:09:34 +05:30
|
|
|
describe('When group is collapsed', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
createComponent({
|
|
|
|
name: 'panel',
|
|
|
|
collapseGroup: true,
|
2020-01-01 13:55:28 +05:30
|
|
|
});
|
2020-07-28 23:09:34 +05:30
|
|
|
});
|
2020-01-01 13:55:28 +05:30
|
|
|
|
2020-07-28 23:09:34 +05:30
|
|
|
it('should show the angle-down caret icon when collapseGroup is true', () => {
|
|
|
|
expect(findCaretIcon().props('name')).toBe('angle-right');
|
|
|
|
});
|
2020-01-01 13:55:28 +05:30
|
|
|
|
2022-04-04 11:22:00 +05:30
|
|
|
it('should show the angle-right caret icon when collapseGroup is false', async () => {
|
2020-07-28 23:09:34 +05:30
|
|
|
findToggleButton().trigger('click');
|
2020-01-01 13:55:28 +05:30
|
|
|
|
2022-04-04 11:22:00 +05:30
|
|
|
await nextTick();
|
|
|
|
expect(findCaretIcon().props('name')).toBe('angle-down');
|
2020-07-28 23:09:34 +05:30
|
|
|
});
|
2020-06-23 00:09:42 +05:30
|
|
|
|
2020-07-28 23:09:34 +05:30
|
|
|
it('should call collapse the graph group content when enter is pressed on the caret icon', () => {
|
|
|
|
const graphGroupContent = findContent();
|
|
|
|
const button = findToggleButton();
|
2020-06-23 00:09:42 +05:30
|
|
|
|
2020-07-28 23:09:34 +05:30
|
|
|
button.trigger('keyup.enter');
|
|
|
|
|
|
|
|
expect(graphGroupContent.isVisible()).toBe(false);
|
|
|
|
});
|
|
|
|
});
|
2020-06-23 00:09:42 +05:30
|
|
|
|
2020-07-28 23:09:34 +05:30
|
|
|
describe('When groups can not be collapsed', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
createComponent({
|
|
|
|
name: 'panel',
|
|
|
|
showPanels: false,
|
|
|
|
collapseGroup: false,
|
2020-06-23 00:09:42 +05:30
|
|
|
});
|
2020-01-01 13:55:28 +05:30
|
|
|
});
|
|
|
|
|
2020-07-28 23:09:34 +05:30
|
|
|
it('should not have a container when showPanels is false', () => {
|
|
|
|
expect(findGroup().exists()).toBe(false);
|
|
|
|
expect(findContent().exists()).toBe(true);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('When group is loading', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
createComponent({
|
|
|
|
name: 'panel',
|
|
|
|
isLoading: true,
|
2020-01-01 13:55:28 +05:30
|
|
|
});
|
2020-07-28 23:09:34 +05:30
|
|
|
});
|
2020-01-01 13:55:28 +05:30
|
|
|
|
2020-07-28 23:09:34 +05:30
|
|
|
it('should show a loading icon', () => {
|
|
|
|
expect(findLoadingIcon().exists()).toBe(true);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('When group does not show a panel heading', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
createComponent({
|
|
|
|
name: 'panel',
|
|
|
|
showPanels: false,
|
|
|
|
collapseGroup: false,
|
2019-12-04 20:38:33 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2020-07-28 23:09:34 +05:30
|
|
|
it('should collapse the panel content', () => {
|
|
|
|
expect(findContent().isVisible()).toBe(true);
|
|
|
|
expect(findCaretIcon().exists()).toBe(false);
|
|
|
|
});
|
|
|
|
|
2022-04-04 11:22:00 +05:30
|
|
|
it('should show the panel content when collapse is set to false', async () => {
|
2020-07-28 23:09:34 +05:30
|
|
|
wrapper.setProps({
|
|
|
|
collapseGroup: false,
|
2020-01-01 13:55:28 +05:30
|
|
|
});
|
|
|
|
|
2022-04-04 11:22:00 +05:30
|
|
|
await nextTick();
|
|
|
|
expect(findContent().isVisible()).toBe(true);
|
|
|
|
expect(findCaretIcon().exists()).toBe(false);
|
2019-12-04 20:38:33 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|