2017-03-13 20:58:26 -04:00
|
|
|
import Store from '~/environments/stores/environments_store';
|
|
|
|
import { environmentsList, serverData } from './mock_data';
|
2016-11-21 18:19:51 -05:00
|
|
|
|
2017-03-28 06:56:24 -04:00
|
|
|
describe('Store', () => {
|
|
|
|
let store;
|
2017-02-09 06:35:53 -05:00
|
|
|
|
2017-03-28 06:56:24 -04:00
|
|
|
beforeEach(() => {
|
|
|
|
store = new Store();
|
|
|
|
});
|
2016-11-14 17:37:13 -05:00
|
|
|
|
2017-03-28 06:56:24 -04:00
|
|
|
it('should start with a blank state', () => {
|
|
|
|
expect(store.state.environments.length).toEqual(0);
|
|
|
|
expect(store.state.stoppedCounter).toEqual(0);
|
|
|
|
expect(store.state.availableCounter).toEqual(0);
|
|
|
|
expect(store.state.paginationInformation).toEqual({});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should store environments', () => {
|
|
|
|
store.storeEnvironments(serverData);
|
2018-10-09 14:03:09 -04:00
|
|
|
|
2017-03-28 06:56:24 -04:00
|
|
|
expect(store.state.environments.length).toEqual(serverData.length);
|
|
|
|
expect(store.state.environments[0]).toEqual(environmentsList[0]);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should store available count', () => {
|
|
|
|
store.storeAvailableCount(2);
|
2018-10-09 14:03:09 -04:00
|
|
|
|
2017-03-28 06:56:24 -04:00
|
|
|
expect(store.state.availableCounter).toEqual(2);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should store stopped count', () => {
|
|
|
|
store.storeStoppedCount(2);
|
2018-10-09 14:03:09 -04:00
|
|
|
|
2017-03-28 06:56:24 -04:00
|
|
|
expect(store.state.stoppedCounter).toEqual(2);
|
|
|
|
});
|
2016-10-26 04:17:32 -04:00
|
|
|
|
2019-03-13 07:55:56 -04:00
|
|
|
it('should add folder keys when environment is a folder', () => {
|
|
|
|
const environment = {
|
|
|
|
name: 'bar',
|
|
|
|
size: 3,
|
|
|
|
id: 2,
|
|
|
|
};
|
2017-03-29 12:29:57 -04:00
|
|
|
|
2019-03-13 07:55:56 -04:00
|
|
|
store.storeEnvironments([environment]);
|
2018-10-09 14:03:09 -04:00
|
|
|
|
2019-03-13 07:55:56 -04:00
|
|
|
expect(store.state.environments[0].isFolder).toEqual(true);
|
|
|
|
expect(store.state.environments[0].folderName).toEqual('bar');
|
|
|
|
});
|
2017-03-29 12:29:57 -04:00
|
|
|
|
2019-03-13 07:55:56 -04:00
|
|
|
it('should extract content of `latest` key when provided', () => {
|
|
|
|
const environment = {
|
|
|
|
name: 'bar',
|
|
|
|
size: 3,
|
|
|
|
id: 2,
|
|
|
|
latest: {
|
|
|
|
last_deployment: {},
|
|
|
|
isStoppable: true,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
store.storeEnvironments([environment]);
|
|
|
|
|
|
|
|
expect(store.state.environments[0].last_deployment).toEqual({});
|
|
|
|
expect(store.state.environments[0].isStoppable).toEqual(true);
|
|
|
|
});
|
2017-03-29 12:29:57 -04:00
|
|
|
|
2019-03-13 07:55:56 -04:00
|
|
|
it('should store latest.name when the environment is not a folder', () => {
|
|
|
|
store.storeEnvironments(serverData);
|
2018-10-09 14:03:09 -04:00
|
|
|
|
2019-03-13 07:55:56 -04:00
|
|
|
expect(store.state.environments[0].name).toEqual(serverData[0].latest.name);
|
|
|
|
});
|
2017-03-29 12:29:57 -04:00
|
|
|
|
2019-03-13 07:55:56 -04:00
|
|
|
it('should store root level name when environment is a folder', () => {
|
|
|
|
store.storeEnvironments(serverData);
|
2018-10-09 14:03:09 -04:00
|
|
|
|
2019-03-13 07:55:56 -04:00
|
|
|
expect(store.state.environments[1].folderName).toEqual(serverData[1].name);
|
2017-03-28 06:56:24 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
describe('toggleFolder', () => {
|
|
|
|
it('should toggle folder', () => {
|
2017-02-16 05:23:59 -05:00
|
|
|
store.storeEnvironments(serverData);
|
2017-02-09 06:35:53 -05:00
|
|
|
|
2017-03-28 06:56:24 -04:00
|
|
|
store.toggleFolder(store.state.environments[1]);
|
2018-10-09 14:03:09 -04:00
|
|
|
|
2017-03-28 06:56:24 -04:00
|
|
|
expect(store.state.environments[1].isOpen).toEqual(true);
|
2016-10-26 13:17:00 -04:00
|
|
|
|
2017-03-28 06:56:24 -04:00
|
|
|
store.toggleFolder(store.state.environments[1]);
|
2018-10-09 14:03:09 -04:00
|
|
|
|
2017-03-28 06:56:24 -04:00
|
|
|
expect(store.state.environments[1].isOpen).toEqual(false);
|
2017-02-09 10:10:16 -05:00
|
|
|
});
|
2017-07-05 12:08:53 -04:00
|
|
|
|
|
|
|
it('should keep folder open when environments are updated', () => {
|
|
|
|
store.storeEnvironments(serverData);
|
|
|
|
|
|
|
|
store.toggleFolder(store.state.environments[1]);
|
2018-10-09 14:03:09 -04:00
|
|
|
|
2017-07-05 12:08:53 -04:00
|
|
|
expect(store.state.environments[1].isOpen).toEqual(true);
|
|
|
|
|
|
|
|
store.storeEnvironments(serverData);
|
2018-10-09 14:03:09 -04:00
|
|
|
|
2017-07-05 12:08:53 -04:00
|
|
|
expect(store.state.environments[1].isOpen).toEqual(true);
|
|
|
|
});
|
2017-03-28 06:56:24 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
describe('setfolderContent', () => {
|
|
|
|
it('should store folder content', () => {
|
|
|
|
store.storeEnvironments(serverData);
|
|
|
|
|
|
|
|
store.setfolderContent(store.state.environments[1], serverData);
|
2017-02-09 10:10:16 -05:00
|
|
|
|
2017-03-28 06:56:24 -04:00
|
|
|
expect(store.state.environments[1].children.length).toEqual(serverData.length);
|
|
|
|
expect(store.state.environments[1].children[0].isChildren).toEqual(true);
|
2016-11-15 07:07:11 -05:00
|
|
|
});
|
2017-07-05 12:08:53 -04:00
|
|
|
|
|
|
|
it('should keep folder content when environments are updated', () => {
|
|
|
|
store.storeEnvironments(serverData);
|
|
|
|
|
|
|
|
store.setfolderContent(store.state.environments[1], serverData);
|
|
|
|
|
|
|
|
expect(store.state.environments[1].children.length).toEqual(serverData.length);
|
|
|
|
// poll
|
|
|
|
store.storeEnvironments(serverData);
|
2018-10-09 14:03:09 -04:00
|
|
|
|
2017-07-05 12:08:53 -04:00
|
|
|
expect(store.state.environments[1].children.length).toEqual(serverData.length);
|
|
|
|
});
|
2016-10-25 10:14:08 -04:00
|
|
|
});
|
2017-03-29 12:29:57 -04:00
|
|
|
|
|
|
|
describe('store pagination', () => {
|
|
|
|
it('should store normalized and integer pagination information', () => {
|
|
|
|
const pagination = {
|
|
|
|
'X-nExt-pAge': '2',
|
|
|
|
'X-page': '1',
|
|
|
|
'X-Per-Page': '1',
|
|
|
|
'X-Prev-Page': '2',
|
|
|
|
'X-TOTAL': '37',
|
|
|
|
'X-Total-Pages': '2',
|
|
|
|
};
|
|
|
|
|
|
|
|
const expectedResult = {
|
|
|
|
perPage: 1,
|
|
|
|
page: 1,
|
|
|
|
total: 37,
|
|
|
|
totalPages: 2,
|
|
|
|
nextPage: 2,
|
|
|
|
previousPage: 2,
|
|
|
|
};
|
|
|
|
|
|
|
|
store.setPagination(pagination);
|
2018-10-09 14:03:09 -04:00
|
|
|
|
2017-03-29 12:29:57 -04:00
|
|
|
expect(store.state.paginationInformation).toEqual(expectedResult);
|
|
|
|
});
|
|
|
|
});
|
2017-05-12 18:02:41 -04:00
|
|
|
|
|
|
|
describe('getOpenFolders', () => {
|
|
|
|
it('should return open folder', () => {
|
|
|
|
store.storeEnvironments(serverData);
|
|
|
|
|
|
|
|
store.toggleFolder(store.state.environments[1]);
|
2018-10-09 14:03:09 -04:00
|
|
|
|
2017-05-12 18:02:41 -04:00
|
|
|
expect(store.getOpenFolders()[0]).toEqual(store.state.environments[1]);
|
|
|
|
});
|
|
|
|
});
|
2017-03-28 06:56:24 -04:00
|
|
|
});
|