debian-mirror-gitlab/spec/frontend/environments/kubernetes_overview_spec.js

123 lines
3.5 KiB
JavaScript
Raw Normal View History

2023-05-27 22:25:52 +05:30
import { nextTick } from 'vue';
import { shallowMount } from '@vue/test-utils';
2023-06-20 00:43:36 +05:30
import { GlCollapse, GlButton, GlAlert } from '@gitlab/ui';
2023-05-27 22:25:52 +05:30
import KubernetesOverview from '~/environments/components/kubernetes_overview.vue';
import KubernetesAgentInfo from '~/environments/components/kubernetes_agent_info.vue';
2023-06-20 00:43:36 +05:30
import KubernetesPods from '~/environments/components/kubernetes_pods.vue';
import { agent } from './graphql/mock_data';
import { mockKasTunnelUrl } from './mock_data';
2023-05-27 22:25:52 +05:30
const propsData = {
agentId: agent.id,
agentName: agent.name,
agentProjectPath: agent.project,
2023-06-20 00:43:36 +05:30
namespace: agent.kubernetesNamespace,
};
const provide = {
kasTunnelUrl: mockKasTunnelUrl,
};
const configuration = {
basePath: provide.kasTunnelUrl.replace(/\/$/, ''),
baseOptions: {
headers: { 'GitLab-Agent-Id': '1' },
},
2023-05-27 22:25:52 +05:30
};
describe('~/environments/components/kubernetes_overview.vue', () => {
let wrapper;
const findCollapse = () => wrapper.findComponent(GlCollapse);
const findCollapseButton = () => wrapper.findComponent(GlButton);
const findAgentInfo = () => wrapper.findComponent(KubernetesAgentInfo);
2023-06-20 00:43:36 +05:30
const findKubernetesPods = () => wrapper.findComponent(KubernetesPods);
const findAlert = () => wrapper.findComponent(GlAlert);
2023-05-27 22:25:52 +05:30
const createWrapper = () => {
wrapper = shallowMount(KubernetesOverview, {
propsData,
2023-06-20 00:43:36 +05:30
provide,
2023-05-27 22:25:52 +05:30
});
};
const toggleCollapse = async () => {
findCollapseButton().vm.$emit('click');
await nextTick();
};
describe('default', () => {
beforeEach(() => {
createWrapper();
});
it('renders the kubernetes overview title', () => {
expect(wrapper.text()).toBe(KubernetesOverview.i18n.sectionTitle);
});
});
describe('collapse', () => {
beforeEach(() => {
createWrapper();
});
it('is collapsed by default', () => {
expect(findCollapse().props('visible')).toBeUndefined();
expect(findCollapseButton().attributes('aria-label')).toBe(KubernetesOverview.i18n.expand);
expect(findCollapseButton().props('icon')).toBe('chevron-right');
});
it("doesn't render components when the collapse is not visible", () => {
expect(findAgentInfo().exists()).toBe(false);
2023-06-20 00:43:36 +05:30
expect(findKubernetesPods().exists()).toBe(false);
2023-05-27 22:25:52 +05:30
});
it('opens on click', async () => {
findCollapseButton().vm.$emit('click');
await nextTick();
expect(findCollapse().attributes('visible')).toBe('true');
expect(findCollapseButton().attributes('aria-label')).toBe(KubernetesOverview.i18n.collapse);
expect(findCollapseButton().props('icon')).toBe('chevron-down');
});
});
describe('when section is expanded', () => {
2023-06-20 00:43:36 +05:30
beforeEach(() => {
2023-05-27 22:25:52 +05:30
createWrapper();
2023-06-20 00:43:36 +05:30
toggleCollapse();
});
2023-05-27 22:25:52 +05:30
2023-06-20 00:43:36 +05:30
it('renders kubernetes agent info', () => {
2023-05-27 22:25:52 +05:30
expect(findAgentInfo().props()).toEqual({
agentName: agent.name,
agentId: agent.id,
agentProjectPath: agent.project,
});
});
2023-06-20 00:43:36 +05:30
it('renders kubernetes pods', () => {
expect(findKubernetesPods().props()).toEqual({
namespace: agent.kubernetesNamespace,
configuration,
});
});
});
describe('on cluster error', () => {
beforeEach(() => {
createWrapper();
toggleCollapse();
});
it('shows alert with the error message', async () => {
const error = 'Error message from pods';
findKubernetesPods().vm.$emit('cluster-error', error);
await nextTick();
expect(findAlert().text()).toBe(error);
});
2023-05-27 22:25:52 +05:30
});
});