Commit eccf0728 authored by Thong Kuah's avatar Thong Kuah Committed by Jose Vargas

Move toggleDeployBoard function to core

https://gitlab.com/gitlab-org/gitlab/-/merge_requests/47147
parent 6151f1e2
......@@ -135,12 +135,22 @@ export default class EnvironmentsStore {
/**
* Toggles deploy board visibility for the provided environment ID.
* Currently only works on EE.
*
* @param {Object} environment
* @return {Array}
*/
toggleDeployBoard() {
toggleDeployBoard(environmentID) {
const environments = this.state.environments.slice();
this.state.environments = environments.map(env => {
let updated = { ...env };
if (env.id === environmentID) {
updated = { ...updated, isDeployBoardVisible: !env.isDeployBoardVisible };
}
return updated;
});
return this.state.environments;
}
......
import CeEnvironmentsStore from '~/environments/stores/environments_store';
export default class EnvironmentsStore extends CeEnvironmentsStore {
// TODO: delete when deploy boards moved to Core
storeEnvironments(environments = []) {
super.storeEnvironments(environments);
......@@ -15,24 +16,4 @@ export default class EnvironmentsStore extends CeEnvironmentsStore {
this.state.environments[0].showCanaryCallout = true;
}
}
/**
* Toggles deploy board visibility for the provided environment ID.
*
* @param {Object} environment
* @return {Array}
*/
toggleDeployBoard(environmentID) {
const environments = this.state.environments.slice();
this.state.environments = environments.map((env) => {
let updated = { ...env };
if (env.id === environmentID) {
updated = { ...updated, isDeployBoardVisible: !env.isDeployBoardVisible };
}
return updated;
});
return this.state.environments;
}
}
......@@ -39,12 +39,6 @@ describe('Store', () => {
store.storeEnvironments([environment]);
});
it('should toggle deploy board property for given environment id', () => {
store.toggleDeployBoard(1);
expect(store.state.environments[0].isDeployBoardVisible).toEqual(false);
});
it('should keep deploy board data when updating environments', () => {
expect(store.state.environments[0].deployBoardData).toEqual(deployBoardMockData);
......
// TODO remove
export const deployBoardMockData = {
instances: [
{ status: 'finished', tooltip: 'tanuki-2334 Finished', pod_name: 'production-tanuki-1' },
......
import Store from '~/environments/stores/environments_store';
import { environmentsList, serverData } from './mock_data';
import { environmentsList, serverData, deployBoardMockData } from './mock_data';
describe('Store', () => {
let store;
......@@ -76,6 +76,27 @@ describe('Store', () => {
expect(store.state.environments[1].folderName).toEqual(serverData[1].name);
});
describe('deploy boards', () => {
beforeEach(() => {
const environment = {
name: 'foo',
size: 1,
latest: {
id: 1,
},
rollout_status: deployBoardMockData,
};
store.storeEnvironments([environment]);
});
it('should toggle deploy board property for given environment id', () => {
store.toggleDeployBoard(1);
expect(store.state.environments[0].isDeployBoardVisible).toEqual(false);
});
});
describe('toggleFolder', () => {
it('should toggle folder', () => {
store.storeEnvironments(serverData);
......
......@@ -26,6 +26,42 @@ const buildProps = {
updated_at: '2017-02-01T19:42:18.400Z',
};
const deployBoardMockData = {
instances: [
{ status: 'finished', tooltip: 'tanuki-2334 Finished', pod_name: 'production-tanuki-1' },
{ status: 'finished', tooltip: 'tanuki-2335 Finished', pod_name: 'production-tanuki-1' },
{ status: 'finished', tooltip: 'tanuki-2336 Finished', pod_name: 'production-tanuki-1' },
{ status: 'finished', tooltip: 'tanuki-2337 Finished', pod_name: 'production-tanuki-1' },
{ status: 'finished', tooltip: 'tanuki-2338 Finished', pod_name: 'production-tanuki-1' },
{ status: 'finished', tooltip: 'tanuki-2339 Finished', pod_name: 'production-tanuki-1' },
{ status: 'finished', tooltip: 'tanuki-2340 Finished', pod_name: 'production-tanuki-1' },
{ status: 'finished', tooltip: 'tanuki-2334 Finished', pod_name: 'production-tanuki-1' },
{ status: 'finished', tooltip: 'tanuki-2335 Finished', pod_name: 'production-tanuki-1' },
{ status: 'finished', tooltip: 'tanuki-2336 Finished', pod_name: 'production-tanuki-1' },
{ status: 'finished', tooltip: 'tanuki-2337 Finished', pod_name: 'production-tanuki-1' },
{ status: 'finished', tooltip: 'tanuki-2338 Finished', pod_name: 'production-tanuki-1' },
{ status: 'finished', tooltip: 'tanuki-2339 Finished', pod_name: 'production-tanuki-1' },
{ status: 'finished', tooltip: 'tanuki-2340 Finished', pod_name: 'production-tanuki-1' },
{ status: 'deploying', tooltip: 'tanuki-2341 Deploying', pod_name: 'production-tanuki-1' },
{ status: 'deploying', tooltip: 'tanuki-2342 Deploying', pod_name: 'production-tanuki-1' },
{ status: 'deploying', tooltip: 'tanuki-2343 Deploying', pod_name: 'production-tanuki-1' },
{ status: 'failed', tooltip: 'tanuki-2344 Failed', pod_name: 'production-tanuki-1' },
{ status: 'ready', tooltip: 'tanuki-2345 Ready', pod_name: 'production-tanuki-1' },
{ status: 'ready', tooltip: 'tanuki-2346 Ready', pod_name: 'production-tanuki-1' },
{ status: 'preparing', tooltip: 'tanuki-2348 Preparing', pod_name: 'production-tanuki-1' },
{ status: 'preparing', tooltip: 'tanuki-2349 Preparing', pod_name: 'production-tanuki-1' },
{ status: 'preparing', tooltip: 'tanuki-2350 Preparing', pod_name: 'production-tanuki-1' },
{ status: 'preparing', tooltip: 'tanuki-2353 Preparing', pod_name: 'production-tanuki-1' },
{ status: 'waiting', tooltip: 'tanuki-2354 Waiting', pod_name: 'production-tanuki-1' },
{ status: 'waiting', tooltip: 'tanuki-2355 Waiting', pod_name: 'production-tanuki-1' },
{ status: 'waiting', tooltip: 'tanuki-2356 Waiting', pod_name: 'production-tanuki-1' },
],
abort_url: 'url',
rollback_url: 'url',
completion: 100,
status: 'found',
};
const environment = {
name: 'production',
size: 1,
......@@ -262,4 +298,4 @@ const tableData = {
},
};
export { environment, environmentsList, folder, serverData, tableData };
export { environment, environmentsList, folder, serverData, tableData, 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