Commit a29c2a71 authored by Paul Slaughter's avatar Paul Slaughter

Merge branch '194259-migrate-file_row_spec' into 'master'

Migrated file_row_spec.js from Karma to Jest

See merge request gitlab-org/gitlab!25832
parents 5889b69a c20b157f
import Vue from 'vue'; import { file } from 'jest/ide/helpers';
import { file } from 'spec/ide/helpers';
import FileRow from '~/vue_shared/components/file_row.vue'; import FileRow from '~/vue_shared/components/file_row.vue';
import mountComponent from '../../helpers/vue_mount_component_helper'; import { mount } from '@vue/test-utils';
describe('File row component', () => { describe('File row component', () => {
let vm; let wrapper;
function createComponent(propsData) { function createComponent(propsData) {
const FileRowComponent = Vue.extend(FileRow); wrapper = mount(FileRow, {
propsData,
vm = mountComponent(FileRowComponent, propsData); });
} }
afterEach(() => { afterEach(() => {
vm.$destroy(); wrapper.destroy();
}); });
it('renders name', () => { it('renders name', () => {
const fileName = 't4';
createComponent({ createComponent({
file: file('t4'), file: file(fileName),
level: 0, level: 0,
}); });
const name = vm.$el.querySelector('.file-row-name'); const name = wrapper.find('.file-row-name');
expect(name.textContent.trim()).toEqual(vm.file.name); expect(name.text().trim()).toEqual(fileName);
}); });
it('emits toggleTreeOpen on click', () => { it('emits toggleTreeOpen on click', () => {
const fileName = 't3';
createComponent({ createComponent({
file: { file: {
...file('t3'), ...file(fileName),
type: 'tree', type: 'tree',
}, },
level: 0, level: 0,
}); });
spyOn(vm, '$emit').and.stub(); jest.spyOn(wrapper.vm, '$emit');
vm.$el.click(); wrapper.element.click();
expect(vm.$emit).toHaveBeenCalledWith('toggleTreeOpen', vm.file.path); expect(wrapper.vm.$emit).toHaveBeenCalledWith('toggleTreeOpen', fileName);
}); });
it('calls scrollIntoView if made active', done => { it('calls scrollIntoView if made active', () => {
createComponent({ createComponent({
file: { file: {
...file(), ...file(),
...@@ -52,14 +53,16 @@ describe('File row component', () => { ...@@ -52,14 +53,16 @@ describe('File row component', () => {
level: 0, level: 0,
}); });
spyOn(vm, 'scrollIntoView').and.stub(); jest.spyOn(wrapper.vm, 'scrollIntoView');
vm.file.active = true; wrapper.setProps({
file: Object.assign({}, wrapper.props('file'), {
vm.$nextTick(() => { active: true,
expect(vm.scrollIntoView).toHaveBeenCalled(); }),
});
done(); return wrapper.vm.$nextTick().then(() => {
expect(wrapper.vm.scrollIntoView).toHaveBeenCalled();
}); });
}); });
...@@ -69,7 +72,7 @@ describe('File row component', () => { ...@@ -69,7 +72,7 @@ describe('File row component', () => {
level: 2, level: 2,
}); });
expect(vm.$el.querySelector('.file-row-name').style.marginLeft).toBe('32px'); expect(wrapper.find('.file-row-name').element.style.marginLeft).toBe('32px');
}); });
it('renders header for file', () => { it('renders header for file', () => {
...@@ -82,6 +85,6 @@ describe('File row component', () => { ...@@ -82,6 +85,6 @@ describe('File row component', () => {
level: 0, level: 0,
}); });
expect(vm.$el.classList).toContain('js-file-row-header'); expect(wrapper.element.classList).toContain('js-file-row-header');
}); });
}); });
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