Commit 605195c2 authored by Filipa Lacerda's avatar Filipa Lacerda

Fix broken tests

parent 9ac8bf2c
...@@ -38,11 +38,11 @@ class EnvironmentsStore { ...@@ -38,11 +38,11 @@ class EnvironmentsStore {
let filtered = {}; let filtered = {};
if (env.size > 1) { if (env.size > 1) {
filtered = Object.assign({}, env, { isFolder: true }); filtered = Object.assign({}, env, { isFolder: true, folderName: env.name });
} }
if (env.latest) { if (env.latest) {
filtered = Object.assign(filtered, env, env.latest, { folderName: env.name }); filtered = Object.assign(filtered, env, env.latest);
delete filtered.latest; delete filtered.latest;
} else { } else {
filtered = Object.assign(filtered, env); filtered = Object.assign(filtered, env);
......
...@@ -14,11 +14,10 @@ describe('Environment item', () => { ...@@ -14,11 +14,10 @@ describe('Environment item', () => {
beforeEach(() => { beforeEach(() => {
mockItem = { mockItem = {
name: 'review', name: 'review',
folderName: 'review',
size: 3, size: 3,
isFolder: true, isFolder: true,
latest: { environment_path: 'url',
environment_path: 'url',
},
}; };
component = new EnvironmentItem({ component = new EnvironmentItem({
...@@ -49,21 +48,36 @@ describe('Environment item', () => { ...@@ -49,21 +48,36 @@ describe('Environment item', () => {
environment = { environment = {
name: 'production', name: 'production',
size: 1, size: 1,
latest: { state: 'stopped',
state: 'stopped', external_url: 'http://external.com',
external_url: 'http://external.com', environment_type: null,
environment_type: null, last_deployment: {
last_deployment: { id: 66,
id: 66, iid: 6,
iid: 6, sha: '500aabcb17c97bdcf2d0c410b70cb8556f0362dd',
sha: '500aabcb17c97bdcf2d0c410b70cb8556f0362dd', ref: {
ref: { name: 'master',
name: 'master', ref_path: 'root/ci-folders/tree/master',
ref_path: 'root/ci-folders/tree/master', },
}, tag: true,
tag: true, 'last?': true,
'last?': true, user: {
user: { name: 'Administrator',
username: 'root',
id: 1,
state: 'active',
avatar_url: 'http://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80\u0026d=identicon',
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: {
name: 'Administrator', name: 'Administrator',
username: 'root', username: 'root',
id: 1, id: 1,
...@@ -71,44 +85,27 @@ describe('Environment item', () => { ...@@ -71,44 +85,27 @@ describe('Environment item', () => {
avatar_url: 'http://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80\u0026d=identicon', avatar_url: 'http://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80\u0026d=identicon',
web_url: 'http://localhost:3000/root', web_url: 'http://localhost:3000/root',
}, },
commit: { commit_path: '/root/ci-folders/tree/500aabcb17c97bdcf2d0c410b70cb8556f0362dd',
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: {
name: 'Administrator',
username: 'root',
id: 1,
state: 'active',
avatar_url: 'http://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80\u0026d=identicon',
web_url: 'http://localhost:3000/root',
},
commit_path: '/root/ci-folders/tree/500aabcb17c97bdcf2d0c410b70cb8556f0362dd',
},
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',
},
],
}, },
'stop_action?': true, deployable: {
environment_path: 'root/ci-folders/environments/31', id: 1279,
created_at: '2016-11-07T11:11:16.525Z', name: 'deploy',
updated_at: '2016-11-10T15:55:58.778Z', 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',
},
],
}, },
'stop_action?': true,
environment_path: 'root/ci-folders/environments/31',
created_at: '2016-11-07T11:11:16.525Z',
updated_at: '2016-11-10T15:55:58.778Z',
}; };
component = new EnvironmentItem({ component = new EnvironmentItem({
...@@ -129,7 +126,7 @@ describe('Environment item', () => { ...@@ -129,7 +126,7 @@ describe('Environment item', () => {
it('should render deployment internal id', () => { it('should render deployment internal id', () => {
expect( expect(
component.$el.querySelector('.deployment-column span').textContent, component.$el.querySelector('.deployment-column span').textContent,
).toContain(environment.latest.last_deployment.iid); ).toContain(environment.last_deployment.iid);
expect( expect(
component.$el.querySelector('.deployment-column span').textContent, component.$el.querySelector('.deployment-column span').textContent,
...@@ -139,7 +136,7 @@ describe('Environment item', () => { ...@@ -139,7 +136,7 @@ describe('Environment item', () => {
it('should render last deployment date', () => { it('should render last deployment date', () => {
const timeagoInstance = new timeago(); // eslint-disable-line const timeagoInstance = new timeago(); // eslint-disable-line
const formatedDate = timeagoInstance.format( const formatedDate = timeagoInstance.format(
environment.latest.last_deployment.deployable.created_at, environment.last_deployment.deployable.created_at,
); );
expect( expect(
...@@ -151,7 +148,7 @@ describe('Environment item', () => { ...@@ -151,7 +148,7 @@ describe('Environment item', () => {
it('should render user avatar with link to profile', () => { it('should render user avatar with link to profile', () => {
expect( expect(
component.$el.querySelector('.js-deploy-user-container').getAttribute('href'), component.$el.querySelector('.js-deploy-user-container').getAttribute('href'),
).toEqual(environment.latest.last_deployment.user.web_url); ).toEqual(environment.last_deployment.user.web_url);
}); });
}); });
...@@ -159,13 +156,13 @@ describe('Environment item', () => { ...@@ -159,13 +156,13 @@ describe('Environment item', () => {
it('Should link to build url provided', () => { it('Should link to build url provided', () => {
expect( expect(
component.$el.querySelector('.build-link').getAttribute('href'), component.$el.querySelector('.build-link').getAttribute('href'),
).toEqual(environment.latest.last_deployment.deployable.build_path); ).toEqual(environment.last_deployment.deployable.build_path);
}); });
it('Should render deployable name and id', () => { it('Should render deployable name and id', () => {
expect( expect(
component.$el.querySelector('.build-link').getAttribute('href'), component.$el.querySelector('.build-link').getAttribute('href'),
).toEqual(environment.latest.last_deployment.deployable.build_path); ).toEqual(environment.last_deployment.deployable.build_path);
}); });
}); });
......
const Store = require('~/environments/stores/environments_store'); const Store = require('~/environments/stores/environments_store');
const { environmentsList } = require('./mock_data'); const { environmentsList, serverData } = require('./mock_data');
(() => { (() => {
describe('Store', () => { describe('Store', () => {
...@@ -17,8 +17,9 @@ const { environmentsList } = require('./mock_data'); ...@@ -17,8 +17,9 @@ const { environmentsList } = require('./mock_data');
}); });
it('should store environments', () => { it('should store environments', () => {
store.storeEnvironments(environmentsList); store.storeEnvironments(serverData);
expect(store.state.environments.length).toEqual(environmentsList.length); expect(store.state.environments.length).toEqual(serverData.length);
expect(store.state.environments[0]).toEqual(environmentsList[0]);
}); });
it('should store available count', () => { it('should store available count', () => {
......
...@@ -8,7 +8,7 @@ describe('Environments Folder View', () => { ...@@ -8,7 +8,7 @@ describe('Environments Folder View', () => {
beforeEach(() => { beforeEach(() => {
loadFixtures('static/environments/environments_folder_view.html.raw'); loadFixtures('static/environments/environments_folder_view.html.raw');
window.history.pushState({}, null, 'environments/folders/51'); window.history.pushState({}, null, 'environments/folders/build');
}); });
let component; let component;
...@@ -80,12 +80,11 @@ describe('Environments Folder View', () => { ...@@ -80,12 +80,11 @@ describe('Environments Folder View', () => {
}, 0); }, 0);
}); });
// FIX ME:
it('should render parent folder name', (done) => { it('should render parent folder name', (done) => {
setTimeout(() => { setTimeout(() => {
expect( expect(
component.$el.querySelector('.js-folder-name'), component.$el.querySelector('.js-folder-name').textContent,
).toBe(null); ).toContain('Environments / build');
done(); done();
}, 0); }, 0);
}); });
...@@ -199,14 +198,5 @@ describe('Environments Folder View', () => { ...@@ -199,14 +198,5 @@ describe('Environments Folder View', () => {
done(); done();
}, 0); }, 0);
}); });
it('should not render parent folder name', (done) => {
setTimeout(() => {
expect(
component.$el.querySelector('.js-folder-name'),
).toBe(null);
done();
}, 0);
});
}); });
}); });
const environmentsList = [ const environmentsList = [
{
name: 'DEV',
size: 1,
id: 7,
state: 'available',
external_url: null,
environment_type: null,
last_deployment: null,
'stop_action?': false,
environment_path: '/root/review-app/environments/7',
stop_path: '/root/review-app/environments/7/stop',
created_at: '2017-01-31T10:53:46.894Z',
updated_at: '2017-01-31T10:53:46.894Z',
},
{
folderName: 'build',
size: 5,
id: 12,
name: 'build/update-README',
state: 'available',
external_url: null,
environment_type: 'build',
last_deployment: null,
'stop_action?': false,
environment_path: '/root/review-app/environments/12',
stop_path: '/root/review-app/environments/12/stop',
created_at: '2017-02-01T19:42:18.400Z',
updated_at: '2017-02-01T19:42:18.400Z',
},
];
const serverData = [
{ {
name: 'DEV', name: 'DEV',
size: 1, size: 1,
...@@ -56,4 +88,5 @@ const environment = { ...@@ -56,4 +88,5 @@ const environment = {
module.exports = { module.exports = {
environmentsList, environmentsList,
environment, environment,
serverData,
}; };
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment