diff options
author | Filipa Lacerda <filipa@gitlab.com> | 2019-02-26 20:12:45 +0300 |
---|---|---|
committer | Filipa Lacerda <filipa@gitlab.com> | 2019-02-26 20:12:45 +0300 |
commit | 3a29b6af828da63ff7142183135d5ddbbd90d940 (patch) | |
tree | 99f858f11545a88253857b7a2c7c2ce2e9c51e89 /spec | |
parent | cb3324d30d193a17ff5536f119dc2bc49488f012 (diff) | |
parent | fa882a674a389fc41a155f5ba72e757a7ea02d7a (diff) |
Merge branch '46750-ci-empty-environment-is-created-even-when-a-job-isn-t-run-when-manual' into 'master'
Sort Environments by Last Updated
Closes #46750
See merge request gitlab-org/gitlab-ce!25260
Diffstat (limited to 'spec')
-rw-r--r-- | spec/javascripts/environments/environment_table_spec.js | 220 |
1 files changed, 220 insertions, 0 deletions
diff --git a/spec/javascripts/environments/environment_table_spec.js b/spec/javascripts/environments/environment_table_spec.js index 52895f35f3a..ecd28594873 100644 --- a/spec/javascripts/environments/environment_table_spec.js +++ b/spec/javascripts/environments/environment_table_spec.js @@ -31,4 +31,224 @@ describe('Environment table', () => { expect(vm.$el.getAttribute('class')).toContain('ci-table'); }); + + describe('sortEnvironments', () => { + it('should sort environments by last updated', () => { + const mockItems = [ + { + name: 'old', + size: 3, + isFolder: false, + last_deployment: { + created_at: new Date(2019, 0, 5).toISOString(), + }, + }, + { + name: 'new', + size: 3, + isFolder: false, + last_deployment: { + created_at: new Date(2019, 1, 5).toISOString(), + }, + }, + { + name: 'older', + size: 3, + isFolder: false, + last_deployment: { + created_at: new Date(2018, 0, 5).toISOString(), + }, + }, + { + name: 'an environment with no deployment', + }, + ]; + + vm = mountComponent(Component, { + environments: mockItems, + canReadEnvironment: true, + }); + + const [old, newer, older, noDeploy] = mockItems; + + expect(vm.sortEnvironments(mockItems)).toEqual([newer, old, older, noDeploy]); + }); + + it('should push environments with no deployments to the bottom', () => { + const mockItems = [ + { + name: 'production', + size: 1, + id: 2, + state: 'available', + external_url: 'https://google.com/production', + environment_type: null, + last_deployment: null, + has_stop_action: false, + environment_path: '/Commit451/lab-coat/environments/2', + stop_path: '/Commit451/lab-coat/environments/2/stop', + folder_path: '/Commit451/lab-coat/environments/folders/production', + created_at: '2019-01-17T16:26:10.064Z', + updated_at: '2019-01-17T16:27:37.717Z', + can_stop: true, + }, + { + name: 'review/225addcibuildstatus', + size: 2, + isFolder: true, + isLoadingFolderContent: false, + folderName: 'review', + isOpen: false, + children: [], + id: 12, + state: 'available', + external_url: 'https://google.com/review/225addcibuildstatus', + environment_type: 'review', + last_deployment: null, + has_stop_action: false, + environment_path: '/Commit451/lab-coat/environments/12', + stop_path: '/Commit451/lab-coat/environments/12/stop', + folder_path: '/Commit451/lab-coat/environments/folders/review', + created_at: '2019-01-17T16:27:37.877Z', + updated_at: '2019-01-17T16:27:37.883Z', + can_stop: true, + }, + { + name: 'staging', + size: 1, + id: 1, + state: 'available', + external_url: 'https://google.com/staging', + environment_type: null, + last_deployment: { + created_at: '2019-01-17T16:26:15.125Z', + scheduled_actions: [], + }, + }, + ]; + + vm = mountComponent(Component, { + environments: mockItems, + canReadEnvironment: true, + }); + + const [prod, review, staging] = mockItems; + + expect(vm.sortEnvironments(mockItems)).toEqual([review, staging, prod]); + }); + + it('should sort environments by folder first', () => { + const mockItems = [ + { + name: 'old', + size: 3, + isFolder: false, + last_deployment: { + created_at: new Date(2019, 0, 5).toISOString(), + }, + }, + { + name: 'new', + size: 3, + isFolder: false, + last_deployment: { + created_at: new Date(2019, 1, 5).toISOString(), + }, + }, + { + name: 'older', + size: 3, + isFolder: true, + children: [], + }, + ]; + + vm = mountComponent(Component, { + environments: mockItems, + canReadEnvironment: true, + }); + + const [old, newer, older] = mockItems; + + expect(vm.sortEnvironments(mockItems)).toEqual([older, newer, old]); + }); + + it('should break ties by name', () => { + const mockItems = [ + { + name: 'old', + isFolder: false, + }, + { + name: 'new', + isFolder: false, + }, + { + folderName: 'older', + isFolder: true, + }, + ]; + + vm = mountComponent(Component, { + environments: mockItems, + canReadEnvironment: true, + }); + + const [old, newer, older] = mockItems; + + expect(vm.sortEnvironments(mockItems)).toEqual([older, newer, old]); + }); + }); + + describe('sortedEnvironments', () => { + it('it should sort children as well', () => { + const mockItems = [ + { + name: 'production', + last_deployment: null, + }, + { + name: 'review/225addcibuildstatus', + isFolder: true, + folderName: 'review', + isOpen: true, + children: [ + { + name: 'review/225addcibuildstatus', + last_deployment: { + created_at: '2019-01-17T16:26:15.125Z', + }, + }, + { + name: 'review/master', + last_deployment: { + created_at: '2019-02-17T16:26:15.125Z', + }, + }, + ], + }, + { + name: 'staging', + last_deployment: { + created_at: '2019-01-17T16:26:15.125Z', + }, + }, + ]; + const [production, review, staging] = mockItems; + const [addcibuildstatus, master] = mockItems[1].children; + + vm = mountComponent(Component, { + environments: mockItems, + canReadEnvironment: true, + }); + + expect(vm.sortedEnvironments.map(env => env.name)).toEqual([ + review.name, + staging.name, + production.name, + ]); + + expect(vm.sortedEnvironments[0].children).toEqual([master, addcibuildstatus]); + }); + }); }); |