gitlab-org--gitlab-foss/spec/javascripts/environments/environments_store_spec.js.es6

72 lines
2.8 KiB
JavaScript
Raw Normal View History

/* global environmentsList */
2016-10-25 10:14:08 -04:00
//= require vue
//= require environments/stores/environments_store
2016-10-25 10:14:08 -04:00
//= require ./mock_data
2016-10-25 10:14:08 -04:00
(() => {
describe('Store', () => {
beforeEach(() => {
gl.environmentsList.EnvironmentsStore.create();
});
2016-10-26 13:17:00 -04:00
it('should start with a blank state', () => {
2016-10-25 10:14:08 -04:00
expect(gl.environmentsList.EnvironmentsStore.state.environments.length).toBe(0);
2016-10-26 13:17:00 -04:00
expect(gl.environmentsList.EnvironmentsStore.state.stoppedCounter).toBe(0);
2016-11-07 16:11:58 -05:00
expect(gl.environmentsList.EnvironmentsStore.state.availableCounter).toBe(0);
2016-10-25 10:14:08 -04:00
});
2016-10-26 04:17:32 -04:00
2016-10-26 13:17:00 -04:00
describe('store environments', () => {
beforeEach(() => {
2016-11-07 16:11:58 -05:00
gl.environmentsList.EnvironmentsStore.storeEnvironments(environmentsList);
2016-10-26 13:17:00 -04:00
});
it('should count stopped environments and save the count in the state', () => {
expect(gl.environmentsList.EnvironmentsStore.state.stoppedCounter).toBe(1);
});
it('should count available environments and save the count in the state', () => {
2016-11-07 16:11:58 -05:00
expect(gl.environmentsList.EnvironmentsStore.state.availableCounter).toBe(3);
2016-10-26 13:17:00 -04:00
});
it('should store environments with same environment_type as sibilings', () => {
2016-11-07 16:11:58 -05:00
expect(gl.environmentsList.EnvironmentsStore.state.environments.length).toBe(3);
2016-10-27 05:51:44 -04:00
2016-11-07 16:11:58 -05:00
const parentFolder = gl.environmentsList.EnvironmentsStore.state.environments
.filter(env => env.children && env.children.length > 0);
2016-10-26 13:17:00 -04:00
expect(parentFolder[0].children.length).toBe(2);
expect(parentFolder[0].children[0].environment_type).toBe('review');
expect(parentFolder[0].children[1].environment_type).toBe('review');
2016-11-07 16:11:58 -05:00
expect(parentFolder[0].children[0].name).toBe('test-environment');
expect(parentFolder[0].children[1].name).toBe('test-environment-1');
2016-10-26 13:17:00 -04:00
});
it('should sort the environments alphabetically', () => {
const { environments } = gl.environmentsList.EnvironmentsStore.state;
expect(environments[0].name).toBe('production');
2016-11-07 16:11:58 -05:00
expect(environments[1].name).toBe('review');
expect(environments[1].children[0].name).toBe('test-environment');
expect(environments[1].children[1].name).toBe('test-environment-1');
expect(environments[2].name).toBe('review_app');
2016-10-26 13:17:00 -04:00
});
});
describe('toggleFolder', () => {
beforeEach(() => {
gl.environmentsList.EnvironmentsStore.storeEnvironments(environmentsList);
});
it('should toggle the open property for the given environment', () => {
gl.environmentsList.EnvironmentsStore.toggleFolder('review');
const { environments } = gl.environmentsList.EnvironmentsStore.state;
const environment = environments.filter(env => env['vue-isChildren'] === true && env.name === 'review');
expect(environment[0].isOpen).toBe(true);
});
});
2016-10-25 10:14:08 -04:00
});
})();