Commit 237f434c authored by Nick Kipling's avatar Nick Kipling Committed by Nathan Friend

Updating with suggestions as per review

parent b5d50025
...@@ -52,7 +52,7 @@ export default { ...@@ -52,7 +52,7 @@ export default {
return this.repo.pagination.total > this.repo.pagination.perPage; return this.repo.pagination.total > this.repo.pagination.perPage;
}, },
modalTitle() { modalTitle() {
if (this.singleItemToBeDeleted !== null || this.itemsToBeDeleted.length === 1) { if (this.singleItemSelected) {
return s__('ContainerRegistry|Remove image'); return s__('ContainerRegistry|Remove image');
} }
return s__('ContainerRegistry|Remove images'); return s__('ContainerRegistry|Remove images');
...@@ -60,7 +60,7 @@ export default { ...@@ -60,7 +60,7 @@ export default {
modalDescription() { modalDescription() {
const selectedCount = this.itemsToBeDeleted.length; const selectedCount = this.itemsToBeDeleted.length;
if (this.singleItemToBeDeleted !== null || selectedCount === 1) { if (this.singleItemSelected) {
const { tag } = const { tag } =
this.singleItemToBeDeleted !== null this.singleItemToBeDeleted !== null
? this.repo.list[this.singleItemToBeDeleted] ? this.repo.list[this.singleItemToBeDeleted]
...@@ -79,6 +79,9 @@ export default { ...@@ -79,6 +79,9 @@ export default {
{ count: selectedCount }, { count: selectedCount },
); );
}, },
singleItemSelected() {
return this.singleItemToBeDeleted !== null || this.itemsToBeDeleted.length === 1;
},
}, },
methods: { methods: {
...mapActions(['fetchList', 'deleteItems']), ...mapActions(['fetchList', 'deleteItems']),
......
import Vue from 'vue'; import Vue from 'vue';
import tableRegistry from '~/registry/components/table_registry.vue'; import tableRegistry from '~/registry/components/table_registry.vue';
import store from '~/registry/stores'; import store from '~/registry/stores';
import { mountComponentWithStore } from 'spec/helpers/vue_mount_component_helper';
import { repoPropsData } from '../mock_data'; import { repoPropsData } from '../mock_data';
const [firstImage, secondImage] = repoPropsData.list; const [firstImage, secondImage] = repoPropsData.list;
describe('table registry', () => { describe('table registry', () => {
let vm; let vm;
let Component; const Component = Vue.extend(tableRegistry);
const bulkDeletePath = 'path'; const bulkDeletePath = 'path';
const findDeleteBtn = () => vm.$el.querySelector('.js-delete-registry'); const findDeleteBtn = () => vm.$el.querySelector('.js-delete-registry');
...@@ -15,17 +16,19 @@ describe('table registry', () => { ...@@ -15,17 +16,19 @@ describe('table registry', () => {
const findSelectAllCheckbox = () => vm.$el.querySelector('.js-select-all-checkbox > input'); const findSelectAllCheckbox = () => vm.$el.querySelector('.js-select-all-checkbox > input');
const findAllRowCheckboxes = () => const findAllRowCheckboxes = () =>
Array.from(vm.$el.querySelectorAll('.js-select-checkbox input')); Array.from(vm.$el.querySelectorAll('.js-select-checkbox input'));
const confirmationModal = (child = '') => document.querySelector(`#${vm.modalId} ${child}`);
const createComponent = () => { const createComponent = () => {
Component = Vue.extend(tableRegistry); vm = mountComponentWithStore(Component, {
vm = new Component({
store, store,
propsData: { props: {
repo: repoPropsData, repo: repoPropsData,
}, },
}).$mount(); });
}; };
const toggleSelectAll = () => vm.selectAll();
beforeEach(() => { beforeEach(() => {
createComponent(); createComponent();
}); });
...@@ -34,6 +37,7 @@ describe('table registry', () => { ...@@ -34,6 +37,7 @@ describe('table registry', () => {
vm.$destroy(); vm.$destroy();
}); });
describe('rendering', () => {
it('should render a table with the registry list', () => { it('should render a table with the registry list', () => {
expect(vm.$el.querySelectorAll('table tbody tr').length).toEqual(repoPropsData.list.length); expect(vm.$el.querySelectorAll('table tbody tr').length).toEqual(repoPropsData.list.length);
}); });
...@@ -49,16 +53,12 @@ describe('table registry', () => { ...@@ -49,16 +53,12 @@ describe('table registry', () => {
expect(textRendered).toContain(repoPropsData.list[0].layers); expect(textRendered).toContain(repoPropsData.list[0].layers);
expect(textRendered).toContain(repoPropsData.list[0].size); expect(textRendered).toContain(repoPropsData.list[0].size);
}); });
describe('multi select', () => {
beforeEach(() => {
vm.itemsToBeDeleted = [];
}); });
describe('multi select', () => {
it('should support multiselect and selecting a row should enable delete button', done => { it('should support multiselect and selecting a row should enable delete button', done => {
findSelectAllCheckbox().click(); findSelectAllCheckbox().click();
toggleSelectAll();
vm.selectAll();
expect(findSelectAllCheckbox().checked).toBe(true); expect(findSelectAllCheckbox().checked).toBe(true);
...@@ -70,7 +70,7 @@ describe('table registry', () => { ...@@ -70,7 +70,7 @@ describe('table registry', () => {
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', done => {
findSelectAllCheckbox().click(); findSelectAllCheckbox().click();
vm.selectAll(); toggleSelectAll();
Vue.nextTick(() => { Vue.nextTick(() => {
const checkedValues = findAllRowCheckboxes().filter(x => x.checked); const checkedValues = findAllRowCheckboxes().filter(x => x.checked);
...@@ -82,8 +82,8 @@ describe('table registry', () => { ...@@ -82,8 +82,8 @@ describe('table registry', () => {
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', done => {
findSelectAllCheckbox().click(); findSelectAllCheckbox().click();
vm.selectAll(); // Select them all on toggleSelectAll(); // Select them all on
vm.selectAll(); // Select them all off toggleSelectAll(); // Select them all off
Vue.nextTick(() => { Vue.nextTick(() => {
const checkedValues = findAllRowCheckboxes().filter(x => x.checked); const checkedValues = findAllRowCheckboxes().filter(x => x.checked);
...@@ -95,7 +95,7 @@ describe('table registry', () => { ...@@ -95,7 +95,7 @@ describe('table registry', () => {
it('should delete multiple items when multiple items are selected', done => { it('should delete multiple items when multiple items are selected', done => {
findSelectAllCheckbox().click(); findSelectAllCheckbox().click();
vm.selectAll(); toggleSelectAll();
Vue.nextTick(() => { Vue.nextTick(() => {
expect(vm.itemsToBeDeleted).toEqual([0, 1]); expect(vm.itemsToBeDeleted).toEqual([0, 1]);
...@@ -105,8 +105,8 @@ describe('table registry', () => { ...@@ -105,8 +105,8 @@ describe('table registry', () => {
spyOn(vm, 'deleteItems').and.returnValue(Promise.resolve()); spyOn(vm, 'deleteItems').and.returnValue(Promise.resolve());
Vue.nextTick(() => { Vue.nextTick(() => {
const modal = document.querySelector(`#${vm.modalId}`); const modal = confirmationModal();
document.querySelector(`#${vm.modalId} .btn-danger`).click(); confirmationModal('.btn-danger').click();
expect(modal).toExist(); expect(modal).toExist();
...@@ -146,7 +146,7 @@ describe('table registry', () => { ...@@ -146,7 +146,7 @@ describe('table registry', () => {
spyOn(vm, 'deleteItems').and.returnValue(Promise.resolve()); spyOn(vm, 'deleteItems').and.returnValue(Promise.resolve());
Vue.nextTick(() => { Vue.nextTick(() => {
document.querySelector(`#${vm.modalId} .btn-danger`).click(); confirmationModal('.btn-danger').click();
expect(vm.itemsToBeDeleted).toEqual([]); expect(vm.itemsToBeDeleted).toEqual([]);
expect(vm.deleteItems).toHaveBeenCalledWith({ expect(vm.deleteItems).toHaveBeenCalledWith({
...@@ -164,4 +164,27 @@ describe('table registry', () => { ...@@ -164,4 +164,27 @@ describe('table registry', () => {
expect(vm.$el.querySelector('.gl-pagination')).toBeDefined(); expect(vm.$el.querySelector('.gl-pagination')).toBeDefined();
}); });
}); });
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 => {
findSelectAllCheckbox().click();
toggleSelectAll();
Vue.nextTick(() => {
expect(vm.modalTitle).toBe('Remove images');
expect(vm.modalDescription).toContain('<b>2</b> images');
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