Commit ef34501e authored by Lukas Eipert's avatar Lukas Eipert

Move a few vue_shared specs to jest

This moves a few specs, we removed a few tests that were testing
nothing or the internals of debounce.
parent f3ad7cf8
......@@ -2,10 +2,7 @@ import Vue from 'vue';
import { mount } from '@vue/test-utils';
import { formatDate } from '~/lib/utils/datetime_utility';
import RelatedIssuableItem from '~/vue_shared/components/issue/related_issuable_item.vue';
import {
defaultAssignees,
defaultMilestone,
} from '../../../../javascripts/vue_shared/components/issue/related_issuable_mock_data';
import { defaultAssignees, defaultMilestone } from './related_issuable_mock_data';
describe('RelatedIssuableItem', () => {
let wrapper;
......
......@@ -37,10 +37,10 @@ const MOCK_DATA = {
noteHtml: `
<div class="suggestion">
<div class="line">-oldtest</div>
</div>
</div>
<div class="suggestion">
<div class="line">+newtest</div>
</div>
</div>
`,
isApplied: false,
helpPagePath: 'path_to_docs',
......@@ -59,7 +59,7 @@ describe('Suggestion component', () => {
diffTable = vm.generateDiff(0).$mount().$el;
spyOn(vm, 'renderSuggestions');
jest.spyOn(vm, 'renderSuggestions').mockImplementation(() => {});
vm.renderSuggestions();
Vue.nextTick(done);
});
......@@ -85,10 +85,6 @@ describe('Suggestion component', () => {
expect(diffTable.querySelector('.md-suggestion-diff')).not.toBeNull();
});
it('generates a diff table that contains contents of `oldLineContent`', () => {
expect(diffTable.innerHTML.includes(vm.fromContent)).toBe(true);
});
it('generates a diff table that contains contents the suggested lines', () => {
MOCK_DATA.suggestions[0].diff_lines.forEach(line => {
const text = line.text.substring(1);
......
......@@ -3,7 +3,7 @@ import { head } from 'lodash';
import { GlSearchBoxByType, GlInfiniteScroll } from '@gitlab/ui';
import { mount, createLocalVue } from '@vue/test-utils';
import { trimText } from 'spec/helpers/text_helper';
import { trimText } from 'helpers/text_helper';
import ProjectListItem from '~/vue_shared/components/project_selector/project_list_item.vue';
import ProjectSelector from '~/vue_shared/components/project_selector/project_selector.vue';
......@@ -12,7 +12,6 @@ const localVue = createLocalVue();
describe('ProjectSelector component', () => {
let wrapper;
let vm;
loadJSONFixtures('static/projects.json');
const allProjects = getJSONFixture('static/projects.json');
const searchResults = allProjects.slice(0, 5);
let selected = [];
......@@ -21,9 +20,6 @@ describe('ProjectSelector component', () => {
const findSearchInput = () => wrapper.find(GlSearchBoxByType).find('input');
beforeEach(() => {
jasmine.clock().install();
jasmine.clock().mockDate();
wrapper = mount(Vue.extend(ProjectSelector), {
localVue,
propsData: {
......@@ -41,7 +37,6 @@ describe('ProjectSelector component', () => {
});
afterEach(() => {
jasmine.clock().uninstall();
vm.$destroy();
});
......@@ -49,42 +44,17 @@ describe('ProjectSelector component', () => {
expect(wrapper.findAll('.js-project-list-item').length).toBe(5);
});
it(`triggers a (debounced) search when the search input value changes`, () => {
spyOn(vm, '$emit');
it(`triggers a search when the search input value changes`, () => {
jest.spyOn(vm, '$emit').mockImplementation(() => {});
const query = 'my test query!';
const searchInput = findSearchInput();
searchInput.setValue(query);
searchInput.trigger('input');
expect(vm.$emit).not.toHaveBeenCalledWith();
jasmine.clock().tick(501);
expect(vm.$emit).toHaveBeenCalledWith('searched', query);
});
it(`debounces the search input`, () => {
spyOn(vm, '$emit');
const searchInput = findSearchInput();
const updateSearchQuery = (count = 0) => {
if (count === 10) {
jasmine.clock().tick(101);
expect(vm.$emit).toHaveBeenCalledTimes(1);
expect(vm.$emit).toHaveBeenCalledWith('searched', `search query #9`);
} else {
searchInput.setValue(`search query #${count}`);
searchInput.trigger('input');
jasmine.clock().tick(400);
updateSearchQuery(count + 1);
}
};
updateSearchQuery();
});
it(`includes a placeholder in the search box`, () => {
const searchInput = findSearchInput();
......@@ -92,14 +62,14 @@ describe('ProjectSelector component', () => {
});
it(`triggers a "bottomReached" event when user has scrolled to the bottom of the list`, () => {
spyOn(vm, '$emit');
jest.spyOn(vm, '$emit').mockImplementation(() => {});
wrapper.find(GlInfiniteScroll).vm.$emit('bottomReached');
expect(vm.$emit).toHaveBeenCalledWith('bottomReached');
});
it(`triggers a "projectClicked" event when a project is clicked`, () => {
spyOn(vm, '$emit');
jest.spyOn(vm, '$emit').mockImplementation(() => {});
wrapper.find(ProjectListItem).vm.$emit('click', head(searchResults));
expect(vm.$emit).toHaveBeenCalledWith('projectClicked', head(searchResults));
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment