debian-mirror-gitlab/spec/javascripts/registry/components/table_registry_spec.js

190 lines
5.8 KiB
JavaScript
Raw Normal View History

2018-03-17 18:26:18 +05:30
import Vue from 'vue';
import tableRegistry from '~/registry/components/table_registry.vue';
import store from '~/registry/stores';
2019-10-12 21:52:04 +05:30
import { mountComponentWithStore } from 'spec/helpers/vue_mount_component_helper';
2018-03-17 18:26:18 +05:30
import { repoPropsData } from '../mock_data';
2019-10-12 21:52:04 +05:30
const [firstImage, secondImage] = repoPropsData.list;
2019-09-30 21:07:59 +05:30
2018-03-17 18:26:18 +05:30
describe('table registry', () => {
let vm;
2019-10-12 21:52:04 +05:30
const Component = Vue.extend(tableRegistry);
const bulkDeletePath = 'path';
2018-03-17 18:26:18 +05:30
2019-09-30 21:07:59 +05:30
const findDeleteBtn = () => vm.$el.querySelector('.js-delete-registry');
2019-10-12 21:52:04 +05:30
const findDeleteBtnRow = () => vm.$el.querySelector('.js-delete-registry-row');
const findSelectAllCheckbox = () => vm.$el.querySelector('.js-select-all-checkbox > input');
const findAllRowCheckboxes = () =>
Array.from(vm.$el.querySelectorAll('.js-select-checkbox input'));
const confirmationModal = (child = '') => document.querySelector(`#${vm.modalId} ${child}`);
2019-09-30 21:07:59 +05:30
2019-10-12 21:52:04 +05:30
const createComponent = () => {
vm = mountComponentWithStore(Component, {
2018-03-17 18:26:18 +05:30
store,
2019-10-12 21:52:04 +05:30
props: {
2018-03-17 18:26:18 +05:30
repo: repoPropsData,
},
2019-10-12 21:52:04 +05:30
});
};
const selectAllCheckboxes = () => vm.selectAll();
const deselectAllCheckboxes = () => vm.deselectAll();
beforeEach(() => {
createComponent();
2018-03-17 18:26:18 +05:30
});
afterEach(() => {
vm.$destroy();
});
2019-10-12 21:52:04 +05:30
describe('rendering', () => {
it('should render a table with the registry list', () => {
expect(vm.$el.querySelectorAll('table tbody tr').length).toEqual(repoPropsData.list.length);
});
it('should render registry tag', () => {
const textRendered = vm.$el
.querySelector('.table tbody tr')
.textContent.trim()
// replace additional whitespace characters (e.g. new lines) with a single empty space
.replace(/\s\s+/g, ' ');
expect(textRendered).toContain(repoPropsData.list[0].tag);
expect(textRendered).toContain(repoPropsData.list[0].shortRevision);
expect(textRendered).toContain(repoPropsData.list[0].layers);
expect(textRendered).toContain(repoPropsData.list[0].size);
});
2018-03-17 18:26:18 +05:30
});
2019-10-12 21:52:04 +05:30
describe('multi select', () => {
it('should support multiselect and selecting a row should enable delete button', done => {
findSelectAllCheckbox().click();
selectAllCheckboxes();
expect(findSelectAllCheckbox().checked).toBe(true);
Vue.nextTick(() => {
expect(findDeleteBtn().disabled).toBe(false);
done();
});
});
it('selecting all checkbox should select all rows and enable delete button', done => {
selectAllCheckboxes();
Vue.nextTick(() => {
const checkedValues = findAllRowCheckboxes().filter(x => x.checked);
expect(checkedValues.length).toBe(repoPropsData.list.length);
done();
});
});
it('deselecting select all checkbox should deselect all rows and disable delete button', done => {
selectAllCheckboxes();
deselectAllCheckboxes();
Vue.nextTick(() => {
const checkedValues = findAllRowCheckboxes().filter(x => x.checked);
expect(checkedValues.length).toBe(0);
done();
});
});
it('should delete multiple items when multiple items are selected', done => {
selectAllCheckboxes();
Vue.nextTick(() => {
expect(vm.itemsToBeDeleted).toEqual([0, 1]);
expect(findDeleteBtn().disabled).toBe(false);
findDeleteBtn().click();
spyOn(vm, 'multiDeleteItems').and.returnValue(Promise.resolve());
Vue.nextTick(() => {
const modal = confirmationModal();
confirmationModal('.btn-danger').click();
expect(modal).toExist();
2018-12-13 13:39:08 +05:30
2019-10-12 21:52:04 +05:30
Vue.nextTick(() => {
expect(vm.itemsToBeDeleted).toEqual([]);
expect(vm.multiDeleteItems).toHaveBeenCalledWith({
path: bulkDeletePath,
items: [firstImage.tag, secondImage.tag],
});
done();
});
});
});
});
2018-03-17 18:26:18 +05:30
});
2019-09-30 21:07:59 +05:30
describe('delete registry', () => {
2019-10-12 21:52:04 +05:30
beforeEach(() => {
vm.itemsToBeDeleted = [0];
2019-09-30 21:07:59 +05:30
});
2019-10-12 21:52:04 +05:30
it('should be possible to delete a registry', done => {
Vue.nextTick(() => {
expect(vm.itemsToBeDeleted).toEqual([0]);
expect(findDeleteBtn()).toBeDefined();
expect(findDeleteBtn().disabled).toBe(false);
expect(findDeleteBtnRow()).toBeDefined();
done();
});
});
2019-09-30 21:07:59 +05:30
2019-10-12 21:52:04 +05:30
it('should call deleteItems and reset itemsToBeDeleted when confirming deletion', done => {
2019-09-30 21:07:59 +05:30
Vue.nextTick(() => {
2019-10-12 21:52:04 +05:30
expect(vm.itemsToBeDeleted).toEqual([0]);
expect(findDeleteBtn().disabled).toBe(false);
findDeleteBtn().click();
spyOn(vm, 'multiDeleteItems').and.returnValue(Promise.resolve());
2019-09-30 21:07:59 +05:30
2019-10-12 21:52:04 +05:30
Vue.nextTick(() => {
confirmationModal('.btn-danger').click();
expect(vm.itemsToBeDeleted).toEqual([]);
expect(vm.multiDeleteItems).toHaveBeenCalledWith({
path: bulkDeletePath,
items: [firstImage.tag],
});
done();
});
2019-09-30 21:07:59 +05:30
});
});
2018-03-17 18:26:18 +05:30
});
describe('pagination', () => {
it('should be possible to change the page', () => {
expect(vm.$el.querySelector('.gl-pagination')).toBeDefined();
});
});
2019-10-12 21:52:04 +05:30
describe('modal content', () => {
it('should show the singular title and image name when deleting a single image', done => {
findDeleteBtnRow().click();
Vue.nextTick(() => {
expect(vm.modalTitle).toBe('Remove image');
expect(vm.modalDescription).toContain(firstImage.tag);
done();
});
});
it('should show the plural title and image count when deleting more than one image', done => {
selectAllCheckboxes();
vm.setModalDescription();
Vue.nextTick(() => {
expect(vm.modalTitle).toBe('Remove images');
expect(vm.modalDescription).toContain('<b>2</b> images');
done();
});
});
});
2018-03-17 18:26:18 +05:30
});