gitlab-org--gitlab-foss/spec/javascripts/registry/components/app_spec.js

108 lines
2.9 KiB
JavaScript
Raw Normal View History

import MockAdapter from 'axios-mock-adapter';
import axios from '~/lib/utils/axios_utils';
2017-09-22 06:46:55 -04:00
import Vue from 'vue';
import registry from '~/registry/components/app.vue';
import mountComponent from 'spec/helpers/vue_mount_component_helper';
import { TEST_HOST } from 'spec/test_constants';
import { reposServerResponse } from '../mock_data';
2017-09-22 06:46:55 -04:00
describe('Registry List', () => {
const Component = Vue.extend(registry);
2017-09-22 06:46:55 -04:00
let vm;
let mock;
2017-09-22 06:46:55 -04:00
beforeEach(() => {
mock = new MockAdapter(axios);
2017-09-22 06:46:55 -04:00
});
afterEach(() => {
mock.restore();
2017-09-22 06:46:55 -04:00
vm.$destroy();
});
describe('with data', () => {
beforeEach(() => {
mock.onGet(`${TEST_HOST}/foo`).replyOnce(200, reposServerResponse);
2017-09-22 06:46:55 -04:00
vm = mountComponent(Component, { endpoint: `${TEST_HOST}/foo` });
2017-09-22 06:46:55 -04:00
});
2018-10-17 03:13:26 -04:00
it('should render a list of repos', done => {
2017-09-22 06:46:55 -04:00
setTimeout(() => {
expect(vm.$store.state.repos.length).toEqual(reposServerResponse.length);
Vue.nextTick(() => {
2018-10-17 03:13:26 -04:00
expect(vm.$el.querySelectorAll('.container-image').length).toEqual(
reposServerResponse.length,
);
2017-09-22 06:46:55 -04:00
done();
});
}, 0);
});
describe('delete repository', () => {
2018-10-17 03:13:26 -04:00
it('should be possible to delete a repo', done => {
2017-09-22 06:46:55 -04:00
setTimeout(() => {
Vue.nextTick(() => {
expect(vm.$el.querySelector('.container-image-head .js-remove-repo')).toBeDefined();
done();
});
}, 0);
});
});
describe('toggle repository', () => {
2018-10-17 03:13:26 -04:00
it('should open the container', done => {
2017-09-22 06:46:55 -04:00
setTimeout(() => {
Vue.nextTick(() => {
vm.$el.querySelector('.js-toggle-repo').click();
2017-09-22 06:46:55 -04:00
Vue.nextTick(() => {
expect(
vm.$el.querySelector('.js-toggle-repo use').getAttribute('xlink:href'),
).toContain('angle-up');
2017-09-22 06:46:55 -04:00
done();
});
});
}, 0);
});
});
});
describe('without data', () => {
beforeEach(() => {
mock.onGet(`${TEST_HOST}/foo`).replyOnce(200, []);
2017-09-22 06:46:55 -04:00
vm = mountComponent(Component, { endpoint: `${TEST_HOST}/foo` });
2017-09-22 06:46:55 -04:00
});
2018-10-17 03:13:26 -04:00
it('should render empty message', done => {
2017-09-22 06:46:55 -04:00
setTimeout(() => {
expect(
2018-10-17 03:13:26 -04:00
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.',
);
2017-09-22 06:46:55 -04:00
done();
}, 0);
});
});
describe('while loading data', () => {
beforeEach(() => {
mock.onGet(`${TEST_HOST}/foo`).replyOnce(200, []);
2017-09-22 06:46:55 -04:00
vm = mountComponent(Component, { endpoint: `${TEST_HOST}/foo` });
2017-09-22 06:46:55 -04:00
});
2018-10-17 03:13:26 -04:00
it('should render a loading spinner', done => {
2017-09-22 06:46:55 -04:00
Vue.nextTick(() => {
expect(vm.$el.querySelector('.spinner')).not.toBe(null);
2017-09-22 06:46:55 -04:00
done();
});
});
});
});