debian-mirror-gitlab/spec/frontend/boards/components/board_app_spec.js

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

98 lines
2.7 KiB
JavaScript
Raw Normal View History

2021-11-11 11:23:49 +05:30
import { shallowMount } from '@vue/test-utils';
2023-06-20 00:43:36 +05:30
import Vue, { nextTick } from 'vue';
import VueApollo from 'vue-apollo';
2021-11-11 11:23:49 +05:30
import Vuex from 'vuex';
2023-06-20 00:43:36 +05:30
import createMockApollo from 'helpers/mock_apollo_helper';
2021-11-11 11:23:49 +05:30
import BoardApp from '~/boards/components/board_app.vue';
2023-06-20 00:43:36 +05:30
import activeBoardItemQuery from 'ee_else_ce/boards/graphql/client/active_board_item.query.graphql';
2023-07-09 08:55:56 +05:30
import boardListsQuery from 'ee_else_ce/boards/graphql/board_lists.query.graphql';
import { rawIssue, boardListsQueryResponse } from '../mock_data';
2021-11-11 11:23:49 +05:30
describe('BoardApp', () => {
let wrapper;
let store;
2023-07-09 08:55:56 +05:30
const boardListQueryHandler = jest.fn().mockResolvedValue(boardListsQueryResponse);
const mockApollo = createMockApollo([[boardListsQuery, boardListQueryHandler]]);
2021-11-11 11:23:49 +05:30
Vue.use(Vuex);
2023-06-20 00:43:36 +05:30
Vue.use(VueApollo);
2021-11-11 11:23:49 +05:30
const createStore = ({ mockGetters = {} } = {}) => {
store = new Vuex.Store({
state: {},
actions: {
performSearch: jest.fn(),
},
getters: {
isSidebarOpen: () => true,
...mockGetters,
},
});
};
2023-06-20 00:43:36 +05:30
const createComponent = ({ isApolloBoard = false, issue = rawIssue } = {}) => {
mockApollo.clients.defaultClient.cache.writeQuery({
query: activeBoardItemQuery,
data: {
activeBoardItem: issue,
},
});
2021-11-11 11:23:49 +05:30
wrapper = shallowMount(BoardApp, {
2023-06-20 00:43:36 +05:30
apolloProvider: mockApollo,
2021-11-11 11:23:49 +05:30
store,
provide: {
2023-07-09 08:55:56 +05:30
fullPath: 'gitlab-org',
2023-04-23 21:23:45 +05:30
initialBoardId: 'gid://gitlab/Board/1',
2023-05-27 22:25:52 +05:30
initialFilterParams: {},
2023-07-09 08:55:56 +05:30
issuableType: 'issue',
boardType: 'group',
2023-06-20 00:43:36 +05:30
isIssueBoard: true,
2023-07-09 08:55:56 +05:30
isGroupBoard: true,
2023-06-20 00:43:36 +05:30
isApolloBoard,
2021-11-11 11:23:49 +05:30
},
});
};
afterEach(() => {
store = null;
});
it("should have 'is-compact' class when sidebar is open", () => {
createStore();
createComponent();
expect(wrapper.classes()).toContain('is-compact');
});
it("should not have 'is-compact' class when sidebar is closed", () => {
createStore({ mockGetters: { isSidebarOpen: () => false } });
createComponent();
expect(wrapper.classes()).not.toContain('is-compact');
});
2023-06-20 00:43:36 +05:30
describe('Apollo boards', () => {
beforeEach(async () => {
createComponent({ isApolloBoard: true });
await nextTick();
});
2023-07-09 08:55:56 +05:30
it('fetches lists', () => {
expect(boardListQueryHandler).toHaveBeenCalled();
});
2023-06-20 00:43:36 +05:30
it('should have is-compact class when a card is selected', () => {
expect(wrapper.classes()).toContain('is-compact');
});
it('should not have is-compact class when no card is selected', async () => {
createComponent({ isApolloBoard: true, issue: {} });
await nextTick();
expect(wrapper.classes()).not.toContain('is-compact');
});
});
2021-11-11 11:23:49 +05:30
});