debian-mirror-gitlab/spec/frontend/comment_templates/pages/index_spec.js

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

46 lines
1.6 KiB
JavaScript
Raw Normal View History

2023-05-27 22:25:52 +05:30
import Vue from 'vue';
import { mount } from '@vue/test-utils';
import VueApollo from 'vue-apollo';
2023-06-20 00:43:36 +05:30
import savedRepliesResponse from 'test_fixtures/graphql/comment_templates/saved_replies.query.graphql.json';
2023-05-27 22:25:52 +05:30
import createMockApollo from 'helpers/mock_apollo_helper';
import waitForPromises from 'helpers/wait_for_promises';
2023-06-20 00:43:36 +05:30
import IndexPage from '~/comment_templates/pages/index.vue';
import ListItem from '~/comment_templates/components/list_item.vue';
import savedRepliesQuery from '~/comment_templates/queries/saved_replies.query.graphql';
2023-05-27 22:25:52 +05:30
let wrapper;
function createMockApolloProvider(response) {
Vue.use(VueApollo);
const requestHandlers = [[savedRepliesQuery, jest.fn().mockResolvedValue(response)]];
return createMockApollo(requestHandlers);
}
function createComponent(options = {}) {
const { mockApollo } = options;
return mount(IndexPage, {
apolloProvider: mockApollo,
});
}
2023-06-20 00:43:36 +05:30
describe('Comment templates index page component', () => {
it('renders list of comment templates', async () => {
2023-05-27 22:25:52 +05:30
const mockApollo = createMockApolloProvider(savedRepliesResponse);
const savedReplies = savedRepliesResponse.data.currentUser.savedReplies.nodes;
wrapper = createComponent({ mockApollo });
await waitForPromises();
expect(wrapper.findAllComponents(ListItem).length).toBe(2);
2023-06-20 00:43:36 +05:30
expect(wrapper.findAllComponents(ListItem).at(0).props('template')).toEqual(
2023-05-27 22:25:52 +05:30
expect.objectContaining(savedReplies[0]),
);
2023-06-20 00:43:36 +05:30
expect(wrapper.findAllComponents(ListItem).at(1).props('template')).toEqual(
2023-05-27 22:25:52 +05:30
expect.objectContaining(savedReplies[1]),
);
});
});