1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
|
import { shallowMount } from '@vue/test-utils';
import { GlIcon, GlLink, GlSprintf } from '@gitlab/ui';
import { extendedWrapper } from 'helpers/vue_test_utils_helper';
import TimeAgoTooltip from '~/vue_shared/components/time_ago_tooltip.vue';
import KubernetesAgentInfo from '~/environments/components/kubernetes_agent_info.vue';
import { AGENT_STATUSES, ACTIVE_CONNECTION_TIME } from '~/clusters_list/constants';
import waitForPromises from 'helpers/wait_for_promises';
const defaultClusterAgent = {
name: 'my-agent',
id: 'gid://gitlab/ClusterAgent/1',
webPath: 'path/to/agent-page',
};
const connectedTimeNow = new Date();
const connectedTimeInactive = new Date(connectedTimeNow.getTime() - ACTIVE_CONNECTION_TIME);
describe('~/environments/components/kubernetes_agent_info.vue', () => {
let wrapper;
const findAgentLink = () => wrapper.findComponent(GlLink);
const findAgentStatus = () => wrapper.findByTestId('agent-status');
const findAgentStatusIcon = () => findAgentStatus().findComponent(GlIcon);
const findAgentLastUsedDate = () => wrapper.findByTestId('agent-last-used-date');
const createWrapper = ({ tokens = [] } = {}) => {
wrapper = extendedWrapper(
shallowMount(KubernetesAgentInfo, {
propsData: { clusterAgent: { ...defaultClusterAgent, tokens: { nodes: tokens } } },
stubs: { TimeAgoTooltip, GlSprintf },
}),
);
};
describe('default', () => {
beforeEach(() => {
createWrapper();
});
it('renders the agent name with the link', () => {
expect(findAgentLink().attributes('href')).toBe(defaultClusterAgent.webPath);
expect(findAgentLink().text()).toContain('1');
});
});
describe.each`
lastUsedAt | status | lastUsedText
${null} | ${'unused'} | ${KubernetesAgentInfo.i18n.neverConnectedText}
${connectedTimeNow} | ${'active'} | ${'just now'}
${connectedTimeInactive} | ${'inactive'} | ${'8 minutes ago'}
`('when agent connection status is "$status"', ({ lastUsedAt, status, lastUsedText }) => {
beforeEach(async () => {
const tokens = [{ id: 'token-id', lastUsedAt }];
createWrapper({ tokens });
await waitForPromises();
});
it('displays correct status text', () => {
expect(findAgentStatus().text()).toBe(AGENT_STATUSES[status].name);
});
it('displays correct status icon', () => {
expect(findAgentStatusIcon().props('name')).toBe(AGENT_STATUSES[status].icon);
expect(findAgentStatusIcon().attributes('class')).toBe(AGENT_STATUSES[status].class);
});
it('displays correct last used date status', () => {
expect(findAgentLastUsedDate().text()).toBe(lastUsedText);
});
});
});
|