diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-06-05 21:09:44 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-06-05 21:09:44 +0300 |
commit | 2f1a81fd16ff9968d6b986f8a407d963bc2218f9 (patch) | |
tree | d079c1abc2bc282e749a676651c0f02d288874f3 /spec/frontend/environments | |
parent | 18e9429b63f9a095b1ba3606856537b9ca291eac (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/frontend/environments')
5 files changed, 133 insertions, 0 deletions
diff --git a/spec/frontend/environments/kubernetes_overview_spec.js b/spec/frontend/environments/kubernetes_overview_spec.js index d4ba7323aaf..b9eff2f79c5 100644 --- a/spec/frontend/environments/kubernetes_overview_spec.js +++ b/spec/frontend/environments/kubernetes_overview_spec.js @@ -5,6 +5,7 @@ import KubernetesOverview from '~/environments/components/kubernetes_overview.vu import KubernetesAgentInfo from '~/environments/components/kubernetes_agent_info.vue'; import KubernetesPods from '~/environments/components/kubernetes_pods.vue'; import KubernetesTabs from '~/environments/components/kubernetes_tabs.vue'; +import KubernetesStatusBar from '~/environments/components/kubernetes_status_bar.vue'; import { agent, kubernetesNamespace } from './graphql/mock_data'; import { mockKasTunnelUrl } from './mock_data'; @@ -32,6 +33,7 @@ describe('~/environments/components/kubernetes_overview.vue', () => { const findAgentInfo = () => wrapper.findComponent(KubernetesAgentInfo); const findKubernetesPods = () => wrapper.findComponent(KubernetesPods); const findKubernetesTabs = () => wrapper.findComponent(KubernetesTabs); + const findKubernetesStatusBar = () => wrapper.findComponent(KubernetesStatusBar); const findAlert = () => wrapper.findComponent(GlAlert); const createWrapper = () => { @@ -105,6 +107,49 @@ describe('~/environments/components/kubernetes_overview.vue', () => { configuration, }); }); + + it('renders kubernetes status bar', () => { + expect(findKubernetesStatusBar().exists()).toBe(true); + }); + }); + + describe('Kubernetes health status', () => { + beforeEach(() => { + createWrapper(); + toggleCollapse(); + }); + + it("doesn't set `clusterHealthStatus` when pods are still loading", async () => { + findKubernetesPods().vm.$emit('loading', true); + await nextTick(); + + expect(findKubernetesStatusBar().props('clusterHealthStatus')).toBe(''); + }); + + it("doesn't set `clusterHealthStatus` when workload types are still loading", async () => { + findKubernetesTabs().vm.$emit('loading', true); + await nextTick(); + + expect(findKubernetesStatusBar().props('clusterHealthStatus')).toBe(''); + }); + + it('sets `clusterHealthStatus` as error when pods emitted a failure', async () => { + findKubernetesPods().vm.$emit('failed'); + await nextTick(); + + expect(findKubernetesStatusBar().props('clusterHealthStatus')).toBe('error'); + }); + + it('sets `clusterHealthStatus` as error when workload types emitted a failure', async () => { + findKubernetesTabs().vm.$emit('failed'); + await nextTick(); + + expect(findKubernetesStatusBar().props('clusterHealthStatus')).toBe('error'); + }); + + it('sets `clusterHealthStatus` as success when data is loaded and no failures where emitted', () => { + expect(findKubernetesStatusBar().props('clusterHealthStatus')).toBe('success'); + }); }); describe('on cluster error', () => { diff --git a/spec/frontend/environments/kubernetes_pods_spec.js b/spec/frontend/environments/kubernetes_pods_spec.js index 137309d7853..0420d8df1a9 100644 --- a/spec/frontend/environments/kubernetes_pods_spec.js +++ b/spec/frontend/environments/kubernetes_pods_spec.js @@ -50,6 +50,14 @@ describe('~/environments/components/kubernetes_pods.vue', () => { expect(findLoadingIcon().exists()).toBe(true); }); + it('emits loading state', async () => { + createWrapper(); + expect(wrapper.emitted('loading')[0]).toEqual([true]); + + await waitForPromises(); + expect(wrapper.emitted('loading')[1]).toEqual([false]); + }); + it('hides the loading icon when the list of pods loaded', async () => { createWrapper(); await waitForPromises(); @@ -84,6 +92,13 @@ describe('~/environments/components/kubernetes_pods.vue', () => { }); }, ); + + it('emits a failed event when there are failed pods', async () => { + createWrapper(); + await waitForPromises(); + + expect(wrapper.emitted('failed')).toHaveLength(1); + }); }); describe('when gets an error from the cluster_client API', () => { diff --git a/spec/frontend/environments/kubernetes_status_bar_spec.js b/spec/frontend/environments/kubernetes_status_bar_spec.js new file mode 100644 index 00000000000..2ebb30e2766 --- /dev/null +++ b/spec/frontend/environments/kubernetes_status_bar_spec.js @@ -0,0 +1,42 @@ +import { shallowMount } from '@vue/test-utils'; +import { GlLoadingIcon, GlBadge } from '@gitlab/ui'; +import KubernetesStatusBar from '~/environments/components/kubernetes_status_bar.vue'; +import { + CLUSTER_STATUS_HEALTHY_TEXT, + CLUSTER_STATUS_UNHEALTHY_TEXT, +} from '~/environments/constants'; + +describe('~/environments/components/kubernetes_status_bar.vue', () => { + let wrapper; + + const findLoadingIcon = () => wrapper.findComponent(GlLoadingIcon); + const findHealthBadge = () => wrapper.findComponent(GlBadge); + + const createWrapper = ({ clusterHealthStatus = '' } = {}) => { + wrapper = shallowMount(KubernetesStatusBar, { + propsData: { clusterHealthStatus }, + }); + }; + + describe('health badge', () => { + it('shows loading icon when cluster health is not present', () => { + createWrapper(); + + expect(findLoadingIcon().exists()).toBe(true); + }); + + it.each([ + ['success', 'success', CLUSTER_STATUS_HEALTHY_TEXT], + ['error', 'danger', CLUSTER_STATUS_UNHEALTHY_TEXT], + ])( + 'when clusterHealthStatus is %s shows health badge with variant %s and text %s', + (status, variant, text) => { + createWrapper({ clusterHealthStatus: status }); + + expect(findLoadingIcon().exists()).toBe(false); + expect(findHealthBadge().props('variant')).toBe(variant); + expect(findHealthBadge().text()).toBe(text); + }, + ); + }); +}); diff --git a/spec/frontend/environments/kubernetes_summary_spec.js b/spec/frontend/environments/kubernetes_summary_spec.js index 53b83079486..22c81f29f64 100644 --- a/spec/frontend/environments/kubernetes_summary_spec.js +++ b/spec/frontend/environments/kubernetes_summary_spec.js @@ -59,6 +59,14 @@ describe('~/environments/components/kubernetes_summary.vue', () => { expect(findLoadingIcon().exists()).toBe(true); }); + it('emits loading state', async () => { + createWrapper(); + expect(wrapper.emitted('loading')[0]).toEqual([true]); + + await waitForPromises(); + expect(wrapper.emitted('loading')[1]).toEqual([false]); + }); + describe('when workloads data is loaded', () => { beforeEach(async () => { await createWrapper(); @@ -94,6 +102,10 @@ describe('~/environments/components/kubernetes_summary.vue', () => { ); }); + it('emits a failed event when there are failed workload types', () => { + expect(wrapper.emitted('failed')).toHaveLength(1); + }); + it('emits an error message when gets an error from the cluster_client API', async () => { const error = new Error('Error from the cluster_client API'); const createErroredApolloProvider = () => { diff --git a/spec/frontend/environments/kubernetes_tabs_spec.js b/spec/frontend/environments/kubernetes_tabs_spec.js index 429f267347b..81b0bb86e0e 100644 --- a/spec/frontend/environments/kubernetes_tabs_spec.js +++ b/spec/frontend/environments/kubernetes_tabs_spec.js @@ -165,4 +165,23 @@ describe('~/environments/components/kubernetes_tabs.vue', () => { expect(wrapper.emitted('cluster-error')).toEqual([[error]]); }); }); + + describe('summary tab', () => { + beforeEach(() => { + createWrapper(); + }); + + it('emits loading event when gets it from the component', () => { + findKubernetesSummary().vm.$emit('loading', true); + expect(wrapper.emitted('loading')[0]).toEqual([true]); + + findKubernetesSummary().vm.$emit('loading', false); + expect(wrapper.emitted('loading')[1]).toEqual([false]); + }); + + it('emits a failed event when gets it from the component', () => { + findKubernetesSummary().vm.$emit('failed'); + expect(wrapper.emitted('failed')).toHaveLength(1); + }); + }); }); |