diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-02-07 09:08:49 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-02-07 09:08:49 +0000 |
commit | 456a7247f9e88fc2518b69a1a00e905c6db6d775 (patch) | |
tree | 6235f3838cbf078d46de056442d9562ee4abbd74 /spec/frontend/environments | |
parent | ddd268b03b6f35c68e5a89606dbfd516f72846fd (diff) | |
download | gitlab-ce-456a7247f9e88fc2518b69a1a00e905c6db6d775.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/frontend/environments')
-rw-r--r-- | spec/frontend/environments/environments_store_spec.js | 163 | ||||
-rw-r--r-- | spec/frontend/environments/mock_data.js | 59 |
2 files changed, 221 insertions, 1 deletions
diff --git a/spec/frontend/environments/environments_store_spec.js b/spec/frontend/environments/environments_store_spec.js new file mode 100644 index 00000000000..8abdbcbbe54 --- /dev/null +++ b/spec/frontend/environments/environments_store_spec.js @@ -0,0 +1,163 @@ +import Store from '~/environments/stores/environments_store'; +import { environmentsList, serverData } from './mock_data'; + +describe('Store', () => { + let store; + + beforeEach(() => { + store = new Store(); + }); + + 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); + + expect(store.state.environments.length).toEqual(serverData.length); + expect(store.state.environments[0]).toEqual(environmentsList[0]); + }); + + it('should store available count', () => { + store.storeAvailableCount(2); + + expect(store.state.availableCounter).toEqual(2); + }); + + it('should store stopped count', () => { + store.storeStoppedCount(2); + + expect(store.state.stoppedCounter).toEqual(2); + }); + + it('should add folder keys when environment is a folder', () => { + const environment = { + name: 'bar', + size: 3, + id: 2, + }; + + store.storeEnvironments([environment]); + + expect(store.state.environments[0].isFolder).toEqual(true); + expect(store.state.environments[0].folderName).toEqual('bar'); + }); + + 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); + }); + + it('should store latest.name when the environment is not a folder', () => { + store.storeEnvironments(serverData); + + expect(store.state.environments[0].name).toEqual(serverData[0].latest.name); + }); + + it('should store root level name when environment is a folder', () => { + store.storeEnvironments(serverData); + + expect(store.state.environments[1].folderName).toEqual(serverData[1].name); + }); + + describe('toggleFolder', () => { + it('should toggle folder', () => { + store.storeEnvironments(serverData); + + store.toggleFolder(store.state.environments[1]); + + expect(store.state.environments[1].isOpen).toEqual(true); + + store.toggleFolder(store.state.environments[1]); + + expect(store.state.environments[1].isOpen).toEqual(false); + }); + + it('should keep folder open when environments are updated', () => { + store.storeEnvironments(serverData); + + store.toggleFolder(store.state.environments[1]); + + expect(store.state.environments[1].isOpen).toEqual(true); + + store.storeEnvironments(serverData); + + expect(store.state.environments[1].isOpen).toEqual(true); + }); + }); + + describe('setfolderContent', () => { + it('should store folder content', () => { + store.storeEnvironments(serverData); + + store.setfolderContent(store.state.environments[1], serverData); + + expect(store.state.environments[1].children.length).toEqual(serverData.length); + expect(store.state.environments[1].children[0].isChildren).toEqual(true); + }); + + 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); + + expect(store.state.environments[1].children.length).toEqual(serverData.length); + }); + }); + + 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); + + expect(store.state.paginationInformation).toEqual(expectedResult); + }); + }); + + describe('getOpenFolders', () => { + it('should return open folder', () => { + store.storeEnvironments(serverData); + + store.toggleFolder(store.state.environments[1]); + + expect(store.getOpenFolders()[0]).toEqual(store.state.environments[1]); + }); + }); +}); diff --git a/spec/frontend/environments/mock_data.js b/spec/frontend/environments/mock_data.js index a2b581578d2..77c5dad0bbf 100644 --- a/spec/frontend/environments/mock_data.js +++ b/spec/frontend/environments/mock_data.js @@ -1,3 +1,31 @@ +const devProps = { + id: 7, + name: 'DEV', + state: 'available', + external_url: null, + environment_type: null, + last_deployment: null, + has_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', +}; + +const buildProps = { + id: 12, + name: 'build/update-README', + state: 'available', + external_url: null, + environment_type: 'build', + last_deployment: null, + has_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 environment = { name: 'production', size: 1, @@ -66,6 +94,18 @@ const environment = { auto_stop_at: null, }; +const environmentsList = [ + { + size: 1, + ...devProps, + }, + { + folderName: 'build', + size: 5, + ...buildProps, + }, +]; + const folder = { name: 'review', folderName: 'review', @@ -78,6 +118,23 @@ const folder = { }, }; +const serverData = [ + { + name: 'DEV', + size: 1, + latest: { + ...devProps, + }, + }, + { + name: 'build', + size: 5, + latest: { + ...buildProps, + }, + }, +]; + const tableData = { name: { title: 'Environment', @@ -108,4 +165,4 @@ const tableData = { }, }; -export { environment, folder, tableData }; +export { environment, environmentsList, folder, serverData, tableData }; |