debian-mirror-gitlab/spec/frontend/ide/components/new_dropdown/button_spec.js

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

61 lines
1.3 KiB
JavaScript
Raw Normal View History

2022-11-25 23:54:43 +05:30
import { mount } from '@vue/test-utils';
2018-11-18 11:00:15 +05:30
import Button from '~/ide/components/new_dropdown/button.vue';
describe('IDE new entry dropdown button component', () => {
2022-11-25 23:54:43 +05:30
let wrapper;
const createComponent = (props = {}) => {
wrapper = mount(Button, {
propsData: {
label: 'Testing',
icon: 'doc-new',
...props,
},
2018-11-18 11:00:15 +05:30
});
2022-11-25 23:54:43 +05:30
};
2018-11-18 11:00:15 +05:30
afterEach(() => {
2022-11-25 23:54:43 +05:30
wrapper.destroy();
2018-11-18 11:00:15 +05:30
});
it('renders button with label', () => {
2022-11-25 23:54:43 +05:30
createComponent();
expect(wrapper.text()).toContain('Testing');
2018-11-18 11:00:15 +05:30
});
it('renders icon', () => {
2022-11-25 23:54:43 +05:30
createComponent();
expect(wrapper.find('[data-testid="doc-new-icon"]').exists()).toBe(true);
2018-11-18 11:00:15 +05:30
});
2022-11-25 23:54:43 +05:30
it('emits click event', async () => {
createComponent();
2018-11-18 11:00:15 +05:30
2022-11-25 23:54:43 +05:30
await wrapper.trigger('click');
expect(wrapper.emitted('click')).toHaveLength(1);
2018-11-18 11:00:15 +05:30
});
2022-11-25 23:54:43 +05:30
it('hides label if showLabel is false', () => {
createComponent({ showLabel: false });
2018-11-18 11:00:15 +05:30
2022-11-25 23:54:43 +05:30
expect(wrapper.text()).not.toContain('Testing');
2018-11-18 11:00:15 +05:30
});
2018-11-20 20:47:30 +05:30
2022-11-25 23:54:43 +05:30
describe('tooltip title', () => {
2018-11-20 20:47:30 +05:30
it('returns empty string when showLabel is true', () => {
2022-11-25 23:54:43 +05:30
createComponent({ showLabel: true });
expect(wrapper.attributes('title')).toBe('');
2018-11-20 20:47:30 +05:30
});
2022-11-25 23:54:43 +05:30
it('returns label', () => {
createComponent({ showLabel: false });
2018-11-20 20:47:30 +05:30
2022-11-25 23:54:43 +05:30
expect(wrapper.attributes('title')).toBe('Testing');
2018-11-20 20:47:30 +05:30
});
});
2018-11-18 11:00:15 +05:30
});