2021-12-11 22:18:48 +05:30
|
|
|
import { GlButton } from '@gitlab/ui';
|
|
|
|
import { mount, shallowMount } from '@vue/test-utils';
|
|
|
|
|
2022-04-04 11:22:00 +05:30
|
|
|
import { nextTick } from 'vue';
|
2023-03-04 22:38:38 +05:30
|
|
|
import ToggleSidebar from '~/sidebar/components/toggle/toggle_sidebar.vue';
|
2021-12-11 22:18:48 +05:30
|
|
|
|
|
|
|
describe('ToggleSidebar', () => {
|
|
|
|
let wrapper;
|
|
|
|
|
|
|
|
const defaultProps = {
|
|
|
|
collapsed: true,
|
|
|
|
};
|
|
|
|
|
|
|
|
const createComponent = ({ mountFn = shallowMount, props = {} } = {}) => {
|
|
|
|
wrapper = mountFn(ToggleSidebar, {
|
|
|
|
propsData: { ...defaultProps, ...props },
|
2018-03-17 18:26:18 +05:30
|
|
|
});
|
2021-12-11 22:18:48 +05:30
|
|
|
};
|
|
|
|
|
|
|
|
const findGlButton = () => wrapper.findComponent(GlButton);
|
|
|
|
|
2021-01-03 14:25:43 +05:30
|
|
|
it('should render the "chevron-double-lg-left" icon when collapsed', () => {
|
2021-12-11 22:18:48 +05:30
|
|
|
createComponent();
|
|
|
|
|
|
|
|
expect(findGlButton().props('icon')).toBe('chevron-double-lg-left');
|
2018-03-17 18:26:18 +05:30
|
|
|
});
|
|
|
|
|
2021-01-03 14:25:43 +05:30
|
|
|
it('should render the "chevron-double-lg-right" icon when expanded', async () => {
|
2021-12-11 22:18:48 +05:30
|
|
|
createComponent({ props: { collapsed: false } });
|
|
|
|
|
|
|
|
expect(findGlButton().props('icon')).toBe('chevron-double-lg-right');
|
2018-03-17 18:26:18 +05:30
|
|
|
});
|
|
|
|
|
2021-12-11 22:18:48 +05:30
|
|
|
it('should emit toggle event when button clicked', async () => {
|
|
|
|
createComponent({ mountFn: mount });
|
|
|
|
|
|
|
|
findGlButton().trigger('click');
|
2022-04-04 11:22:00 +05:30
|
|
|
await nextTick();
|
2018-03-17 18:26:18 +05:30
|
|
|
|
2021-12-11 22:18:48 +05:30
|
|
|
expect(wrapper.emitted('toggle')[0]).toBeDefined();
|
2018-03-17 18:26:18 +05:30
|
|
|
});
|
|
|
|
});
|