diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-11-18 13:16:36 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-11-18 13:16:36 +0000 |
commit | 311b0269b4eb9839fa63f80c8d7a58f32b8138a0 (patch) | |
tree | 07e7870bca8aed6d61fdcc810731c50d2c40af47 /spec/frontend/environments | |
parent | 27909cef6c4170ed9205afa7426b8d3de47cbb0c (diff) | |
download | gitlab-ce-311b0269b4eb9839fa63f80c8d7a58f32b8138a0.tar.gz |
Add latest changes from gitlab-org/gitlab@14-5-stable-eev14.5.0-rc42
Diffstat (limited to 'spec/frontend/environments')
4 files changed, 745 insertions, 0 deletions
diff --git a/spec/frontend/environments/graphql/mock_data.js b/spec/frontend/environments/graphql/mock_data.js new file mode 100644 index 00000000000..e56b6448b7d --- /dev/null +++ b/spec/frontend/environments/graphql/mock_data.js @@ -0,0 +1,530 @@ +export const environmentsApp = { + environments: [ + { + name: 'review', + size: 2, + latest: { + id: 42, + global_id: 'gid://gitlab/Environment/42', + name: 'review/goodbye', + state: 'available', + external_url: 'https://example.org', + environment_type: 'review', + name_without_type: 'goodbye', + last_deployment: null, + has_stop_action: false, + rollout_status: null, + environment_path: '/h5bp/html5-boilerplate/-/environments/42', + stop_path: '/h5bp/html5-boilerplate/-/environments/42/stop', + cancel_auto_stop_path: '/h5bp/html5-boilerplate/-/environments/42/cancel_auto_stop', + delete_path: '/api/v4/projects/8/environments/42', + folder_path: '/h5bp/html5-boilerplate/-/environments/folders/review', + created_at: '2021-10-04T19:27:20.639Z', + updated_at: '2021-10-04T19:27:20.639Z', + can_stop: true, + logs_path: '/h5bp/html5-boilerplate/-/logs?environment_name=review%2Fgoodbye', + logs_api_path: '/h5bp/html5-boilerplate/-/logs/k8s.json?environment_name=review%2Fgoodbye', + enable_advanced_logs_querying: false, + can_delete: false, + has_opened_alert: false, + }, + }, + { + name: 'production', + size: 1, + latest: { + id: 8, + global_id: 'gid://gitlab/Environment/8', + name: 'production', + state: 'available', + external_url: 'https://example.org', + environment_type: null, + name_without_type: 'production', + last_deployment: { + id: 80, + iid: 24, + sha: '4ca0310329e8f251b892d7be205eec8b7dd220e5', + ref: { + name: 'root-master-patch-18104', + ref_path: '/h5bp/html5-boilerplate/-/tree/root-master-patch-18104', + }, + status: 'success', + created_at: '2021-10-08T19:53:54.543Z', + deployed_at: '2021-10-08T20:02:36.763Z', + tag: false, + 'last?': true, + user: { + id: 1, + name: 'Administrator', + username: 'root', + state: 'active', + avatar_url: + 'https://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80&d=identicon', + web_url: 'http://gdk.test:3000/root', + show_status: false, + path: '/root', + }, + deployable: { + id: 911, + name: 'deploy-job', + started: '2021-10-08T19:54:00.658Z', + complete: true, + archived: false, + build_path: '/h5bp/html5-boilerplate/-/jobs/911', + retry_path: '/h5bp/html5-boilerplate/-/jobs/911/retry', + play_path: '/h5bp/html5-boilerplate/-/jobs/911/play', + playable: true, + scheduled: false, + created_at: '2021-10-08T19:53:54.482Z', + updated_at: '2021-10-08T20:02:36.730Z', + status: { + icon: 'status_success', + text: 'passed', + label: 'manual play action', + group: 'success', + tooltip: 'passed', + has_details: true, + details_path: '/h5bp/html5-boilerplate/-/jobs/911', + illustration: { + image: + '/assets/illustrations/manual_action-c55aee2c5f9ebe9f72751480af8bb307be1a6f35552f344cc6d1bf979d3422f6.svg', + size: 'svg-394', + title: 'This job requires a manual action', + content: + 'This job requires manual intervention to start. Before starting this job, you can add variables below for last-minute configuration changes.', + }, + favicon: + '/assets/ci_favicons/favicon_status_success-8451333011eee8ce9f2ab25dc487fe24a8758c694827a582f17f42b0a90446a2.png', + action: { + icon: 'play', + title: 'Play', + path: '/h5bp/html5-boilerplate/-/jobs/911/play', + method: 'post', + button_title: 'Trigger this manual action', + }, + }, + }, + commit: { + id: '4ca0310329e8f251b892d7be205eec8b7dd220e5', + short_id: '4ca03103', + created_at: '2021-10-08T19:27:01.000+00:00', + parent_ids: ['b385360b15bd61391a0efbd101788d4a80387270'], + title: 'Update .gitlab-ci.yml', + message: 'Update .gitlab-ci.yml', + author_name: 'Administrator', + author_email: 'admin@example.com', + authored_date: '2021-10-08T19:27:01.000+00:00', + committer_name: 'Administrator', + committer_email: 'admin@example.com', + committed_date: '2021-10-08T19:27:01.000+00:00', + trailers: {}, + web_url: + 'http://gdk.test:3000/h5bp/html5-boilerplate/-/commit/4ca0310329e8f251b892d7be205eec8b7dd220e5', + author: { + id: 1, + name: 'Administrator', + username: 'root', + state: 'active', + avatar_url: + 'https://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80&d=identicon', + web_url: 'http://gdk.test:3000/root', + show_status: false, + path: '/root', + }, + author_gravatar_url: + 'https://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80&d=identicon', + commit_url: + 'http://gdk.test:3000/h5bp/html5-boilerplate/-/commit/4ca0310329e8f251b892d7be205eec8b7dd220e5', + commit_path: + '/h5bp/html5-boilerplate/-/commit/4ca0310329e8f251b892d7be205eec8b7dd220e5', + }, + manual_actions: [], + scheduled_actions: [], + playable_build: { + retry_path: '/h5bp/html5-boilerplate/-/jobs/911/retry', + play_path: '/h5bp/html5-boilerplate/-/jobs/911/play', + }, + cluster: null, + }, + has_stop_action: false, + rollout_status: null, + environment_path: '/h5bp/html5-boilerplate/-/environments/8', + stop_path: '/h5bp/html5-boilerplate/-/environments/8/stop', + cancel_auto_stop_path: '/h5bp/html5-boilerplate/-/environments/8/cancel_auto_stop', + delete_path: '/api/v4/projects/8/environments/8', + folder_path: '/h5bp/html5-boilerplate/-/environments/folders/production', + created_at: '2021-06-17T15:09:38.599Z', + updated_at: '2021-10-08T19:50:44.445Z', + can_stop: true, + logs_path: '/h5bp/html5-boilerplate/-/logs?environment_name=production', + logs_api_path: '/h5bp/html5-boilerplate/-/logs/k8s.json?environment_name=production', + enable_advanced_logs_querying: false, + can_delete: false, + has_opened_alert: false, + }, + }, + { + name: 'staging', + size: 1, + latest: { + id: 7, + global_id: 'gid://gitlab/Environment/7', + name: 'staging', + state: 'available', + external_url: null, + environment_type: null, + name_without_type: 'staging', + last_deployment: null, + has_stop_action: false, + rollout_status: null, + environment_path: '/h5bp/html5-boilerplate/-/environments/7', + stop_path: '/h5bp/html5-boilerplate/-/environments/7/stop', + cancel_auto_stop_path: '/h5bp/html5-boilerplate/-/environments/7/cancel_auto_stop', + delete_path: '/api/v4/projects/8/environments/7', + folder_path: '/h5bp/html5-boilerplate/-/environments/folders/staging', + created_at: '2021-06-17T15:09:38.570Z', + updated_at: '2021-06-17T15:09:38.570Z', + can_stop: true, + logs_path: '/h5bp/html5-boilerplate/-/logs?environment_name=staging', + logs_api_path: '/h5bp/html5-boilerplate/-/logs/k8s.json?environment_name=staging', + enable_advanced_logs_querying: false, + can_delete: false, + has_opened_alert: false, + }, + }, + ], + review_app: { + can_setup_review_app: true, + all_clusters_empty: true, + 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"]}}', + }, + available_count: 4, + stopped_count: 0, +}; + +export const resolvedEnvironmentsApp = { + availableCount: 4, + environments: [ + { + name: 'review', + size: 2, + latest: { + id: 42, + globalId: 'gid://gitlab/Environment/42', + name: 'review/goodbye', + state: 'available', + externalUrl: 'https://example.org', + environmentType: 'review', + nameWithoutType: 'goodbye', + lastDeployment: null, + hasStopAction: false, + rolloutStatus: null, + environmentPath: '/h5bp/html5-boilerplate/-/environments/42', + stopPath: '/h5bp/html5-boilerplate/-/environments/42/stop', + cancelAutoStopPath: '/h5bp/html5-boilerplate/-/environments/42/cancel_auto_stop', + deletePath: '/api/v4/projects/8/environments/42', + folderPath: '/h5bp/html5-boilerplate/-/environments/folders/review', + createdAt: '2021-10-04T19:27:20.639Z', + updatedAt: '2021-10-04T19:27:20.639Z', + canStop: true, + logsPath: '/h5bp/html5-boilerplate/-/logs?environment_name=review%2Fgoodbye', + logsApiPath: '/h5bp/html5-boilerplate/-/logs/k8s.json?environment_name=review%2Fgoodbye', + enableAdvancedLogsQuerying: false, + canDelete: false, + hasOpenedAlert: false, + }, + __typename: 'NestedLocalEnvironment', + }, + { + name: 'production', + size: 1, + latest: { + id: 8, + globalId: 'gid://gitlab/Environment/8', + name: 'production', + state: 'available', + externalUrl: 'https://example.org', + environmentType: null, + nameWithoutType: 'production', + lastDeployment: { + id: 80, + iid: 24, + sha: '4ca0310329e8f251b892d7be205eec8b7dd220e5', + ref: { + name: 'root-master-patch-18104', + refPath: '/h5bp/html5-boilerplate/-/tree/root-master-patch-18104', + }, + status: 'success', + createdAt: '2021-10-08T19:53:54.543Z', + deployedAt: '2021-10-08T20:02:36.763Z', + tag: false, + 'last?': true, + user: { + id: 1, + name: 'Administrator', + username: 'root', + state: 'active', + avatarUrl: + 'https://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80&d=identicon', + webUrl: 'http://gdk.test:3000/root', + showStatus: false, + path: '/root', + }, + deployable: { + id: 911, + name: 'deploy-job', + started: '2021-10-08T19:54:00.658Z', + complete: true, + archived: false, + buildPath: '/h5bp/html5-boilerplate/-/jobs/911', + retryPath: '/h5bp/html5-boilerplate/-/jobs/911/retry', + playPath: '/h5bp/html5-boilerplate/-/jobs/911/play', + playable: true, + scheduled: false, + createdAt: '2021-10-08T19:53:54.482Z', + updatedAt: '2021-10-08T20:02:36.730Z', + status: { + icon: 'status_success', + text: 'passed', + label: 'manual play action', + group: 'success', + tooltip: 'passed', + hasDetails: true, + detailsPath: '/h5bp/html5-boilerplate/-/jobs/911', + illustration: { + image: + '/assets/illustrations/manual_action-c55aee2c5f9ebe9f72751480af8bb307be1a6f35552f344cc6d1bf979d3422f6.svg', + size: 'svg-394', + title: 'This job requires a manual action', + content: + 'This job requires manual intervention to start. Before starting this job, you can add variables below for last-minute configuration changes.', + }, + favicon: + '/assets/ci_favicons/favicon_status_success-8451333011eee8ce9f2ab25dc487fe24a8758c694827a582f17f42b0a90446a2.png', + action: { + icon: 'play', + title: 'Play', + path: '/h5bp/html5-boilerplate/-/jobs/911/play', + method: 'post', + buttonTitle: 'Trigger this manual action', + }, + }, + }, + commit: { + id: '4ca0310329e8f251b892d7be205eec8b7dd220e5', + shortId: '4ca03103', + createdAt: '2021-10-08T19:27:01.000+00:00', + parentIds: ['b385360b15bd61391a0efbd101788d4a80387270'], + title: 'Update .gitlab-ci.yml', + message: 'Update .gitlab-ci.yml', + authorName: 'Administrator', + authorEmail: 'admin@example.com', + authoredDate: '2021-10-08T19:27:01.000+00:00', + committerName: 'Administrator', + committerEmail: 'admin@example.com', + committedDate: '2021-10-08T19:27:01.000+00:00', + trailers: {}, + webUrl: + 'http://gdk.test:3000/h5bp/html5-boilerplate/-/commit/4ca0310329e8f251b892d7be205eec8b7dd220e5', + author: { + id: 1, + name: 'Administrator', + username: 'root', + state: 'active', + avatarUrl: + 'https://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80&d=identicon', + webUrl: 'http://gdk.test:3000/root', + showStatus: false, + path: '/root', + }, + authorGravatarUrl: + 'https://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80&d=identicon', + commitUrl: + 'http://gdk.test:3000/h5bp/html5-boilerplate/-/commit/4ca0310329e8f251b892d7be205eec8b7dd220e5', + commitPath: '/h5bp/html5-boilerplate/-/commit/4ca0310329e8f251b892d7be205eec8b7dd220e5', + }, + manualActions: [], + scheduledActions: [], + playableBuild: { + retryPath: '/h5bp/html5-boilerplate/-/jobs/911/retry', + playPath: '/h5bp/html5-boilerplate/-/jobs/911/play', + }, + cluster: null, + }, + hasStopAction: false, + rolloutStatus: null, + environmentPath: '/h5bp/html5-boilerplate/-/environments/8', + stopPath: '/h5bp/html5-boilerplate/-/environments/8/stop', + cancelAutoStopPath: '/h5bp/html5-boilerplate/-/environments/8/cancel_auto_stop', + deletePath: '/api/v4/projects/8/environments/8', + folderPath: '/h5bp/html5-boilerplate/-/environments/folders/production', + createdAt: '2021-06-17T15:09:38.599Z', + updatedAt: '2021-10-08T19:50:44.445Z', + canStop: true, + logsPath: '/h5bp/html5-boilerplate/-/logs?environment_name=production', + logsApiPath: '/h5bp/html5-boilerplate/-/logs/k8s.json?environment_name=production', + enableAdvancedLogsQuerying: false, + canDelete: false, + hasOpenedAlert: false, + }, + __typename: 'NestedLocalEnvironment', + }, + { + name: 'staging', + size: 1, + latest: { + id: 7, + globalId: 'gid://gitlab/Environment/7', + name: 'staging', + state: 'available', + externalUrl: null, + environmentType: null, + nameWithoutType: 'staging', + lastDeployment: null, + hasStopAction: false, + rolloutStatus: null, + environmentPath: '/h5bp/html5-boilerplate/-/environments/7', + stopPath: '/h5bp/html5-boilerplate/-/environments/7/stop', + cancelAutoStopPath: '/h5bp/html5-boilerplate/-/environments/7/cancel_auto_stop', + deletePath: '/api/v4/projects/8/environments/7', + folderPath: '/h5bp/html5-boilerplate/-/environments/folders/staging', + createdAt: '2021-06-17T15:09:38.570Z', + updatedAt: '2021-06-17T15:09:38.570Z', + canStop: true, + logsPath: '/h5bp/html5-boilerplate/-/logs?environment_name=staging', + logsApiPath: '/h5bp/html5-boilerplate/-/logs/k8s.json?environment_name=staging', + enableAdvancedLogsQuerying: false, + canDelete: false, + hasOpenedAlert: false, + }, + __typename: 'NestedLocalEnvironment', + }, + ], + reviewApp: { + canSetupReviewApp: true, + allClustersEmpty: true, + reviewSnippet: + '{"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', + }, + stoppedCount: 0, + __typename: 'LocalEnvironmentApp', +}; + +export const folder = { + environments: [ + { + id: 42, + global_id: 'gid://gitlab/Environment/42', + name: 'review/goodbye', + state: 'available', + external_url: 'https://example.org', + environment_type: 'review', + name_without_type: 'goodbye', + last_deployment: null, + has_stop_action: false, + rollout_status: null, + environment_path: '/h5bp/html5-boilerplate/-/environments/42', + stop_path: '/h5bp/html5-boilerplate/-/environments/42/stop', + cancel_auto_stop_path: '/h5bp/html5-boilerplate/-/environments/42/cancel_auto_stop', + delete_path: '/api/v4/projects/8/environments/42', + folder_path: '/h5bp/html5-boilerplate/-/environments/folders/review', + created_at: '2021-10-04T19:27:20.639Z', + updated_at: '2021-10-04T19:27:20.639Z', + can_stop: true, + logs_path: '/h5bp/html5-boilerplate/-/logs?environment_name=review%2Fgoodbye', + logs_api_path: '/h5bp/html5-boilerplate/-/logs/k8s.json?environment_name=review%2Fgoodbye', + enable_advanced_logs_querying: false, + can_delete: false, + has_opened_alert: false, + }, + { + id: 41, + global_id: 'gid://gitlab/Environment/41', + name: 'review/hello', + state: 'available', + external_url: 'https://example.org', + environment_type: 'review', + name_without_type: 'hello', + last_deployment: null, + has_stop_action: false, + rollout_status: null, + environment_path: '/h5bp/html5-boilerplate/-/environments/41', + stop_path: '/h5bp/html5-boilerplate/-/environments/41/stop', + cancel_auto_stop_path: '/h5bp/html5-boilerplate/-/environments/41/cancel_auto_stop', + delete_path: '/api/v4/projects/8/environments/41', + folder_path: '/h5bp/html5-boilerplate/-/environments/folders/review', + created_at: '2021-10-04T19:27:00.527Z', + updated_at: '2021-10-04T19:27:00.527Z', + can_stop: true, + logs_path: '/h5bp/html5-boilerplate/-/logs?environment_name=review%2Fhello', + logs_api_path: '/h5bp/html5-boilerplate/-/logs/k8s.json?environment_name=review%2Fhello', + enable_advanced_logs_querying: false, + can_delete: false, + has_opened_alert: false, + }, + ], + available_count: 2, + stopped_count: 0, +}; + +export const resolvedFolder = { + availableCount: 2, + environments: [ + { + id: 42, + globalId: 'gid://gitlab/Environment/42', + name: 'review/goodbye', + state: 'available', + externalUrl: 'https://example.org', + environmentType: 'review', + nameWithoutType: 'goodbye', + lastDeployment: null, + hasStopAction: false, + rolloutStatus: null, + environmentPath: '/h5bp/html5-boilerplate/-/environments/42', + stopPath: '/h5bp/html5-boilerplate/-/environments/42/stop', + cancelAutoStopPath: '/h5bp/html5-boilerplate/-/environments/42/cancel_auto_stop', + deletePath: '/api/v4/projects/8/environments/42', + folderPath: '/h5bp/html5-boilerplate/-/environments/folders/review', + createdAt: '2021-10-04T19:27:20.639Z', + updatedAt: '2021-10-04T19:27:20.639Z', + canStop: true, + logsPath: '/h5bp/html5-boilerplate/-/logs?environment_name=review%2Fgoodbye', + logsApiPath: '/h5bp/html5-boilerplate/-/logs/k8s.json?environment_name=review%2Fgoodbye', + enableAdvancedLogsQuerying: false, + canDelete: false, + hasOpenedAlert: false, + __typename: 'LocalEnvironment', + }, + { + id: 41, + globalId: 'gid://gitlab/Environment/41', + name: 'review/hello', + state: 'available', + externalUrl: 'https://example.org', + environmentType: 'review', + nameWithoutType: 'hello', + lastDeployment: null, + hasStopAction: false, + rolloutStatus: null, + environmentPath: '/h5bp/html5-boilerplate/-/environments/41', + stopPath: '/h5bp/html5-boilerplate/-/environments/41/stop', + cancelAutoStopPath: '/h5bp/html5-boilerplate/-/environments/41/cancel_auto_stop', + deletePath: '/api/v4/projects/8/environments/41', + folderPath: '/h5bp/html5-boilerplate/-/environments/folders/review', + createdAt: '2021-10-04T19:27:00.527Z', + updatedAt: '2021-10-04T19:27:00.527Z', + canStop: true, + logsPath: '/h5bp/html5-boilerplate/-/logs?environment_name=review%2Fhello', + logsApiPath: '/h5bp/html5-boilerplate/-/logs/k8s.json?environment_name=review%2Fhello', + enableAdvancedLogsQuerying: false, + canDelete: false, + hasOpenedAlert: false, + __typename: 'LocalEnvironment', + }, + ], + stoppedCount: 0, + __typename: 'LocalEnvironmentFolder', +}; diff --git a/spec/frontend/environments/graphql/resolvers_spec.js b/spec/frontend/environments/graphql/resolvers_spec.js new file mode 100644 index 00000000000..4d2a0818996 --- /dev/null +++ b/spec/frontend/environments/graphql/resolvers_spec.js @@ -0,0 +1,91 @@ +import MockAdapter from 'axios-mock-adapter'; +import axios from '~/lib/utils/axios_utils'; +import { resolvers } from '~/environments/graphql/resolvers'; +import { TEST_HOST } from 'helpers/test_constants'; +import { environmentsApp, resolvedEnvironmentsApp, folder, resolvedFolder } from './mock_data'; + +const ENDPOINT = `${TEST_HOST}/environments`; + +describe('~/frontend/environments/graphql/resolvers', () => { + let mockResolvers; + let mock; + + beforeEach(() => { + mockResolvers = resolvers(ENDPOINT); + mock = new MockAdapter(axios); + }); + + afterEach(() => { + mock.reset(); + }); + + describe('environmentApp', () => { + it('should fetch environments and map them to frontend data', async () => { + mock.onGet(ENDPOINT, { params: { nested: true } }).reply(200, environmentsApp); + + const app = await mockResolvers.Query.environmentApp(); + expect(app).toEqual(resolvedEnvironmentsApp); + }); + }); + describe('folder', () => { + it('should fetch the folder url passed to it', async () => { + mock.onGet(ENDPOINT, { params: { per_page: 3 } }).reply(200, folder); + + const environmentFolder = await mockResolvers.Query.folder(null, { + environment: { folderPath: ENDPOINT }, + }); + + expect(environmentFolder).toEqual(resolvedFolder); + }); + }); + describe('stopEnvironment', () => { + it('should post to the stop environment path', async () => { + mock.onPost(ENDPOINT).reply(200); + + await mockResolvers.Mutations.stopEnvironment(null, { environment: { stopPath: ENDPOINT } }); + + expect(mock.history.post).toContainEqual( + expect.objectContaining({ url: ENDPOINT, method: 'post' }), + ); + }); + }); + describe('rollbackEnvironment', () => { + it('should post to the retry environment path', async () => { + mock.onPost(ENDPOINT).reply(200); + + await mockResolvers.Mutations.rollbackEnvironment(null, { + environment: { retryUrl: ENDPOINT }, + }); + + expect(mock.history.post).toContainEqual( + expect.objectContaining({ url: ENDPOINT, method: 'post' }), + ); + }); + }); + describe('deleteEnvironment', () => { + it('should DELETE to the delete environment path', async () => { + mock.onDelete(ENDPOINT).reply(200); + + await mockResolvers.Mutations.deleteEnvironment(null, { + environment: { deletePath: ENDPOINT }, + }); + + expect(mock.history.delete).toContainEqual( + expect.objectContaining({ url: ENDPOINT, method: 'delete' }), + ); + }); + }); + describe('cancelAutoStop', () => { + it('should post to the auto stop path', async () => { + mock.onPost(ENDPOINT).reply(200); + + await mockResolvers.Mutations.cancelAutoStop(null, { + environment: { autoStopPath: ENDPOINT }, + }); + + expect(mock.history.post).toContainEqual( + expect.objectContaining({ url: ENDPOINT, method: 'post' }), + ); + }); + }); +}); diff --git a/spec/frontend/environments/new_environment_folder_spec.js b/spec/frontend/environments/new_environment_folder_spec.js new file mode 100644 index 00000000000..5696e187a86 --- /dev/null +++ b/spec/frontend/environments/new_environment_folder_spec.js @@ -0,0 +1,74 @@ +import VueApollo from 'vue-apollo'; +import Vue from 'vue'; +import { GlCollapse, GlIcon } from '@gitlab/ui'; +import createMockApollo from 'helpers/mock_apollo_helper'; +import { mountExtended } from 'helpers/vue_test_utils_helper'; +import EnvironmentsFolder from '~/environments/components/new_environment_folder.vue'; +import { s__ } from '~/locale'; +import { resolvedEnvironmentsApp, resolvedFolder } from './graphql/mock_data'; + +Vue.use(VueApollo); + +describe('~/environments/components/new_environments_folder.vue', () => { + let wrapper; + let environmentFolderMock; + let nestedEnvironment; + let folderName; + + const findLink = () => wrapper.findByRole('link', { name: s__('Environments|Show all') }); + + const createApolloProvider = () => { + const mockResolvers = { Query: { folder: environmentFolderMock } }; + + return createMockApollo([], mockResolvers); + }; + + const createWrapper = (propsData, apolloProvider) => + mountExtended(EnvironmentsFolder, { apolloProvider, propsData }); + + beforeEach(() => { + environmentFolderMock = jest.fn(); + [nestedEnvironment] = resolvedEnvironmentsApp.environments; + environmentFolderMock.mockReturnValue(resolvedFolder); + wrapper = createWrapper({ nestedEnvironment }, createApolloProvider()); + folderName = wrapper.findByText(nestedEnvironment.name); + }); + + afterEach(() => { + wrapper?.destroy(); + }); + + it('displays the name of the folder', () => { + expect(folderName.text()).toBe(nestedEnvironment.name); + }); + + describe('collapse', () => { + let icons; + let collapse; + + beforeEach(() => { + collapse = wrapper.findComponent(GlCollapse); + icons = wrapper.findAllComponents(GlIcon); + }); + + it('is collapsed by default', () => { + const link = findLink(); + + expect(collapse.attributes('visible')).toBeUndefined(); + expect(icons.wrappers.map((i) => i.props('name'))).toEqual(['angle-right', 'folder-o']); + expect(folderName.classes('gl-font-weight-bold')).toBe(false); + expect(link.exists()).toBe(false); + }); + + it('opens on click', async () => { + await folderName.trigger('click'); + + const link = findLink(); + + expect(collapse.attributes('visible')).toBe('true'); + expect(icons.wrappers.map((i) => i.props('name'))).toEqual(['angle-down', 'folder-open']); + expect(folderName.classes('gl-font-weight-bold')).toBe(true); + expect(link.attributes('href')).toBe(nestedEnvironment.latest.folderPath); + }); + }); +}); diff --git a/spec/frontend/environments/new_environments_app_spec.js b/spec/frontend/environments/new_environments_app_spec.js new file mode 100644 index 00000000000..0ad8e8f442c --- /dev/null +++ b/spec/frontend/environments/new_environments_app_spec.js @@ -0,0 +1,50 @@ +import Vue from 'vue'; +import VueApollo from 'vue-apollo'; +import { mount } from '@vue/test-utils'; +import createMockApollo from 'helpers/mock_apollo_helper'; +import waitForPromises from 'helpers/wait_for_promises'; +import EnvironmentsApp from '~/environments/components/new_environments_app.vue'; +import EnvironmentsFolder from '~/environments/components/new_environment_folder.vue'; +import { resolvedEnvironmentsApp, resolvedFolder } from './graphql/mock_data'; + +Vue.use(VueApollo); + +describe('~/environments/components/new_environments_app.vue', () => { + let wrapper; + let environmentAppMock; + let environmentFolderMock; + + const createApolloProvider = () => { + const mockResolvers = { + Query: { environmentApp: environmentAppMock, folder: environmentFolderMock }, + }; + + return createMockApollo([], mockResolvers); + }; + + const createWrapper = (apolloProvider) => mount(EnvironmentsApp, { apolloProvider }); + + beforeEach(() => { + environmentAppMock = jest.fn(); + environmentFolderMock = jest.fn(); + }); + + afterEach(() => { + wrapper?.destroy(); + }); + + it('should show all the folders that are fetched', async () => { + environmentAppMock.mockReturnValue(resolvedEnvironmentsApp); + environmentFolderMock.mockReturnValue(resolvedFolder); + const apolloProvider = createApolloProvider(); + wrapper = createWrapper(apolloProvider); + + await waitForPromises(); + await Vue.nextTick(); + + const text = wrapper.findAllComponents(EnvironmentsFolder).wrappers.map((w) => w.text()); + + expect(text).toContainEqual(expect.stringMatching('review')); + expect(text).not.toContainEqual(expect.stringMatching('production')); + }); +}); |