debian-mirror-gitlab/spec/frontend/whats_new/components/app_spec.js

80 lines
1.7 KiB
JavaScript
Raw Normal View History

2020-10-24 23:57:45 +05:30
import { createLocalVue, mount } from '@vue/test-utils';
import Vuex from 'vuex';
import { GlDrawer } from '@gitlab/ui';
import App from '~/whats_new/components/app.vue';
const localVue = createLocalVue();
localVue.use(Vuex);
describe('App', () => {
let wrapper;
let store;
let actions;
let state;
2020-11-24 15:15:51 +05:30
let propsData = { features: '[ {"title":"Whats New Drawer"} ]' };
2020-10-24 23:57:45 +05:30
2020-11-24 15:15:51 +05:30
const buildWrapper = () => {
2020-10-24 23:57:45 +05:30
actions = {
2020-11-24 15:15:51 +05:30
openDrawer: jest.fn(),
2020-10-24 23:57:45 +05:30
closeDrawer: jest.fn(),
};
state = {
open: true,
};
store = new Vuex.Store({
actions,
state,
});
wrapper = mount(App, {
localVue,
store,
2020-11-24 15:15:51 +05:30
propsData,
2020-10-24 23:57:45 +05:30
});
2020-11-24 15:15:51 +05:30
};
beforeEach(() => {
buildWrapper();
2020-10-24 23:57:45 +05:30
});
afterEach(() => {
wrapper.destroy();
});
const getDrawer = () => wrapper.find(GlDrawer);
it('contains a drawer', () => {
expect(getDrawer().exists()).toBe(true);
});
2020-11-24 15:15:51 +05:30
it('dispatches openDrawer when mounted', () => {
expect(actions.openDrawer).toHaveBeenCalled();
});
2020-10-24 23:57:45 +05:30
it('dispatches closeDrawer when clicking close', () => {
getDrawer().vm.$emit('close');
expect(actions.closeDrawer).toHaveBeenCalled();
});
it.each([true, false])('passes open property', async openState => {
wrapper.vm.$store.state.open = openState;
await wrapper.vm.$nextTick();
expect(getDrawer().props('open')).toBe(openState);
});
2020-11-24 15:15:51 +05:30
it('renders features when provided as props', () => {
expect(wrapper.find('h5').text()).toBe('Whats New Drawer');
});
it('handles bad json argument gracefully', () => {
propsData = { features: 'this is not json' };
buildWrapper();
expect(getDrawer().exists()).toBe(true);
});
2020-10-24 23:57:45 +05:30
});