debian-mirror-gitlab/spec/frontend/monitoring/components/graph_group_spec.js

114 lines
3.1 KiB
JavaScript
Raw Normal View History

2020-03-09 13:42:32 +05:30
import { shallowMount } from '@vue/test-utils';
2019-12-04 20:38:33 +05:30
import GraphGroup from '~/monitoring/components/graph_group.vue';
2020-01-01 13:55:28 +05:30
import Icon from '~/vue_shared/components/icon.vue';
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' });
const findCaretIcon = () => wrapper.find(Icon);
const createComponent = propsData => {
2020-03-09 13:42:32 +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-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
});
2020-03-09 13:42:32 +05:30
it('should show the angle-right caret icon when the user collapses the group', () => {
2020-01-01 13:55:28 +05:30
wrapper.vm.collapse();
2019-12-04 20:38:33 +05:30
2020-03-09 13:42:32 +05:30
return wrapper.vm.$nextTick(() => {
2020-01-01 13:55:28 +05:30
expect(findContent().isVisible()).toBe(false);
expect(findCaretIcon().props('name')).toBe('angle-right');
});
2019-12-04 20:38:33 +05:30
});
2020-03-09 13:42:32 +05:30
it('should show the open the group when collapseGroup is set to true', () => {
2020-01-01 13:55:28 +05:30
wrapper.setProps({
collapseGroup: true,
});
2020-03-09 13:42:32 +05:30
return wrapper.vm.$nextTick(() => {
2020-01-01 13:55:28 +05:30
expect(findContent().isVisible()).toBe(true);
expect(findCaretIcon().props('name')).toBe('angle-down');
});
});
describe('When group is collapsed', () => {
beforeEach(() => {
createComponent({
2019-12-04 20:38:33 +05:30
name: 'panel',
collapseGroup: true,
2020-01-01 13:55:28 +05:30
});
});
it('should show the angle-down caret icon when collapseGroup is true', () => {
expect(wrapper.vm.caretIcon).toBe('angle-right');
});
it('should show the angle-right caret icon when collapseGroup is false', () => {
wrapper.vm.collapse();
expect(wrapper.vm.caretIcon).toBe('angle-down');
});
});
describe('When groups can not be collapsed', () => {
beforeEach(() => {
createComponent({
name: 'panel',
2019-12-04 20:38:33 +05:30
showPanels: false,
2020-01-01 13:55:28 +05:30
collapseGroup: false,
});
});
it('should not have a container when showPanels is false', () => {
expect(findGroup().exists()).toBe(false);
expect(findContent().exists()).toBe(true);
2019-12-04 20:38:33 +05:30
});
});
2020-01-01 13:55:28 +05:30
describe('When group does not show a panel heading', () => {
beforeEach(() => {
createComponent({
name: 'panel',
showPanels: false,
collapseGroup: false,
});
});
it('should collapse the panel content', () => {
expect(findContent().isVisible()).toBe(true);
expect(findCaretIcon().exists()).toBe(false);
});
2020-03-09 13:42:32 +05:30
it('should show the panel content when clicked', () => {
2020-01-01 13:55:28 +05:30
wrapper.vm.collapse();
2020-03-09 13:42:32 +05:30
return wrapper.vm.$nextTick(() => {
2020-01-01 13:55:28 +05:30
expect(findContent().isVisible()).toBe(true);
expect(findCaretIcon().exists()).toBe(false);
});
});
2019-12-04 20:38:33 +05:30
});
});
});