diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-01-21 03:08:59 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-01-21 03:08:59 +0300 |
commit | 367847e266036617e540e41b7fd3c7d03033800c (patch) | |
tree | a14547ad7556d48dcdeb977021f8cd89305ea026 /spec/frontend/environments | |
parent | 5d7e5a8902382caaffa616e1b496b684ba72d148 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/frontend/environments')
-rw-r--r-- | spec/frontend/environments/environments_app_spec.js | 30 | ||||
-rw-r--r-- | spec/frontend/environments/graphql/mock_data.js | 2 | ||||
-rw-r--r-- | spec/frontend/environments/stop_stale_environments_modal_spec.js | 60 |
3 files changed, 92 insertions, 0 deletions
diff --git a/spec/frontend/environments/environments_app_spec.js b/spec/frontend/environments/environments_app_spec.js index 65a9f2907d2..986ecca4e84 100644 --- a/spec/frontend/environments/environments_app_spec.js +++ b/spec/frontend/environments/environments_app_spec.js @@ -195,6 +195,36 @@ describe('~/environments/components/environments_app.vue', () => { expect(button.exists()).toBe(false); }); + it('should not show a button to clean up environments if the user has no permissions', async () => { + await createWrapperWithMocked({ + environmentsApp: { + ...resolvedEnvironmentsApp, + canStopStaleEnvironments: false, + }, + folder: resolvedFolder, + }); + + const button = wrapper.findByRole('button', { + name: s__('Environments|Clean up environments'), + }); + expect(button.exists()).toBe(false); + }); + + it('should show a button to clean up environments if the user has permissions', async () => { + await createWrapperWithMocked({ + environmentsApp: { + ...resolvedEnvironmentsApp, + canStopStaleEnvironments: true, + }, + folder: resolvedFolder, + }); + + const button = wrapper.findByRole('button', { + name: s__('Environments|Clean up environments'), + }); + expect(button.exists()).toBe(true); + }); + describe('tabs', () => { it('should show tabs for available and stopped environmets', async () => { await createWrapperWithMocked({ diff --git a/spec/frontend/environments/graphql/mock_data.js b/spec/frontend/environments/graphql/mock_data.js index 355b77b55c3..0b1c8dc6fb8 100644 --- a/spec/frontend/environments/graphql/mock_data.js +++ b/spec/frontend/environments/graphql/mock_data.js @@ -265,6 +265,7 @@ export const environmentsApp = { review_snippet: '{"deploy_review"=>{"stage"=>"deploy", "script"=>["echo \\"Deploy a review app\\""], "environment"=>{"name"=>"review/$CI_COMMIT_REF_NAME", "url"=>"https://$CI_ENVIRONMENT_SLUG.example.com"}, "only"=>["branches"]}}', }, + can_stop_stale_environments: true, available_count: 4, stopped_count: 0, }; @@ -474,6 +475,7 @@ export const resolvedEnvironmentsApp = { '{"deploy_review"=>{"stage"=>"deploy", "script"=>["echo \\"Deploy a review app\\""], "environment"=>{"name"=>"review/$CI_COMMIT_REF_NAME", "url"=>"https://$CI_ENVIRONMENT_SLUG.example.com"}, "only"=>["branches"]}}', __typename: 'ReviewApp', }, + canStopStaleEnvironments: true, stoppedCount: 0, __typename: 'LocalEnvironmentApp', }; diff --git a/spec/frontend/environments/stop_stale_environments_modal_spec.js b/spec/frontend/environments/stop_stale_environments_modal_spec.js new file mode 100644 index 00000000000..a2ab4f707b5 --- /dev/null +++ b/spec/frontend/environments/stop_stale_environments_modal_spec.js @@ -0,0 +1,60 @@ +import MockAdapter from 'axios-mock-adapter'; +import { GlModal } from '@gitlab/ui'; +import { shallowMount } from '@vue/test-utils'; +import StopStaleEnvironmentsModal from '~/environments/components/stop_stale_environments_modal.vue'; +import axios from '~/lib/utils/axios_utils'; +import { getDateInPast } from '~/lib/utils/datetime_utility'; +import { STOP_STALE_ENVIRONMENTS_PATH } from '~/api/environments_api'; +import { HTTP_STATUS_OK } from '~/lib/utils/http_status'; + +const DEFAULT_OPTS = { + provide: { projectId: 1 }, +}; + +const ONE_WEEK_AGO = getDateInPast(new Date(), 7); +const TEN_YEARS_AGO = getDateInPast(new Date(), 3650); + +describe('~/environments/components/stop_stale_environments_modal.vue', () => { + let wrapper; + let mock; + let before; + let originalGon; + + const createWrapper = (opts = {}) => + shallowMount(StopStaleEnvironmentsModal, { + ...DEFAULT_OPTS, + ...opts, + propsData: { modalId: 'stop-stale-environments-modal', visible: true }, + }); + + beforeEach(() => { + originalGon = window.gon; + window.gon = { api_version: 'v4' }; + + mock = new MockAdapter(axios); + jest.spyOn(axios, 'post'); + wrapper = createWrapper(); + before = wrapper.find("[data-testid='stop-environments-before']"); + }); + + afterEach(() => { + mock.restore(); + wrapper.destroy(); + jest.resetAllMocks(); + window.gon = originalGon; + }); + + it('sets the correct min and max dates', async () => { + expect(before.props().minDate.toISOString()).toBe(TEN_YEARS_AGO.toISOString()); + expect(before.props().maxDate.toISOString()).toBe(ONE_WEEK_AGO.toISOString()); + }); + + it('requests cleanup when submit is clicked', async () => { + mock.onPost().replyOnce(HTTP_STATUS_OK); + wrapper.findComponent(GlModal).vm.$emit('primary'); + const url = STOP_STALE_ENVIRONMENTS_PATH.replace(':id', 1).replace(':version', 'v4'); + expect(axios.post).toHaveBeenCalledWith(url, null, { + params: { before: ONE_WEEK_AGO.toISOString() }, + }); + }); +}); |