Commit 2ffff0ee authored by Natalia Tepluhina's avatar Natalia Tepluhina

Merge branch 'nmezzopera-clean-registry-list-tests' into 'master'

Clean registry list tests

See merge request gitlab-org/gitlab!22470
parents 26c6bdca 802f0b38
import Vue from 'vue';
import { mount } from '@vue/test-utils'; import { mount } from '@vue/test-utils';
import { TEST_HOST } from 'helpers/test_constants'; import { TEST_HOST } from 'helpers/test_constants';
import registry from '~/registry/list/components/app.vue'; import registry from '~/registry/list/components/app.vue';
...@@ -35,12 +34,8 @@ describe('Registry List', () => { ...@@ -35,12 +34,8 @@ describe('Registry List', () => {
}; };
beforeEach(() => { beforeEach(() => {
// This is needed due to console.error called by vue to emit a warning that stop the tests.
// See https://github.com/vuejs/vue-test-utils/issues/532.
Vue.config.silent = true;
wrapper = mount(registry, { wrapper = mount(registry, {
attachToDocument: true, attachToDocument: true,
sync: false,
propsData, propsData,
computed: { computed: {
repos() { repos() {
...@@ -52,7 +47,6 @@ describe('Registry List', () => { ...@@ -52,7 +47,6 @@ describe('Registry List', () => {
}); });
afterEach(() => { afterEach(() => {
Vue.config.silent = false;
wrapper.destroy(); wrapper.destroy();
}); });
...@@ -138,7 +132,7 @@ describe('Registry List', () => { ...@@ -138,7 +132,7 @@ describe('Registry List', () => {
wrapper = mount(registry, { wrapper = mount(registry, {
propsData: { propsData: {
...propsData, ...propsData,
endpoint: null, endpoint: '',
isGroupPage, isGroupPage,
}, },
methods, methods,
...@@ -146,7 +140,7 @@ describe('Registry List', () => { ...@@ -146,7 +140,7 @@ describe('Registry List', () => {
}); });
it('call the right vuex setters', () => { it('call the right vuex setters', () => {
expect(methods.setMainEndpoint).toHaveBeenLastCalledWith(null); expect(methods.setMainEndpoint).toHaveBeenLastCalledWith('');
expect(methods.setIsDeleteDisabled).toHaveBeenLastCalledWith(true); expect(methods.setIsDeleteDisabled).toHaveBeenLastCalledWith(true);
}); });
......
import Vue from 'vue';
import Vuex from 'vuex'; import Vuex from 'vuex';
import { mount, createLocalVue } from '@vue/test-utils'; import { mount, createLocalVue } from '@vue/test-utils';
import createFlash from '~/flash'; import createFlash from '~/flash';
...@@ -28,14 +27,10 @@ describe('collapsible registry container', () => { ...@@ -28,14 +27,10 @@ describe('collapsible registry container', () => {
store, store,
localVue, localVue,
attachToDocument: true, attachToDocument: true,
sync: false,
}); });
beforeEach(() => { beforeEach(() => {
createFlash.mockClear(); createFlash.mockClear();
// This is needed due to console.error called by vue to emit a warning that stop the tests
// see https://github.com/vuejs/vue-test-utils/issues/532
Vue.config.silent = true;
store = new Vuex.Store({ store = new Vuex.Store({
state: { state: {
isDeleteDisabled: false, isDeleteDisabled: false,
...@@ -51,7 +46,6 @@ describe('collapsible registry container', () => { ...@@ -51,7 +46,6 @@ describe('collapsible registry container', () => {
}); });
afterEach(() => { afterEach(() => {
Vue.config.silent = false;
wrapper.destroy(); wrapper.destroy();
}); });
...@@ -72,25 +66,23 @@ describe('collapsible registry container', () => { ...@@ -72,25 +66,23 @@ describe('collapsible registry container', () => {
expectIsClosed(); expectIsClosed();
}); });
it('should be open when user clicks on closed repo', done => { it('should be open when user clicks on closed repo', () => {
const toggleRepos = findToggleRepos(); const toggleRepos = findToggleRepos();
toggleRepos.at(0).trigger('click'); toggleRepos.at(0).trigger('click');
Vue.nextTick(() => { return wrapper.vm.$nextTick().then(() => {
const container = findContainerImageTags(); const container = findContainerImageTags();
expect(container.exists()).toBe(true); expect(container.exists()).toBe(true);
expect(wrapper.vm.fetchList).toHaveBeenCalled(); expect(wrapper.vm.fetchList).toHaveBeenCalled();
done();
}); });
}); });
it('should be closed when the user clicks on an opened repo', done => { it('should be closed when the user clicks on an opened repo', () => {
const toggleRepos = findToggleRepos(); const toggleRepos = findToggleRepos();
toggleRepos.at(0).trigger('click'); toggleRepos.at(0).trigger('click');
Vue.nextTick(() => { return wrapper.vm.$nextTick().then(() => {
toggleRepos.at(0).trigger('click'); toggleRepos.at(0).trigger('click');
Vue.nextTick(() => { wrapper.vm.$nextTick(() => {
expectIsClosed(); expectIsClosed();
done();
}); });
}); });
}); });
......
import Vue from 'vue';
import Vuex from 'vuex'; import Vuex from 'vuex';
import { mount, createLocalVue } from '@vue/test-utils'; import { mount, createLocalVue } from '@vue/test-utils';
import createFlash from '~/flash'; import createFlash from '~/flash';
...@@ -29,13 +28,9 @@ describe('table registry', () => { ...@@ -29,13 +28,9 @@ describe('table registry', () => {
const bulkDeletePath = 'path'; const bulkDeletePath = 'path';
const mountWithStore = config => const mountWithStore = config =>
mount(tableRegistry, { ...config, store, localVue, attachToDocument: true, sync: false }); mount(tableRegistry, { ...config, store, localVue, attachToDocument: true });
beforeEach(() => { beforeEach(() => {
// This is needed due to console.error called by vue to emit a warning that stop the tests
// see https://github.com/vuejs/vue-test-utils/issues/532
Vue.config.silent = true;
store = new Vuex.Store({ store = new Vuex.Store({
state: { state: {
isDeleteDisabled: false, isDeleteDisabled: false,
...@@ -52,7 +47,6 @@ describe('table registry', () => { ...@@ -52,7 +47,6 @@ describe('table registry', () => {
}); });
afterEach(() => { afterEach(() => {
Vue.config.silent = false;
wrapper.destroy(); wrapper.destroy();
}); });
...@@ -82,53 +76,53 @@ describe('table registry', () => { ...@@ -82,53 +76,53 @@ describe('table registry', () => {
}); });
describe('multi select', () => { describe('multi select', () => {
it('selecting a row should enable delete button', done => { it('selecting a row should enable delete button', () => {
const deleteBtn = findDeleteButton(); const deleteBtn = findDeleteButton();
const checkboxes = findSelectCheckboxes(); const checkboxes = findSelectCheckboxes();
expect(deleteBtn.attributes('disabled')).toBe('disabled'); expect(deleteBtn.attributes('disabled')).toBe('disabled');
checkboxes.at(0).trigger('click'); checkboxes.at(0).trigger('click');
Vue.nextTick(() => { return wrapper.vm.$nextTick().then(() => {
expect(deleteBtn.attributes('disabled')).toEqual(undefined); expect(deleteBtn.attributes('disabled')).toEqual(undefined);
done();
}); });
}); });
it('selecting all checkbox should select all rows and enable delete button', done => { it('selecting all checkbox should select all rows and enable delete button', () => {
const selectAll = findSelectAllCheckbox(); const selectAll = findSelectAllCheckbox();
selectAll.trigger('click'); selectAll.trigger('click');
Vue.nextTick(() => { return wrapper.vm.$nextTick().then(() => {
const checkboxes = findSelectCheckboxes(); const checkboxes = findSelectCheckboxes();
const checked = checkboxes.filter(w => w.element.checked); const checked = checkboxes.filter(w => w.element.checked);
expect(checked.length).toBe(checkboxes.length); expect(checked.length).toBe(checkboxes.length);
done();
}); });
}); });
it('deselecting select all checkbox should deselect all rows and disable delete button', done => { it('deselecting select all checkbox should deselect all rows and disable delete button', () => {
const checkboxes = findSelectCheckboxes(); const checkboxes = findSelectCheckboxes();
const selectAll = findSelectAllCheckbox(); const selectAll = findSelectAllCheckbox();
selectAll.trigger('click'); selectAll.trigger('click');
selectAll.trigger('click'); selectAll.trigger('click');
Vue.nextTick(() => { return wrapper.vm.$nextTick().then(() => {
const checked = checkboxes.filter(w => !w.element.checked); const checked = checkboxes.filter(w => !w.element.checked);
expect(checked.length).toBe(checkboxes.length); expect(checked.length).toBe(checkboxes.length);
done();
}); });
}); });
it('should delete multiple items when multiple items are selected', done => { it('should delete multiple items when multiple items are selected', () => {
const multiDeleteItems = jest.fn().mockResolvedValue(); const multiDeleteItems = jest.fn().mockResolvedValue();
wrapper.setMethods({ multiDeleteItems }); wrapper.setMethods({ multiDeleteItems });
Vue.nextTick(() => { return wrapper.vm
.$nextTick()
.then(() => {
const selectAll = findSelectAllCheckbox(); const selectAll = findSelectAllCheckbox();
selectAll.trigger('click'); selectAll.trigger('click');
return wrapper.vm.$nextTick();
Vue.nextTick(() => { })
.then(() => {
const deleteBtn = findDeleteButton(); const deleteBtn = findDeleteButton();
expect(wrapper.vm.selectedItems).toEqual([0, 1]); expect(wrapper.vm.selectedItems).toEqual([0, 1]);
expect(deleteBtn.attributes('disabled')).toEqual(undefined); expect(deleteBtn.attributes('disabled')).toEqual(undefined);
...@@ -140,8 +134,6 @@ describe('table registry', () => { ...@@ -140,8 +134,6 @@ describe('table registry', () => {
path: bulkDeletePath, path: bulkDeletePath,
items: [firstImage.tag, secondImage.tag], items: [firstImage.tag, secondImage.tag],
}); });
done();
});
}); });
}); });
......
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