debian-mirror-gitlab/spec/frontend/clusters/agents/components/token_table_spec.js

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

157 lines
4.5 KiB
JavaScript
Raw Normal View History

2022-05-07 20:08:51 +05:30
import { GlEmptyState, GlTooltip, GlTruncate } from '@gitlab/ui';
2021-11-18 22:05:49 +05:30
import { mount } from '@vue/test-utils';
import TokenTable from '~/clusters/agents/components/token_table.vue';
2022-05-07 20:08:51 +05:30
import CreateTokenButton from '~/clusters/agents/components/create_token_button.vue';
2022-07-23 23:45:48 +05:30
import CreateTokenModal from '~/clusters/agents/components/create_token_modal.vue';
2021-11-18 22:05:49 +05:30
import { useFakeDate } from 'helpers/fake_date';
import { extendedWrapper } from 'helpers/vue_test_utils_helper';
2022-05-07 20:08:51 +05:30
import { MAX_LIST_COUNT } from '~/clusters/agents/constants';
2021-11-18 22:05:49 +05:30
describe('ClusterAgentTokenTable', () => {
let wrapper;
useFakeDate([2021, 2, 15]);
const defaultTokens = [
{
id: '1',
createdAt: '2021-02-13T00:00:00Z',
description: 'Description of token 1',
createdByUser: {
name: 'user-1',
},
lastUsedAt: '2021-02-13T00:00:00Z',
name: 'token-1',
},
{
id: '2',
createdAt: '2021-02-10T00:00:00Z',
description: null,
createdByUser: null,
lastUsedAt: null,
name: 'token-2',
},
];
2022-05-07 20:08:51 +05:30
const clusterAgentId = 'cluster-agent-id';
const cursor = {
first: MAX_LIST_COUNT,
last: null,
};
const provide = {
agentName: 'cluster-agent',
projectPath: 'path/to/project',
canAdminCluster: true,
};
2021-11-18 22:05:49 +05:30
const createComponent = (tokens) => {
2022-05-07 20:08:51 +05:30
wrapper = extendedWrapper(
mount(TokenTable, { propsData: { tokens, clusterAgentId, cursor }, provide }),
);
2021-11-18 22:05:49 +05:30
};
2022-05-07 20:08:51 +05:30
const findEmptyState = () => wrapper.findComponent(GlEmptyState);
const findCreateTokenBtn = () => wrapper.findComponent(CreateTokenButton);
2022-07-23 23:45:48 +05:30
const findCreateModal = () => wrapper.findComponent(CreateTokenModal);
2021-11-18 22:05:49 +05:30
beforeEach(() => {
return createComponent(defaultTokens);
});
afterEach(() => {
wrapper.destroy();
});
2022-05-07 20:08:51 +05:30
it('displays the create token button', () => {
expect(findCreateTokenBtn().exists()).toBe(true);
});
2021-11-18 22:05:49 +05:30
2022-07-23 23:45:48 +05:30
it('passes the correct params to the create token modal component', () => {
expect(findCreateModal().props()).toMatchObject({
2022-05-07 20:08:51 +05:30
clusterAgentId,
cursor,
});
2021-11-18 22:05:49 +05:30
});
it.each`
name | lineNumber
${'token-1'} | ${0}
${'token-2'} | ${1}
`('displays token name "$name" for line "$lineNumber"', ({ name, lineNumber }) => {
2022-05-07 20:08:51 +05:30
const tokens = wrapper.findAllByTestId('agent-token-name');
2021-11-18 22:05:49 +05:30
const token = tokens.at(lineNumber);
expect(token.text()).toBe(name);
});
it.each`
lastContactText | lineNumber
${'2 days ago'} | ${0}
${'Never'} | ${1}
`(
'displays last contact information "$lastContactText" for line "$lineNumber"',
({ lastContactText, lineNumber }) => {
const tokens = wrapper.findAllByTestId('agent-token-used');
const token = tokens.at(lineNumber);
expect(token.text()).toBe(lastContactText);
},
);
it.each`
createdText | lineNumber
${'2 days ago'} | ${0}
${'5 days ago'} | ${1}
`(
'displays created information "$createdText" for line "$lineNumber"',
({ createdText, lineNumber }) => {
2022-05-07 20:08:51 +05:30
const tokens = wrapper.findAllByTestId('agent-token-created-time');
2021-11-18 22:05:49 +05:30
const token = tokens.at(lineNumber);
expect(token.text()).toBe(createdText);
},
);
it.each`
createdBy | lineNumber
${'user-1'} | ${0}
${'Unknown user'} | ${1}
`(
'displays creator information "$createdBy" for line "$lineNumber"',
({ createdBy, lineNumber }) => {
2022-05-07 20:08:51 +05:30
const tokens = wrapper.findAllByTestId('agent-token-created-user');
2021-11-18 22:05:49 +05:30
const token = tokens.at(lineNumber);
expect(token.text()).toBe(createdBy);
},
);
it.each`
description | truncatesText | hasTooltip | lineNumber
${'Description of token 1'} | ${true} | ${true} | ${0}
${''} | ${false} | ${false} | ${1}
`(
'displays description information "$description" for line "$lineNumber"',
({ description, truncatesText, hasTooltip, lineNumber }) => {
2022-05-07 20:08:51 +05:30
const tokens = wrapper.findAllByTestId('agent-token-description');
2021-11-18 22:05:49 +05:30
const token = tokens.at(lineNumber);
expect(token.text()).toContain(description);
2022-08-27 11:52:29 +05:30
expect(token.findComponent(GlTruncate).exists()).toBe(truncatesText);
expect(token.findComponent(GlTooltip).exists()).toBe(hasTooltip);
2021-11-18 22:05:49 +05:30
},
);
describe('when there are no tokens', () => {
beforeEach(() => {
return createComponent([]);
});
it('displays an empty state', () => {
const emptyState = findEmptyState();
expect(emptyState.exists()).toBe(true);
expect(emptyState.text()).toContain(TokenTable.i18n.noTokens);
});
});
});