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

137 lines
3.4 KiB
JavaScript
Raw Normal View History

2019-01-03 12:48:30 +05:30
import _ from 'underscore';
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';
2018-03-17 18:26:18 +05:30
import { reposServerResponse } from '../mock_data';
describe('Registry List', () => {
let vm;
2019-01-03 12:48:30 +05:30
let Component;
2018-03-17 18:26:18 +05:30
beforeEach(() => {
2019-01-03 12:48:30 +05:30
Component = Vue.extend(registry);
2018-03-17 18:26:18 +05:30
});
afterEach(() => {
vm.$destroy();
});
describe('with data', () => {
2019-01-03 12:48:30 +05:30
const interceptor = (request, next) => {
next(
request.respondWith(JSON.stringify(reposServerResponse), {
status: 200,
}),
);
};
2018-03-17 18:26:18 +05:30
beforeEach(() => {
2019-01-03 12:48:30 +05:30
Vue.http.interceptors.push(interceptor);
vm = mountComponent(Component, { endpoint: 'foo' });
});
2018-03-17 18:26:18 +05:30
2019-01-03 12:48:30 +05:30
afterEach(() => {
Vue.http.interceptors = _.without(Vue.http.interceptors, interceptor);
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-01-03 12:48:30 +05:30
expect(vm.$el.querySelector('.js-toggle-repo i').className).toEqual(
'fa fa-chevron-up',
);
2018-03-17 18:26:18 +05:30
done();
});
});
}, 0);
});
});
});
describe('without data', () => {
2019-01-03 12:48:30 +05:30
const interceptor = (request, next) => {
next(
request.respondWith(JSON.stringify([]), {
status: 200,
}),
);
};
2018-03-17 18:26:18 +05:30
beforeEach(() => {
2019-01-03 12:48:30 +05:30
Vue.http.interceptors.push(interceptor);
vm = mountComponent(Component, { endpoint: 'foo' });
});
2018-03-17 18:26:18 +05:30
2019-01-03 12:48:30 +05:30
afterEach(() => {
Vue.http.interceptors = _.without(Vue.http.interceptors, interceptor);
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', () => {
2019-01-03 12:48:30 +05:30
const interceptor = (request, next) => {
next(
request.respondWith(JSON.stringify(reposServerResponse), {
status: 200,
}),
);
};
2018-03-17 18:26:18 +05:30
beforeEach(() => {
2019-01-03 12:48:30 +05:30
Vue.http.interceptors.push(interceptor);
vm = mountComponent(Component, { endpoint: 'foo' });
});
2018-03-17 18:26:18 +05:30
2019-01-03 12:48:30 +05:30
afterEach(() => {
Vue.http.interceptors = _.without(Vue.http.interceptors, interceptor);
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();
});
});
});
});