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

88 lines
2.4 KiB
JavaScript
Raw Normal View History

2019-02-15 15:39:39 +05:30
import MockAdapter from 'axios-mock-adapter';
import axios from '~/lib/utils/axios_utils';
2018-03-17 18:26:18 +05:30
import Vue from 'vue';
import collapsibleComponent from '~/registry/components/collapsible_container.vue';
import store from '~/registry/stores';
2019-02-15 15:39:39 +05:30
import * as types from '~/registry/stores/mutation_types';
import { repoPropsData, registryServerResponse, reposServerResponse } from '../mock_data';
2018-03-17 18:26:18 +05:30
describe('collapsible registry container', () => {
let vm;
2019-02-15 15:39:39 +05:30
let mock;
const Component = Vue.extend(collapsibleComponent);
2018-03-17 18:26:18 +05:30
2019-09-30 21:07:59 +05:30
const findDeleteBtn = () => vm.$el.querySelector('.js-remove-repo');
2018-03-17 18:26:18 +05:30
beforeEach(() => {
2019-02-15 15:39:39 +05:30
mock = new MockAdapter(axios);
mock.onGet(repoPropsData.tagsPath).replyOnce(200, registryServerResponse, {});
store.commit(types.SET_REPOS_LIST, reposServerResponse);
2018-03-17 18:26:18 +05:30
vm = new Component({
store,
propsData: {
repo: repoPropsData,
},
}).$mount();
});
afterEach(() => {
2019-02-15 15:39:39 +05:30
mock.restore();
2018-03-17 18:26:18 +05:30
vm.$destroy();
});
describe('toggle', () => {
it('should be closed by default', () => {
expect(vm.$el.querySelector('.container-image-tags')).toBe(null);
2019-02-15 15:39:39 +05:30
expect(vm.iconName).toEqual('angle-right');
2018-03-17 18:26:18 +05:30
});
2018-12-13 13:39:08 +05:30
it('should be open when user clicks on closed repo', done => {
2018-03-17 18:26:18 +05:30
vm.$el.querySelector('.js-toggle-repo').click();
2019-02-15 15:39:39 +05:30
2018-03-17 18:26:18 +05:30
Vue.nextTick(() => {
2019-02-15 15:39:39 +05:30
expect(vm.$el.querySelector('.container-image-tags')).not.toBeNull();
expect(vm.iconName).toEqual('angle-up');
2018-03-17 18:26:18 +05:30
done();
});
});
2018-12-13 13:39:08 +05:30
it('should be closed when the user clicks on an opened repo', done => {
2018-03-17 18:26:18 +05:30
vm.$el.querySelector('.js-toggle-repo').click();
Vue.nextTick(() => {
vm.$el.querySelector('.js-toggle-repo').click();
2019-02-15 15:39:39 +05:30
setTimeout(() => {
Vue.nextTick(() => {
expect(vm.$el.querySelector('.container-image-tags')).toBe(null);
expect(vm.iconName).toEqual('angle-right');
done();
});
2018-03-17 18:26:18 +05:30
});
});
});
});
describe('delete repo', () => {
it('should be possible to delete a repo', () => {
2019-09-30 21:07:59 +05:30
expect(findDeleteBtn()).not.toBeNull();
});
it('should call deleteItem when confirming deletion', done => {
findDeleteBtn().click();
spyOn(vm, 'deleteItem').and.returnValue(Promise.resolve());
Vue.nextTick(() => {
document.querySelector(`#${vm.modalId} .btn-danger`).click();
expect(vm.deleteItem).toHaveBeenCalledWith(vm.repo);
done();
});
2018-03-17 18:26:18 +05:30
});
});
});