debian-mirror-gitlab/spec/frontend/issues/new/components/title_suggestions_spec.js

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

97 lines
2.6 KiB
JavaScript
Raw Normal View History

2019-02-15 15:39:39 +05:30
import { shallowMount } from '@vue/test-utils';
2023-05-27 22:25:52 +05:30
import Vue from 'vue';
import VueApollo from 'vue-apollo';
import createMockApollo from 'helpers/mock_apollo_helper';
import waitForPromises from 'helpers/wait_for_promises';
2022-01-26 12:08:38 +05:30
import TitleSuggestions from '~/issues/new/components/title_suggestions.vue';
import TitleSuggestionsItem from '~/issues/new/components/title_suggestions_item.vue';
2023-05-27 22:25:52 +05:30
import getIssueSuggestionsQuery from '~/issues/new/queries/issues.query.graphql';
import { mockIssueSuggestionResponse } from '../mock_data';
Vue.use(VueApollo);
const MOCK_PROJECT_PATH = 'project';
const MOCK_ISSUES_COUNT = mockIssueSuggestionResponse.data.project.issues.edges.length;
2019-02-15 15:39:39 +05:30
2022-01-26 12:08:38 +05:30
describe('Issue title suggestions component', () => {
2020-01-01 13:55:28 +05:30
let wrapper;
2023-05-27 22:25:52 +05:30
let mockApollo;
function createComponent({
search = 'search',
queryResponse = jest.fn().mockResolvedValue(mockIssueSuggestionResponse),
} = {}) {
mockApollo = createMockApollo([[getIssueSuggestionsQuery, queryResponse]]);
2019-02-15 15:39:39 +05:30
2022-01-26 12:08:38 +05:30
wrapper = shallowMount(TitleSuggestions, {
2019-02-15 15:39:39 +05:30
propsData: {
search,
2023-05-27 22:25:52 +05:30
projectPath: MOCK_PROJECT_PATH,
2019-02-15 15:39:39 +05:30
},
2023-05-27 22:25:52 +05:30
apolloProvider: mockApollo,
2019-02-15 15:39:39 +05:30
});
}
2023-05-27 22:25:52 +05:30
const waitForDebounce = () => {
jest.runOnlyPendingTimers();
return waitForPromises();
};
2020-01-01 13:55:28 +05:30
2019-02-15 15:39:39 +05:30
afterEach(() => {
2023-05-27 22:25:52 +05:30
mockApollo = null;
2019-02-15 15:39:39 +05:30
});
2022-04-04 11:22:00 +05:30
it('does not render with empty search', async () => {
2023-05-27 22:25:52 +05:30
createComponent({ search: '' });
await waitForDebounce();
2019-02-15 15:39:39 +05:30
2022-04-04 11:22:00 +05:30
expect(wrapper.isVisible()).toBe(false);
2019-02-15 15:39:39 +05:30
});
2023-05-27 22:25:52 +05:30
it('does not render when loading', () => {
createComponent();
expect(wrapper.isVisible()).toBe(false);
});
2019-02-15 15:39:39 +05:30
2023-05-27 22:25:52 +05:30
it('does not render with empty issues data', async () => {
const emptyIssuesResponse = {
data: {
project: {
id: 'gid://gitlab/Project/1',
issues: {
edges: [],
},
},
},
};
2019-02-15 15:39:39 +05:30
2023-05-27 22:25:52 +05:30
createComponent({ queryResponse: jest.fn().mockResolvedValue(emptyIssuesResponse) });
await waitForDebounce();
2019-02-15 15:39:39 +05:30
2023-05-27 22:25:52 +05:30
expect(wrapper.isVisible()).toBe(false);
});
2019-02-15 15:39:39 +05:30
2023-05-27 22:25:52 +05:30
describe('with data', () => {
beforeEach(async () => {
createComponent();
await waitForDebounce();
2019-02-15 15:39:39 +05:30
});
2023-05-27 22:25:52 +05:30
it('renders component', () => {
expect(wrapper.findAll('li').length).toBe(MOCK_ISSUES_COUNT);
2019-02-15 15:39:39 +05:30
});
2023-05-27 22:25:52 +05:30
it('renders list of issues', () => {
expect(wrapper.findAllComponents(TitleSuggestionsItem).length).toBe(MOCK_ISSUES_COUNT);
2019-02-15 15:39:39 +05:30
});
2023-05-27 22:25:52 +05:30
it('adds margin class to first item', () => {
2022-04-04 11:22:00 +05:30
expect(wrapper.findAll('li').at(0).classes()).toContain('gl-mb-3');
2019-02-15 15:39:39 +05:30
});
2023-05-27 22:25:52 +05:30
it('does not add margin class to last item', () => {
2022-04-04 11:22:00 +05:30
expect(wrapper.findAll('li').at(1).classes()).not.toContain('gl-mb-3');
2019-02-15 15:39:39 +05:30
});
});
});