Commit 0d22ab42 authored by Filipa Lacerda's avatar Filipa Lacerda

Adds missing tests

Adds tests and verifies environment has rollout_status key

Remove fake API response
parent 0437d03f
...@@ -101,6 +101,25 @@ module.exports = Vue.component('deploy_boards_components', { ...@@ -101,6 +101,25 @@ module.exports = Vue.component('deploy_boards_components', {
}); });
}, },
computed: {
canRenderDeployBoard() {
return !this.isLoading && !this.hasError && Object.keys(this.deployBoardData).length;
},
instanceTitle() {
let title;
if (this.deployBoardData.instances.length === 1) {
title = 'Instance';
}
if (this.deployBoardData.instances.length > 1) {
title = 'Instances';
}
return title;
},
},
template: ` template: `
<div class="js-deploy-board deploy-board"> <div class="js-deploy-board deploy-board">
...@@ -108,14 +127,17 @@ module.exports = Vue.component('deploy_boards_components', { ...@@ -108,14 +127,17 @@ module.exports = Vue.component('deploy_boards_components', {
<i class="fa fa-spinner fa-spin"></i> <i class="fa fa-spinner fa-spin"></i>
</div> </div>
<div v-if="!isLoading && !hasError"> <div v-if="canRenderDeployBoard">
<section class="deploy-board-information"> <section class="deploy-board-information">
<span>
<span class="percentage">{{deployBoardData.completion}}%</span> <span class="percentage">{{deployBoardData.completion}}%</span>
<span class="text">Complete</span> <span class="text">Complete</span>
</span>
</section> </section>
<section class="deploy-board-instances"> <section class="deploy-board-instances">
<p class="text">Instances</p> <p class="text">{{instanceTitle}}</p>
<div class="deploy-board-instances-container"> <div class="deploy-board-instances-container">
<template v-for="instance in deployBoardData.instances"> <template v-for="instance in deployBoardData.instances">
...@@ -146,7 +168,7 @@ module.exports = Vue.component('deploy_boards_components', { ...@@ -146,7 +168,7 @@ module.exports = Vue.component('deploy_boards_components', {
</section> </section>
</div> </div>
<div v-if="!isLoading && hasError"> <div v-if="!isLoading && hasError" class="deploy-board-error-message">
We can't fetch the data right now. Please try again later. We can't fetch the data right now. Please try again later.
</div> </div>
</div> </div>
......
...@@ -102,13 +102,13 @@ module.exports = Vue.component('environment-component', { ...@@ -102,13 +102,13 @@ module.exports = Vue.component('environment-component', {
methods: { methods: {
/** /**
* Toggles the visibility of the deploy boards to the clicked environment. * Toggles the visibility of the deploy boards of the clicked environment.
* *
* @param {Object} model * @param {Object} model
* @return {Object} * @return {Object}
*/ */
toggleDeployBoard(model) { toggleDeployBoard(model) {
return this.store.toggleDeployBoard(model); return this.store.toggleDeployBoard(model.id);
}, },
/** /**
......
...@@ -419,17 +419,6 @@ module.exports = Vue.component('environment-item', { ...@@ -419,17 +419,6 @@ module.exports = Vue.component('environment-item', {
folderUrl() { folderUrl() {
return `${window.location.pathname}/folders/${this.model.folderName}`; return `${window.location.pathname}/folders/${this.model.folderName}`;
}, },
/**
* If the environment can have a deploy board we need to render an arrow icon
* next to it's name.
*
* @return {Boolean}
*/
hasDeployBoard() {
return true;
// return this.model.rollout_status;
},
}, },
/** /**
...@@ -451,7 +440,7 @@ module.exports = Vue.component('environment-item', { ...@@ -451,7 +440,7 @@ module.exports = Vue.component('environment-item', {
<tr> <tr>
<td> <td>
<span class="deploy-board-icon" <span class="deploy-board-icon"
v-if="!model.isFolder" v-if="model.hasDeployBoard"
v-on:click="toggleDeployBoard(model)"> v-on:click="toggleDeployBoard(model)">
<i v-show="!model.isDeployBoardVisible" <i v-show="!model.isDeployBoardVisible"
......
...@@ -93,8 +93,7 @@ module.exports = Vue.component('environment-table-component', { ...@@ -93,8 +93,7 @@ module.exports = Vue.component('environment-table-component', {
:commit-icon-svg="commitIconSvg" :commit-icon-svg="commitIconSvg"
:toggleDeployBoard="toggleDeployBoard.bind(model)"></tr> :toggleDeployBoard="toggleDeployBoard.bind(model)"></tr>
<tr v-if="model.isDeployBoardVisible" class="js-deploy-board-row"> <tr v-if="model.hasDeployBoard && model.isDeployBoardVisible" class="js-deploy-board-row">
<td colspan="6" class="deploy-board-container"> <td colspan="6" class="deploy-board-container">
<deploy-board <deploy-board
:store="store" :store="store"
...@@ -103,9 +102,7 @@ module.exports = Vue.component('environment-table-component', { ...@@ -103,9 +102,7 @@ module.exports = Vue.component('environment-table-component', {
:deployBoardData="model.deployBoardData"> :deployBoardData="model.deployBoardData">
</deploy-board> </deploy-board>
</td> </td>
</tr> </tr>
</template> </template>
</tbody> </tbody>
</table> </table>
......
...@@ -45,26 +45,26 @@ class EnvironmentsStore { ...@@ -45,26 +45,26 @@ class EnvironmentsStore {
const filteredEnvironments = environments.map((env) => { const filteredEnvironments = environments.map((env) => {
let filtered = {}; let filtered = {};
if (env.latest) {
filtered = Object.assign(filtered, env, env.latest);
delete filtered.latest;
} else {
filtered = Object.assign(filtered, env);
}
if (env.size > 1) { if (env.size > 1) {
filtered = Object.assign({}, env, { isFolder: true, folderName: env.name }); filtered = Object.assign(filtered, env, { isFolder: true, folderName: env.name });
} }
// FIX ME // no folders items with `rollout_status` key can have a deploy board
// no folders items with `x` key can have a deploy board if (env.size === 1 && env.rollout_status) {
if (env.size === 1) { filtered = Object.assign(filtered, env, {
filtered = Object.assign({}, env, { hasDeployBoard: true,
isDeployBoardVisible: false, isDeployBoardVisible: false,
deployBoardData: {}, deployBoardData: {},
}); });
} }
if (env.latest) {
filtered = Object.assign(filtered, env, env.latest);
delete filtered.latest;
} else {
filtered = Object.assign(filtered, env);
}
return filtered; return filtered;
}); });
...@@ -118,18 +118,18 @@ class EnvironmentsStore { ...@@ -118,18 +118,18 @@ class EnvironmentsStore {
} }
/** /**
* Toggles deploy board visibility for the provided environment. * Toggles deploy board visibility for the provided environment ID.
* *
* @param {Object} environment * @param {Object} environment
* @return {Array} * @return {Array}
*/ */
toggleDeployBoard(environment) { toggleDeployBoard(environmentID) {
const environments = Object.assign([], this.state.environments); const environments = Object.assign([], this.state.environments);
this.state.environments = environments.map((env) => { this.state.environments = environments.map((env) => {
let updated = Object.assign({}, env); let updated = Object.assign({}, env);
if (env.id === environment.id) { if (env.id === environmentID) {
updated = Object.assign({}, updated, { isDeployBoardVisible: !env.isDeployBoardVisible }); updated = Object.assign({}, updated, { isDeployBoardVisible: !env.isDeployBoardVisible });
} }
return updated; return updated;
......
...@@ -161,6 +161,10 @@ ...@@ -161,6 +161,10 @@
justify-content: center; justify-content: center;
margin: 20px 10px; margin: 20px 10px;
> span {
text-align: center;
}
.percentage { .percentage {
color: $gl-text-color; color: $gl-text-color;
} }
...@@ -172,7 +176,7 @@ ...@@ -172,7 +176,7 @@
.deploy-board-instances { .deploy-board-instances {
order: 2; order: 2;
max-width: 75%; width: 75%;
.text { .text {
color: $gl-text-color-secondary; color: $gl-text-color-secondary;
...@@ -191,6 +195,10 @@ ...@@ -191,6 +195,10 @@
order: 3; order: 3;
align-self: center; align-self: center;
} }
.deploy-board-error-message {
justify-content: center;
}
} }
.deploy-board-instance { .deploy-board-instance {
...@@ -234,7 +242,7 @@ ...@@ -234,7 +242,7 @@
.deploy-board-icon i { .deploy-board-icon i {
cursor: pointer; cursor: pointer;
color: $border-color; color: $layout-link-gray;
padding-right: 10px; padding-right: 10px;
} }
......
...@@ -61,7 +61,9 @@ describe('Environment item', () => { ...@@ -61,7 +61,9 @@ describe('Environment item', () => {
}); });
expect(component.$el.querySelector('.js-deploy-board-row')).toBeDefined(); expect(component.$el.querySelector('.js-deploy-board-row')).toBeDefined();
expect(component.$el.querySelector('.deploy-board-icon i').classList).toContain('fa-caret-down'); expect(
component.$el.querySelector('.deploy-board-icon i').classList.contains('fa-caret-right'),
).toEqual(true);
}); });
it('should toggle deploy board visibility when arrow is clicked', () => { it('should toggle deploy board visibility when arrow is clicked', () => {
...@@ -82,22 +84,22 @@ describe('Environment item', () => { ...@@ -82,22 +84,22 @@ describe('Environment item', () => {
isDeployBoardVisible: false, isDeployBoardVisible: false,
}; };
const spy = jasmine.createSpy('spy');
const component = new EnvironmentTable({ const component = new EnvironmentTable({
el: document.querySelector('.test-dom-element'), el: document.querySelector('.test-dom-element'),
propsData: { propsData: {
environments: [mockItem], environments: [mockItem],
canCreateDeployment: true, canCreateDeployment: true,
canReadEnvironment: true, canReadEnvironment: true,
toggleDeployBoard: () => {}, toggleDeployBoard: spy,
store: {}, store: {},
service: {}, service: {},
}, },
}); });
expect(component.$el.querySelector('.deploy-board-icon')).toContain('fa-caret-right');
component.$el.querySelector('.deploy-board-icon').click(); component.$el.querySelector('.deploy-board-icon').click();
// expect toggleDeployBoard to have been called expect(spy).toHaveBeenCalled();
}); });
}); });
const Store = require('~/environments/stores/environments_store'); const Store = require('~/environments/stores/environments_store');
const { serverData } = require('./mock_data'); const { serverData, deployBoardMockData } = require('./mock_data');
(() => { (() => {
describe('Store', () => { describe('Environments Store', () => {
let store; let store;
beforeEach(() => { beforeEach(() => {
...@@ -22,14 +22,16 @@ const { serverData } = require('./mock_data'); ...@@ -22,14 +22,16 @@ const { serverData } = require('./mock_data');
expect(store.state.environments.length).toEqual(serverData.length); expect(store.state.environments.length).toEqual(serverData.length);
}); });
it('should store a non folder environment with deploy board if x key is provided', () => { it('should store a non folder environment with deploy board if rollout_status key is provided', () => {
const environment = { const environment = {
name: 'foo', name: 'foo',
size: 1, size: 1,
id: 1, id: 1,
rollout_status: 'url',
}; };
store.storeEnvironments([environment]); store.storeEnvironments([environment]);
expect(store.state.environments[0].hasDeployBoard).toEqual(true);
expect(store.state.environments[0].isDeployBoardVisible).toEqual(false); expect(store.state.environments[0].isDeployBoardVisible).toEqual(false);
expect(store.state.environments[0].deployBoardData).toEqual({}); expect(store.state.environments[0].deployBoardData).toEqual({});
}); });
...@@ -99,12 +101,24 @@ const { serverData } = require('./mock_data'); ...@@ -99,12 +101,24 @@ const { serverData } = require('./mock_data');
}); });
describe('deploy boards', () => { describe('deploy boards', () => {
it('should toggle deploy board property for given environment id', () => { beforeEach(() => {
const environment = {
name: 'foo',
size: 1,
id: 1,
};
store.storeEnvironments([environment]);
}); });
it('should store deploy board data for given environment id', () => { it('should toggle deploy board property for given environment id', () => {
store.toggleDeployBoard(1);
expect(store.state.environments[0].isDeployBoardVisible).toEqual(true);
});
it('should store deploy board data for given environment id', () => {
store.storeDeployBoard(1, deployBoardMockData);
expect(store.state.environments[0].deployBoardData).toEqual(deployBoardMockData);
}); });
}); });
}); });
......
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