debian-mirror-gitlab/spec/frontend/sidebar/components/toggle/toggle_sidebar_spec.js
2023-03-04 22:38:38 +05:30

46 lines
1.2 KiB
JavaScript

import { GlButton } from '@gitlab/ui';
import { mount, shallowMount } from '@vue/test-utils';
import { nextTick } from 'vue';
import ToggleSidebar from '~/sidebar/components/toggle/toggle_sidebar.vue';
describe('ToggleSidebar', () => {
let wrapper;
const defaultProps = {
collapsed: true,
};
const createComponent = ({ mountFn = shallowMount, props = {} } = {}) => {
wrapper = mountFn(ToggleSidebar, {
propsData: { ...defaultProps, ...props },
});
};
afterEach(() => {
wrapper.destroy();
});
const findGlButton = () => wrapper.findComponent(GlButton);
it('should render the "chevron-double-lg-left" icon when collapsed', () => {
createComponent();
expect(findGlButton().props('icon')).toBe('chevron-double-lg-left');
});
it('should render the "chevron-double-lg-right" icon when expanded', async () => {
createComponent({ props: { collapsed: false } });
expect(findGlButton().props('icon')).toBe('chevron-double-lg-right');
});
it('should emit toggle event when button clicked', async () => {
createComponent({ mountFn: mount });
findGlButton().trigger('click');
await nextTick();
expect(wrapper.emitted('toggle')[0]).toBeDefined();
});
});