diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-11-09 15:10:06 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-11-09 15:10:06 +0300 |
commit | 963e09aecfb3cdd57babdd9b37c15e34601fdb42 (patch) | |
tree | 2c3067224f4ed5197d9bfc34a1ff63e7003e05dc /spec/frontend | |
parent | 529d3153bc5823c8326f04649f8362f1a32d8c61 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/frontend')
5 files changed, 40 insertions, 171 deletions
diff --git a/spec/frontend/environments/environments_app_spec.js b/spec/frontend/environments/environments_app_spec.js index 8c02a07994b..5ac949e77b6 100644 --- a/spec/frontend/environments/environments_app_spec.js +++ b/spec/frontend/environments/environments_app_spec.js @@ -71,7 +71,7 @@ describe('~/environments/components/environments_app.vue', () => { previousPage: 1, __typename: 'LocalPageInfo', }, - location = '?scope=available&page=2&search=prod', + location = '?scope=active&page=2&search=prod', }) => { setWindowLocation(location); environmentAppMock.mockReturnValue(environmentsApp); @@ -96,7 +96,7 @@ describe('~/environments/components/environments_app.vue', () => { paginationMock = jest.fn(); }); - it('should request available environments if the scope is invalid', async () => { + it('should request active environments if the scope is invalid', async () => { await createWrapperWithMocked({ environmentsApp: resolvedEnvironmentsApp, folder: resolvedFolder, @@ -105,7 +105,7 @@ describe('~/environments/components/environments_app.vue', () => { expect(environmentAppMock).toHaveBeenCalledWith( expect.anything(), - expect.objectContaining({ scope: 'available', page: 2 }), + expect.objectContaining({ scope: 'active', page: 2 }), expect.anything(), expect.anything(), ); @@ -225,16 +225,16 @@ describe('~/environments/components/environments_app.vue', () => { }); describe('tabs', () => { - it('should show tabs for available and stopped environmets', async () => { + it('should show tabs for active and stopped environmets', async () => { await createWrapperWithMocked({ environmentsApp: resolvedEnvironmentsApp, folder: resolvedFolder, }); - const [available, stopped] = wrapper.findAllByRole('tab').wrappers; + const [active, stopped] = wrapper.findAllByRole('tab').wrappers; - expect(available.text()).toContain(__('Available')); - expect(available.text()).toContain(resolvedEnvironmentsApp.availableCount.toString()); + expect(active.text()).toContain(__('Active')); + expect(active.text()).toContain(resolvedEnvironmentsApp.activeCount.toString()); expect(stopped.text()).toContain(__('Stopped')); expect(stopped.text()).toContain(resolvedEnvironmentsApp.stoppedCount.toString()); }); @@ -379,7 +379,7 @@ describe('~/environments/components/environments_app.vue', () => { next.trigger('click'); await nextTick(); - expect(window.location.search).toBe('?scope=available&page=3&search=prod'); + expect(window.location.search).toBe('?scope=active&page=3&search=prod'); }); }); @@ -406,7 +406,7 @@ describe('~/environments/components/environments_app.vue', () => { await waitForDebounce(); - expect(window.location.search).toBe('?scope=available&page=1&search=hello'); + expect(window.location.search).toBe('?scope=active&page=1&search=hello'); }); it('should query for the entered parameter', async () => { diff --git a/spec/frontend/environments/graphql/mock_data.js b/spec/frontend/environments/graphql/mock_data.js index b80b8508e8d..7d354566761 100644 --- a/spec/frontend/environments/graphql/mock_data.js +++ b/spec/frontend/environments/graphql/mock_data.js @@ -267,12 +267,12 @@ export const environmentsApp = { '{"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, + active_count: 4, stopped_count: 0, }; export const resolvedEnvironmentsApp = { - availableCount: 4, + activeCount: 4, environments: [ { name: 'review', @@ -535,7 +535,7 @@ export const folder = { has_opened_alert: false, }, ], - available_count: 2, + active_count: 2, stopped_count: 0, }; @@ -704,7 +704,7 @@ export const resolvedEnvironment = { }; export const resolvedFolder = { - availableCount: 2, + activeCount: 2, environments: [ { id: 42, diff --git a/spec/frontend/environments/graphql/resolvers/flux_spec.js b/spec/frontend/environments/graphql/resolvers/flux_spec.js index ea733c6e0e8..526c98b55b3 100644 --- a/spec/frontend/environments/graphql/resolvers/flux_spec.js +++ b/spec/frontend/environments/graphql/resolvers/flux_spec.js @@ -15,8 +15,6 @@ describe('~/frontend/environments/graphql/resolvers', () => { headers: { 'GitLab-Agent-Id': '1' }, }, }; - const namespace = 'default'; - const environmentName = 'my-environment'; beforeEach(() => { mockResolvers = resolvers(); @@ -29,34 +27,14 @@ describe('~/frontend/environments/graphql/resolvers', () => { describe('fluxKustomizationStatus', () => { const client = { writeQuery: jest.fn() }; - const endpoint = `${configuration.basePath}/apis/kustomize.toolkit.fluxcd.io/v1beta1/namespaces/${namespace}/kustomizations/${environmentName}`; const fluxResourcePath = 'kustomize.toolkit.fluxcd.io/v1beta1/namespaces/my-namespace/kustomizations/app'; - const endpointWithFluxResourcePath = `${configuration.basePath}/apis/${fluxResourcePath}`; + const endpoint = `${configuration.basePath}/apis/${fluxResourcePath}`; describe('when k8sWatchApi feature is disabled', () => { - it('should request Flux Kustomizations for the provided namespace via the Kubernetes API if the fluxResourcePath is not specified', async () => { - mock - .onGet(endpoint, { withCredentials: true, headers: configuration.baseOptions.headers }) - .reply(HTTP_STATUS_OK, { - status: { conditions: fluxKustomizationsMock }, - }); - - const fluxKustomizationStatus = await mockResolvers.Query.fluxKustomizationStatus( - null, - { - configuration, - namespace, - environmentName, - }, - { client }, - ); - - expect(fluxKustomizationStatus).toEqual(fluxKustomizationsMock); - }); it('should request Flux Kustomization for the provided fluxResourcePath via the Kubernetes API', async () => { mock - .onGet(endpointWithFluxResourcePath, { + .onGet(endpoint, { withCredentials: true, headers: configuration.baseOptions.headers, }) @@ -68,8 +46,6 @@ describe('~/frontend/environments/graphql/resolvers', () => { null, { configuration, - namespace, - environmentName, fluxResourcePath, }, { client }, @@ -87,8 +63,7 @@ describe('~/frontend/environments/graphql/resolvers', () => { null, { configuration, - namespace, - environmentName, + fluxResourcePath, }, { client }, ); @@ -108,6 +83,8 @@ describe('~/frontend/environments/graphql/resolvers', () => { } }); const resourceName = 'custom-resource'; + const resourceNamespace = 'custom-namespace'; + const apiVersion = 'kustomize.toolkit.fluxcd.io/v1beta1'; beforeEach(() => { gon.features = { k8sWatchApi: true }; @@ -120,7 +97,8 @@ describe('~/frontend/environments/graphql/resolvers', () => { mock .onGet(endpoint, { withCredentials: true, headers: configuration.baseOptions.headers }) .reply(HTTP_STATUS_OK, { - metadata: { name: resourceName }, + apiVersion, + metadata: { name: resourceName, namespace: resourceNamespace }, status: { conditions: fluxKustomizationsMock }, }); }); @@ -129,14 +107,13 @@ describe('~/frontend/environments/graphql/resolvers', () => { null, { configuration, - namespace, - environmentName, + fluxResourcePath, }, { client }, ); expect(mockKustomizationStatusFn).toHaveBeenCalledWith( - `/apis/kustomize.toolkit.fluxcd.io/v1beta1/namespaces/${namespace}/kustomizations`, + `/apis/${apiVersion}/namespaces/${resourceNamespace}/kustomizations`, { watch: true, fieldSelector: `metadata.name=${decodeURIComponent(resourceName)}`, @@ -149,8 +126,7 @@ describe('~/frontend/environments/graphql/resolvers', () => { null, { configuration, - namespace, - environmentName, + fluxResourcePath, }, { client }, ); @@ -168,8 +144,7 @@ describe('~/frontend/environments/graphql/resolvers', () => { null, { configuration, - namespace, - environmentName, + fluxResourcePath, }, { client }, ); @@ -181,34 +156,14 @@ describe('~/frontend/environments/graphql/resolvers', () => { describe('fluxHelmReleaseStatus', () => { const client = { writeQuery: jest.fn() }; - const endpoint = `${configuration.basePath}/apis/helm.toolkit.fluxcd.io/v2beta1/namespaces/${namespace}/helmreleases/${environmentName}`; const fluxResourcePath = 'helm.toolkit.fluxcd.io/v2beta1/namespaces/my-namespace/helmreleases/app'; - const endpointWithFluxResourcePath = `${configuration.basePath}/apis/${fluxResourcePath}`; + const endpoint = `${configuration.basePath}/apis/${fluxResourcePath}`; describe('when k8sWatchApi feature is disabled', () => { - it('should request Flux Helm Releases via the Kubernetes API', async () => { - mock - .onGet(endpoint, { withCredentials: true, headers: configuration.baseOptions.headers }) - .reply(HTTP_STATUS_OK, { - status: { conditions: fluxKustomizationsMock }, - }); - - const fluxHelmReleaseStatus = await mockResolvers.Query.fluxHelmReleaseStatus( - null, - { - configuration, - namespace, - environmentName, - }, - { client }, - ); - - expect(fluxHelmReleaseStatus).toEqual(fluxKustomizationsMock); - }); it('should request Flux HelmRelease for the provided fluxResourcePath via the Kubernetes API', async () => { mock - .onGet(endpointWithFluxResourcePath, { + .onGet(endpoint, { withCredentials: true, headers: configuration.baseOptions.headers, }) @@ -220,8 +175,6 @@ describe('~/frontend/environments/graphql/resolvers', () => { null, { configuration, - namespace, - environmentName, fluxResourcePath, }, { client }, @@ -239,8 +192,7 @@ describe('~/frontend/environments/graphql/resolvers', () => { null, { configuration, - namespace, - environmentName, + fluxResourcePath, }, { client }, ); @@ -260,6 +212,8 @@ describe('~/frontend/environments/graphql/resolvers', () => { } }); const resourceName = 'custom-resource'; + const resourceNamespace = 'custom-namespace'; + const apiVersion = 'helm.toolkit.fluxcd.io/v2beta1'; beforeEach(() => { gon.features = { k8sWatchApi: true }; @@ -272,7 +226,8 @@ describe('~/frontend/environments/graphql/resolvers', () => { mock .onGet(endpoint, { withCredentials: true, headers: configuration.baseOptions.headers }) .reply(HTTP_STATUS_OK, { - metadata: { name: resourceName }, + apiVersion, + metadata: { name: resourceName, namespace: resourceNamespace }, status: { conditions: fluxKustomizationsMock }, }); }); @@ -281,14 +236,13 @@ describe('~/frontend/environments/graphql/resolvers', () => { null, { configuration, - namespace, - environmentName, + fluxResourcePath, }, { client }, ); expect(mockHelmReleaseStatusFn).toHaveBeenCalledWith( - `/apis/helm.toolkit.fluxcd.io/v2beta1/namespaces/${namespace}/helmreleases`, + `/apis/${apiVersion}/namespaces/${resourceNamespace}/helmreleases`, { watch: true, fieldSelector: `metadata.name=${decodeURIComponent(resourceName)}`, @@ -301,8 +255,7 @@ describe('~/frontend/environments/graphql/resolvers', () => { null, { configuration, - namespace, - environmentName, + fluxResourcePath, }, { client }, ); @@ -320,8 +273,7 @@ describe('~/frontend/environments/graphql/resolvers', () => { null, { configuration, - namespace, - environmentName, + fluxResourcePath, }, { client }, ); diff --git a/spec/frontend/environments/kubernetes_overview_spec.js b/spec/frontend/environments/kubernetes_overview_spec.js index 9756859f71e..12689df586f 100644 --- a/spec/frontend/environments/kubernetes_overview_spec.js +++ b/spec/frontend/environments/kubernetes_overview_spec.js @@ -122,7 +122,6 @@ describe('~/environments/components/kubernetes_overview.vue', () => { expect(findKubernetesStatusBar().props()).toEqual({ clusterHealthStatus: 'success', configuration, - namespace: kubernetesNamespace, environmentName: resolvedEnvironment.name, fluxResourcePath: fluxResourcePathMock, }); diff --git a/spec/frontend/environments/kubernetes_status_bar_spec.js b/spec/frontend/environments/kubernetes_status_bar_spec.js index 5dec7ca5aac..dcd628354e1 100644 --- a/spec/frontend/environments/kubernetes_status_bar_spec.js +++ b/spec/frontend/environments/kubernetes_status_bar_spec.js @@ -49,7 +49,6 @@ describe('~/environments/components/kubernetes_status_bar.vue', () => { const createWrapper = ({ apolloProvider = createApolloProvider(), clusterHealthStatus = '', - namespace = '', fluxResourcePath = '', } = {}) => { wrapper = shallowMountExtended(KubernetesStatusBar, { @@ -57,7 +56,6 @@ describe('~/environments/components/kubernetes_status_bar.vue', () => { clusterHealthStatus, configuration, environmentName, - namespace, fluxResourcePath, }, apolloProvider, @@ -88,7 +86,7 @@ describe('~/environments/components/kubernetes_status_bar.vue', () => { }); describe('sync badge', () => { - describe('when no namespace is provided', () => { + describe('when no flux resource path is provided', () => { beforeEach(() => { createWrapper(); }); @@ -104,7 +102,6 @@ describe('~/environments/components/kubernetes_status_bar.vue', () => { }); describe('when flux resource path is provided', () => { - const namespace = 'my-namespace'; let fluxResourcePath; describe('if the provided resource is a Kustomization', () => { @@ -112,7 +109,7 @@ describe('~/environments/components/kubernetes_status_bar.vue', () => { fluxResourcePath = 'kustomize.toolkit.fluxcd.io/v1beta1/namespaces/my-namespace/kustomizations/app'; - createWrapper({ namespace, fluxResourcePath }); + createWrapper({ fluxResourcePath }); }); it('requests the Kustomization resource status', () => { @@ -120,8 +117,6 @@ describe('~/environments/components/kubernetes_status_bar.vue', () => { {}, expect.objectContaining({ configuration, - namespace, - environmentName, fluxResourcePath, }), expect.any(Object), @@ -139,7 +134,7 @@ describe('~/environments/components/kubernetes_status_bar.vue', () => { fluxResourcePath = 'helm.toolkit.fluxcd.io/v2beta1/namespaces/my-namespace/helmreleases/app'; - createWrapper({ namespace, fluxResourcePath }); + createWrapper({ fluxResourcePath }); }); it('requests the HelmRelease resource status', () => { @@ -147,8 +142,6 @@ describe('~/environments/components/kubernetes_status_bar.vue', () => { {}, expect.objectContaining({ configuration, - namespace, - environmentName, fluxResourcePath, }), expect.any(Object), @@ -160,30 +153,6 @@ describe('~/environments/components/kubernetes_status_bar.vue', () => { expect(fluxKustomizationStatusQuery).not.toHaveBeenCalled(); }); }); - }); - - describe('when namespace is provided', () => { - describe('with no Flux resources found', () => { - beforeEach(() => { - createWrapper({ namespace: 'my-namespace' }); - }); - - it('requests Kustomizations', () => { - expect(fluxKustomizationStatusQuery).toHaveBeenCalled(); - }); - - it('requests HelmReleases when there were no Kustomizations found', async () => { - await waitForPromises(); - - expect(fluxHelmReleaseStatusQuery).toHaveBeenCalled(); - }); - - it('renders sync status as Unavailable when no Kustomizations and HelmReleases found', async () => { - await waitForPromises(); - - expect(findSyncBadge().text()).toBe(s__('Deployment|Unavailable')); - }); - }); describe('with Flux Kustomizations available', () => { const createApolloProviderWithKustomizations = ({ @@ -202,63 +171,11 @@ describe('~/environments/components/kubernetes_status_bar.vue', () => { it("doesn't request HelmReleases when the Kustomizations were found", async () => { createWrapper({ apolloProvider: createApolloProviderWithKustomizations(), - namespace: 'my-namespace', }); await waitForPromises(); expect(fluxHelmReleaseStatusQuery).not.toHaveBeenCalled(); }); - - it.each` - status | type | badgeType - ${'True'} | ${'Stalled'} | ${'stalled'} - ${'True'} | ${'Reconciling'} | ${'reconciling'} - ${'True'} | ${'Ready'} | ${'reconciled'} - ${'False'} | ${'Ready'} | ${'failed'} - ${'True'} | ${'Unknown'} | ${'unknown'} - `( - 'renders $badgeType when status is $status and type is $type', - async ({ status, type, badgeType }) => { - createWrapper({ - apolloProvider: createApolloProviderWithKustomizations({ - result: { status, type, message: '' }, - }), - namespace: 'my-namespace', - }); - await waitForPromises(); - - const badge = SYNC_STATUS_BADGES[badgeType]; - - expect(findSyncBadge().text()).toBe(badge.text); - expect(findSyncBadge().props()).toMatchObject({ - icon: badge.icon, - variant: badge.variant, - }); - }, - ); - - it.each` - status | type | message | popoverTitle | popoverText - ${'True'} | ${'Stalled'} | ${'stalled reason'} | ${s__('Deployment|Flux sync stalled')} | ${'stalled reason'} - ${'True'} | ${'Reconciling'} | ${''} | ${undefined} | ${s__('Deployment|Flux sync reconciling')} - ${'True'} | ${'Ready'} | ${''} | ${undefined} | ${s__('Deployment|Flux sync reconciled successfully')} - ${'False'} | ${'Ready'} | ${'failed reason'} | ${s__('Deployment|Flux sync failed')} | ${'failed reason'} - ${'True'} | ${'Unknown'} | ${''} | ${s__('Deployment|Flux sync status is unknown')} | ${s__('Deployment|Unable to detect state. %{linkStart}How are states detected?%{linkEnd}')} - `( - 'renders correct popover text when status is $status and type is $type', - async ({ status, type, message, popoverTitle, popoverText }) => { - createWrapper({ - apolloProvider: createApolloProviderWithKustomizations({ - result: { status, type, message }, - }), - namespace: 'my-namespace', - }); - await waitForPromises(); - - expect(findPopover().text()).toMatchInterpolatedText(popoverText); - expect(findPopover().props('title')).toBe(popoverTitle); - }, - ); }); describe('when Flux API errored', () => { @@ -277,7 +194,8 @@ describe('~/environments/components/kubernetes_status_bar.vue', () => { beforeEach(async () => { createWrapper({ apolloProvider: createApolloProviderWithErrors(), - namespace: 'my-namespace', + fluxResourcePath: + 'kustomize.toolkit.fluxcd.io/v1beta1/namespaces/my-namespace/kustomizations/app', }); await waitForPromises(); }); |