2017-03-13 20:58:26 -04:00
|
|
|
import 'timeago.js';
|
|
|
|
import Vue from 'vue';
|
2017-04-21 11:16:22 -04:00
|
|
|
import environmentItemComp from '~/environments/components/environment_item.vue';
|
2016-11-10 13:58:35 -05:00
|
|
|
|
2017-02-09 06:52:22 -05:00
|
|
|
describe('Environment item', () => {
|
2017-03-13 20:58:26 -04:00
|
|
|
let EnvironmentItem;
|
|
|
|
|
2016-11-10 13:58:35 -05:00
|
|
|
beforeEach(() => {
|
2017-03-13 20:58:26 -04:00
|
|
|
EnvironmentItem = Vue.extend(environmentItemComp);
|
2016-11-10 13:58:35 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
describe('When item is folder', () => {
|
|
|
|
let mockItem;
|
2016-11-15 07:07:11 -05:00
|
|
|
let component;
|
2016-11-10 13:58:35 -05:00
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
mockItem = {
|
|
|
|
name: 'review',
|
2017-02-16 05:23:59 -05:00
|
|
|
folderName: 'review',
|
2017-02-09 06:35:53 -05:00
|
|
|
size: 3,
|
|
|
|
isFolder: true,
|
2017-02-16 05:23:59 -05:00
|
|
|
environment_path: 'url',
|
2019-03-14 13:09:21 -04:00
|
|
|
log_path: 'url',
|
2016-11-10 13:58:35 -05:00
|
|
|
};
|
|
|
|
|
2017-02-09 06:52:22 -05:00
|
|
|
component = new EnvironmentItem({
|
2016-11-10 13:58:35 -05:00
|
|
|
propsData: {
|
|
|
|
model: mockItem,
|
2016-11-15 07:07:11 -05:00
|
|
|
canReadEnvironment: true,
|
2016-11-10 13:58:35 -05:00
|
|
|
},
|
2017-03-13 20:58:26 -04:00
|
|
|
}).$mount();
|
2016-11-15 07:07:11 -05:00
|
|
|
});
|
2016-11-10 13:58:35 -05:00
|
|
|
|
2019-03-14 13:09:21 -04:00
|
|
|
it('should render folder icon and name', () => {
|
2016-11-14 12:22:21 -05:00
|
|
|
expect(component.$el.querySelector('.folder-name').textContent).toContain(mockItem.name);
|
|
|
|
expect(component.$el.querySelector('.folder-icon')).toBeDefined();
|
2016-11-10 13:58:35 -05:00
|
|
|
});
|
|
|
|
|
2019-03-14 13:09:21 -04:00
|
|
|
it('should render the number of children in a badge', () => {
|
2018-10-30 16:28:31 -04:00
|
|
|
expect(component.$el.querySelector('.folder-name .badge').textContent).toContain(
|
|
|
|
mockItem.size,
|
|
|
|
);
|
2016-11-10 13:58:35 -05:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('when item is not folder', () => {
|
2016-11-14 12:22:21 -05:00
|
|
|
let environment;
|
2016-11-15 07:07:11 -05:00
|
|
|
let component;
|
2016-11-14 12:22:21 -05:00
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
environment = {
|
|
|
|
name: 'production',
|
2017-02-03 14:47:56 -05:00
|
|
|
size: 1,
|
2017-02-16 05:23:59 -05:00
|
|
|
state: 'stopped',
|
|
|
|
external_url: 'http://external.com',
|
|
|
|
environment_type: null,
|
|
|
|
last_deployment: {
|
|
|
|
id: 66,
|
|
|
|
iid: 6,
|
|
|
|
sha: '500aabcb17c97bdcf2d0c410b70cb8556f0362dd',
|
|
|
|
ref: {
|
|
|
|
name: 'master',
|
2019-03-20 11:39:27 -04:00
|
|
|
ref_url: 'root/ci-folders/tree/master',
|
2017-02-16 05:23:59 -05:00
|
|
|
},
|
|
|
|
tag: true,
|
|
|
|
'last?': true,
|
|
|
|
user: {
|
|
|
|
name: 'Administrator',
|
|
|
|
username: 'root',
|
|
|
|
id: 1,
|
|
|
|
state: 'active',
|
2018-10-30 16:28:31 -04:00
|
|
|
avatar_url:
|
|
|
|
'https://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80\u0026d=identicon',
|
2017-02-16 05:23:59 -05:00
|
|
|
web_url: 'http://localhost:3000/root',
|
|
|
|
},
|
|
|
|
commit: {
|
|
|
|
id: '500aabcb17c97bdcf2d0c410b70cb8556f0362dd',
|
|
|
|
short_id: '500aabcb',
|
|
|
|
title: 'Update .gitlab-ci.yml',
|
|
|
|
author_name: 'Administrator',
|
|
|
|
author_email: 'admin@example.com',
|
|
|
|
created_at: '2016-11-07T18:28:13.000+00:00',
|
|
|
|
message: 'Update .gitlab-ci.yml',
|
|
|
|
author: {
|
2016-11-14 12:22:21 -05:00
|
|
|
name: 'Administrator',
|
|
|
|
username: 'root',
|
|
|
|
id: 1,
|
|
|
|
state: 'active',
|
2018-10-30 16:28:31 -04:00
|
|
|
avatar_url:
|
|
|
|
'https://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80\u0026d=identicon',
|
2016-11-14 12:22:21 -05:00
|
|
|
web_url: 'http://localhost:3000/root',
|
|
|
|
},
|
2017-02-16 05:23:59 -05:00
|
|
|
commit_path: '/root/ci-folders/tree/500aabcb17c97bdcf2d0c410b70cb8556f0362dd',
|
2017-02-03 14:47:56 -05:00
|
|
|
},
|
2017-02-16 05:23:59 -05:00
|
|
|
deployable: {
|
|
|
|
id: 1279,
|
|
|
|
name: 'deploy',
|
|
|
|
build_path: '/root/ci-folders/builds/1279',
|
|
|
|
retry_path: '/root/ci-folders/builds/1279/retry',
|
|
|
|
created_at: '2016-11-29T18:11:58.430Z',
|
|
|
|
updated_at: '2016-11-29T18:11:58.430Z',
|
|
|
|
},
|
|
|
|
manual_actions: [
|
|
|
|
{
|
|
|
|
name: 'action',
|
|
|
|
play_path: '/play',
|
|
|
|
},
|
|
|
|
],
|
2019-08-21 14:58:04 -04:00
|
|
|
deployed_at: '2016-11-29T18:11:58.430Z',
|
2016-11-14 12:22:21 -05:00
|
|
|
},
|
2018-07-12 06:22:11 -04:00
|
|
|
has_stop_action: true,
|
2017-02-16 05:23:59 -05:00
|
|
|
environment_path: 'root/ci-folders/environments/31',
|
2019-03-14 13:09:21 -04:00
|
|
|
log_path: 'root/ci-folders/environments/31/logs',
|
2017-02-16 05:23:59 -05:00
|
|
|
created_at: '2016-11-07T11:11:16.525Z',
|
|
|
|
updated_at: '2016-11-10T15:55:58.778Z',
|
2016-11-14 12:22:21 -05:00
|
|
|
};
|
|
|
|
|
2017-02-09 06:52:22 -05:00
|
|
|
component = new EnvironmentItem({
|
2016-11-14 12:22:21 -05:00
|
|
|
propsData: {
|
|
|
|
model: environment,
|
2016-11-15 07:07:11 -05:00
|
|
|
canReadEnvironment: true,
|
2016-11-14 12:22:21 -05:00
|
|
|
},
|
2017-03-13 20:58:26 -04:00
|
|
|
}).$mount();
|
2016-11-15 07:07:11 -05:00
|
|
|
});
|
2016-11-10 13:58:35 -05:00
|
|
|
|
2016-11-15 07:07:11 -05:00
|
|
|
it('should render environment name', () => {
|
2018-10-30 16:28:31 -04:00
|
|
|
expect(component.$el.querySelector('.environment-name').textContent).toContain(
|
|
|
|
environment.name,
|
|
|
|
);
|
2016-11-10 13:58:35 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
describe('With deployment', () => {
|
|
|
|
it('should render deployment internal id', () => {
|
2018-10-30 16:28:31 -04:00
|
|
|
expect(component.$el.querySelector('.deployment-column span').textContent).toContain(
|
|
|
|
environment.last_deployment.iid,
|
|
|
|
);
|
2016-11-10 13:58:35 -05:00
|
|
|
|
2018-10-30 16:28:31 -04:00
|
|
|
expect(component.$el.querySelector('.deployment-column span').textContent).toContain('#');
|
2016-11-10 13:58:35 -05:00
|
|
|
});
|
|
|
|
|
2016-11-29 12:40:16 -05:00
|
|
|
it('should render last deployment date', () => {
|
|
|
|
const timeagoInstance = new timeago(); // eslint-disable-line
|
2019-08-21 14:58:04 -04:00
|
|
|
const formatedDate = timeagoInstance.format(environment.last_deployment.deployed_at);
|
2016-11-29 12:40:16 -05:00
|
|
|
|
|
|
|
expect(
|
2016-11-30 09:24:12 -05:00
|
|
|
component.$el.querySelector('.environment-created-date-timeago').textContent,
|
2016-11-29 12:40:16 -05:00
|
|
|
).toContain(formatedDate);
|
|
|
|
});
|
|
|
|
|
2016-11-10 13:58:35 -05:00
|
|
|
describe('With user information', () => {
|
|
|
|
it('should render user avatar with link to profile', () => {
|
2016-11-15 07:07:11 -05:00
|
|
|
expect(
|
2016-11-14 17:37:13 -05:00
|
|
|
component.$el.querySelector('.js-deploy-user-container').getAttribute('href'),
|
2017-02-16 05:23:59 -05:00
|
|
|
).toEqual(environment.last_deployment.user.web_url);
|
2016-11-10 13:58:35 -05:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('With build url', () => {
|
2019-03-14 13:09:21 -04:00
|
|
|
it('should link to build url provided', () => {
|
2018-10-30 16:28:31 -04:00
|
|
|
expect(component.$el.querySelector('.build-link').getAttribute('href')).toEqual(
|
|
|
|
environment.last_deployment.deployable.build_path,
|
|
|
|
);
|
2016-11-10 13:58:35 -05:00
|
|
|
});
|
|
|
|
|
2019-03-14 13:09:21 -04:00
|
|
|
it('should render deployable name and id', () => {
|
2018-10-30 16:28:31 -04:00
|
|
|
expect(component.$el.querySelector('.build-link').getAttribute('href')).toEqual(
|
|
|
|
environment.last_deployment.deployable.build_path,
|
|
|
|
);
|
2016-11-10 13:58:35 -05:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('With commit information', () => {
|
2016-11-15 07:07:11 -05:00
|
|
|
it('should render commit component', () => {
|
2018-10-30 16:28:31 -04:00
|
|
|
expect(component.$el.querySelector('.js-commit-component')).toBeDefined();
|
2016-11-15 07:07:11 -05:00
|
|
|
});
|
2016-11-10 13:58:35 -05:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('With manual actions', () => {
|
2019-03-14 13:09:21 -04:00
|
|
|
it('should render actions component', () => {
|
2018-10-30 16:28:31 -04:00
|
|
|
expect(component.$el.querySelector('.js-manual-actions-container')).toBeDefined();
|
2016-11-10 13:58:35 -05:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('With external URL', () => {
|
|
|
|
it('should render external url component', () => {
|
2018-10-30 16:28:31 -04:00
|
|
|
expect(component.$el.querySelector('.js-external-url-container')).toBeDefined();
|
2016-11-10 13:58:35 -05:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('With stop action', () => {
|
2019-03-14 13:09:21 -04:00
|
|
|
it('should render stop action component', () => {
|
2018-10-30 16:28:31 -04:00
|
|
|
expect(component.$el.querySelector('.js-stop-component-container')).toBeDefined();
|
2016-11-10 13:58:35 -05:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('With retry action', () => {
|
2019-03-14 13:09:21 -04:00
|
|
|
it('should render rollback component', () => {
|
2018-10-30 16:28:31 -04:00
|
|
|
expect(component.$el.querySelector('.js-rollback-component-container')).toBeDefined();
|
2016-11-10 13:58:35 -05:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|