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

108 lines
2.9 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 registry from '~/registry/components/app.vue';
2018-03-27 19:54:05 +05:30
import mountComponent from 'spec/helpers/vue_mount_component_helper';
2019-02-15 15:39:39 +05:30
import { TEST_HOST } from 'spec/test_constants';
2018-03-17 18:26:18 +05:30
import { reposServerResponse } from '../mock_data';
describe('Registry List', () => {
2019-02-15 15:39:39 +05:30
const Component = Vue.extend(registry);
2018-03-17 18:26:18 +05:30
let vm;
2019-02-15 15:39:39 +05:30
let mock;
2018-03-17 18:26:18 +05:30
beforeEach(() => {
2019-02-15 15:39:39 +05:30
mock = new MockAdapter(axios);
2018-03-17 18:26:18 +05:30
});
afterEach(() => {
2019-02-15 15:39:39 +05:30
mock.restore();
2018-03-17 18:26:18 +05:30
vm.$destroy();
});
describe('with data', () => {
beforeEach(() => {
2019-02-15 15:39:39 +05:30
mock.onGet(`${TEST_HOST}/foo`).replyOnce(200, reposServerResponse);
2018-03-17 18:26:18 +05:30
2019-02-15 15:39:39 +05:30
vm = mountComponent(Component, { endpoint: `${TEST_HOST}/foo` });
2018-03-17 18:26:18 +05:30
});
2018-12-13 13:39:08 +05:30
it('should render a list of repos', done => {
2018-03-17 18:26:18 +05:30
setTimeout(() => {
expect(vm.$store.state.repos.length).toEqual(reposServerResponse.length);
Vue.nextTick(() => {
2018-12-13 13:39:08 +05:30
expect(vm.$el.querySelectorAll('.container-image').length).toEqual(
reposServerResponse.length,
);
2018-03-17 18:26:18 +05:30
done();
});
}, 0);
});
describe('delete repository', () => {
2018-12-13 13:39:08 +05:30
it('should be possible to delete a repo', done => {
2018-03-17 18:26:18 +05:30
setTimeout(() => {
Vue.nextTick(() => {
expect(vm.$el.querySelector('.container-image-head .js-remove-repo')).toBeDefined();
done();
});
}, 0);
});
});
describe('toggle repository', () => {
2018-12-13 13:39:08 +05:30
it('should open the container', done => {
2018-03-17 18:26:18 +05:30
setTimeout(() => {
Vue.nextTick(() => {
vm.$el.querySelector('.js-toggle-repo').click();
Vue.nextTick(() => {
2019-02-15 15:39:39 +05:30
expect(
vm.$el.querySelector('.js-toggle-repo use').getAttribute('xlink:href'),
).toContain('angle-up');
2018-03-17 18:26:18 +05:30
done();
});
});
}, 0);
});
});
});
describe('without data', () => {
beforeEach(() => {
2019-02-15 15:39:39 +05:30
mock.onGet(`${TEST_HOST}/foo`).replyOnce(200, []);
2018-03-17 18:26:18 +05:30
2019-02-15 15:39:39 +05:30
vm = mountComponent(Component, { endpoint: `${TEST_HOST}/foo` });
2018-03-17 18:26:18 +05:30
});
2018-12-13 13:39:08 +05:30
it('should render empty message', done => {
2018-03-17 18:26:18 +05:30
setTimeout(() => {
expect(
2018-12-13 13:39:08 +05:30
vm.$el
.querySelector('p')
.textContent.trim()
.replace(/[\r\n]+/g, ' '),
).toEqual(
'No container images stored for this project. Add one by following the instructions above.',
);
2018-03-17 18:26:18 +05:30
done();
}, 0);
});
});
describe('while loading data', () => {
beforeEach(() => {
2019-02-15 15:39:39 +05:30
mock.onGet(`${TEST_HOST}/foo`).replyOnce(200, []);
2018-03-17 18:26:18 +05:30
2019-02-15 15:39:39 +05:30
vm = mountComponent(Component, { endpoint: `${TEST_HOST}/foo` });
2018-03-17 18:26:18 +05:30
});
2018-12-13 13:39:08 +05:30
it('should render a loading spinner', done => {
2018-03-17 18:26:18 +05:30
Vue.nextTick(() => {
expect(vm.$el.querySelector('.fa-spinner')).not.toBe(null);
done();
});
});
});
});