2022-04-04 11:22:00 +05:30
|
|
|
import { GlBadge, GlLoadingIcon, GlTooltip } from '@gitlab/ui';
|
2021-01-29 00:20:46 +05:30
|
|
|
import { mount } from '@vue/test-utils';
|
2022-04-04 11:22:00 +05:30
|
|
|
import { nextTick } from 'vue';
|
2021-01-29 00:20:46 +05:30
|
|
|
import { useFakeDate } from 'helpers/fake_date';
|
2022-07-23 23:45:48 +05:30
|
|
|
import { createMockDirective, getBinding } from 'helpers/vue_mock_directive';
|
|
|
|
import { extendedWrapper } from 'helpers/vue_test_utils_helper';
|
2021-01-29 00:20:46 +05:30
|
|
|
import StatesTable from '~/terraform/components/states_table.vue';
|
2021-03-11 19:13:27 +05:30
|
|
|
import StateActions from '~/terraform/components/states_table_actions.vue';
|
2021-01-29 00:20:46 +05:30
|
|
|
|
|
|
|
describe('StatesTable', () => {
|
|
|
|
let wrapper;
|
|
|
|
useFakeDate([2020, 10, 15]);
|
|
|
|
|
2021-02-22 17:27:13 +05:30
|
|
|
const defaultProps = {
|
2021-01-29 00:20:46 +05:30
|
|
|
states: [
|
|
|
|
{
|
2021-03-11 19:13:27 +05:30
|
|
|
_showDetails: true,
|
|
|
|
errorMessages: ['State 1 has errored'],
|
2021-01-29 00:20:46 +05:30
|
|
|
name: 'state-1',
|
2021-03-11 19:13:27 +05:30
|
|
|
loadingLock: false,
|
|
|
|
loadingRemove: false,
|
2021-01-29 00:20:46 +05:30
|
|
|
lockedAt: '2020-10-13T00:00:00Z',
|
|
|
|
lockedByUser: {
|
|
|
|
name: 'user-1',
|
|
|
|
},
|
|
|
|
updatedAt: '2020-10-13T00:00:00Z',
|
|
|
|
latestVersion: null,
|
|
|
|
},
|
|
|
|
{
|
2021-03-11 19:13:27 +05:30
|
|
|
_showDetails: false,
|
|
|
|
errorMessages: [],
|
2021-01-29 00:20:46 +05:30
|
|
|
name: 'state-2',
|
2021-03-11 19:13:27 +05:30
|
|
|
loadingLock: true,
|
|
|
|
loadingRemove: false,
|
2021-01-29 00:20:46 +05:30
|
|
|
lockedAt: null,
|
|
|
|
lockedByUser: null,
|
|
|
|
updatedAt: '2020-10-10T00:00:00Z',
|
|
|
|
latestVersion: null,
|
|
|
|
},
|
|
|
|
{
|
2021-03-11 19:13:27 +05:30
|
|
|
_showDetails: false,
|
|
|
|
errorMessages: [],
|
2021-01-29 00:20:46 +05:30
|
|
|
name: 'state-3',
|
2021-03-11 19:13:27 +05:30
|
|
|
loadingLock: true,
|
|
|
|
loadingRemove: false,
|
2021-01-29 00:20:46 +05:30
|
|
|
lockedAt: '2020-10-10T00:00:00Z',
|
|
|
|
lockedByUser: {
|
|
|
|
name: 'user-2',
|
|
|
|
},
|
|
|
|
updatedAt: '2020-10-10T00:00:00Z',
|
|
|
|
latestVersion: {
|
|
|
|
updatedAt: '2020-10-11T00:00:00Z',
|
|
|
|
createdByUser: {
|
|
|
|
name: 'user-3',
|
|
|
|
},
|
2021-02-22 17:27:13 +05:30
|
|
|
job: {
|
|
|
|
detailedStatus: {
|
|
|
|
detailsPath: '/job-path-3',
|
|
|
|
group: 'failed',
|
|
|
|
icon: 'status_failed',
|
|
|
|
label: 'failed',
|
|
|
|
text: 'failed',
|
|
|
|
},
|
|
|
|
pipeline: {
|
|
|
|
id: 'gid://gitlab/Ci::Pipeline/3',
|
|
|
|
path: '/pipeline-path-3',
|
|
|
|
},
|
|
|
|
},
|
2021-01-29 00:20:46 +05:30
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2021-03-11 19:13:27 +05:30
|
|
|
_showDetails: true,
|
|
|
|
errorMessages: ['State 4 has errored'],
|
2021-01-29 00:20:46 +05:30
|
|
|
name: 'state-4',
|
2021-03-11 19:13:27 +05:30
|
|
|
loadingLock: false,
|
|
|
|
loadingRemove: false,
|
2021-01-29 00:20:46 +05:30
|
|
|
lockedAt: '2020-10-10T00:00:00Z',
|
|
|
|
lockedByUser: null,
|
|
|
|
updatedAt: '2020-10-10T00:00:00Z',
|
|
|
|
latestVersion: {
|
|
|
|
updatedAt: '2020-10-09T00:00:00Z',
|
|
|
|
createdByUser: null,
|
2021-02-22 17:27:13 +05:30
|
|
|
job: {
|
|
|
|
detailedStatus: {
|
|
|
|
detailsPath: '/job-path-4',
|
|
|
|
group: 'passed',
|
|
|
|
icon: 'status_success',
|
|
|
|
label: 'passed',
|
|
|
|
text: 'passed',
|
|
|
|
},
|
|
|
|
pipeline: {
|
|
|
|
id: 'gid://gitlab/Ci::Pipeline/4',
|
|
|
|
path: '/pipeline-path-4',
|
|
|
|
},
|
|
|
|
},
|
2021-01-29 00:20:46 +05:30
|
|
|
},
|
|
|
|
},
|
2021-03-11 19:13:27 +05:30
|
|
|
{
|
|
|
|
_showDetails: false,
|
|
|
|
errorMessages: [],
|
|
|
|
name: 'state-5',
|
|
|
|
loadingLock: false,
|
|
|
|
loadingRemove: true,
|
|
|
|
lockedAt: null,
|
|
|
|
lockedByUser: null,
|
|
|
|
updatedAt: '2020-10-10T00:00:00Z',
|
|
|
|
latestVersion: null,
|
|
|
|
},
|
2022-07-23 23:45:48 +05:30
|
|
|
{
|
|
|
|
_showDetails: false,
|
|
|
|
errorMessages: [],
|
|
|
|
name: 'state-6',
|
|
|
|
loadingLock: false,
|
|
|
|
loadingRemove: false,
|
|
|
|
lockedAt: null,
|
|
|
|
lockedByUser: null,
|
|
|
|
updatedAt: '2020-10-10T00:00:00Z',
|
|
|
|
deletedAt: '2022-02-02T00:00:00Z',
|
|
|
|
latestVersion: null,
|
|
|
|
},
|
2021-01-29 00:20:46 +05:30
|
|
|
],
|
|
|
|
};
|
|
|
|
|
2022-04-04 11:22:00 +05:30
|
|
|
const createComponent = async (propsData = defaultProps) => {
|
2022-07-23 23:45:48 +05:30
|
|
|
wrapper = extendedWrapper(
|
|
|
|
mount(StatesTable, {
|
|
|
|
propsData,
|
|
|
|
provide: { projectPath: 'path/to/project' },
|
|
|
|
directives: {
|
|
|
|
GlTooltip: createMockDirective(),
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
);
|
2022-04-04 11:22:00 +05:30
|
|
|
await nextTick();
|
2021-02-22 17:27:13 +05:30
|
|
|
};
|
|
|
|
|
2022-10-11 01:57:18 +05:30
|
|
|
const findActions = () => wrapper.findAllComponents(StateActions);
|
2021-02-22 17:27:13 +05:30
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
return createComponent();
|
2021-01-29 00:20:46 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
wrapper.destroy();
|
|
|
|
wrapper = null;
|
|
|
|
});
|
|
|
|
|
|
|
|
it.each`
|
2022-07-23 23:45:48 +05:30
|
|
|
name | toolTipText | hasBadge | loading | lineNumber
|
2021-03-11 19:13:27 +05:30
|
|
|
${'state-1'} | ${'Locked by user-1 2 days ago'} | ${true} | ${false} | ${0}
|
|
|
|
${'state-2'} | ${'Locking state'} | ${false} | ${true} | ${1}
|
|
|
|
${'state-3'} | ${'Unlocking state'} | ${false} | ${true} | ${2}
|
|
|
|
${'state-4'} | ${'Locked by Unknown User 5 days ago'} | ${true} | ${false} | ${3}
|
|
|
|
${'state-5'} | ${'Removing'} | ${false} | ${true} | ${4}
|
2022-07-23 23:45:48 +05:30
|
|
|
${'state-6'} | ${'Deletion in progress'} | ${true} | ${false} | ${5}
|
2021-01-29 00:20:46 +05:30
|
|
|
`(
|
|
|
|
'displays the name and locked information "$name" for line "$lineNumber"',
|
2022-07-23 23:45:48 +05:30
|
|
|
({ name, toolTipText, hasBadge, loading, lineNumber }) => {
|
2021-01-29 00:20:46 +05:30
|
|
|
const states = wrapper.findAll('[data-testid="terraform-states-table-name"]');
|
|
|
|
const state = states.at(lineNumber);
|
|
|
|
|
|
|
|
expect(state.text()).toContain(name);
|
2022-11-25 23:54:43 +05:30
|
|
|
expect(state.findComponent(GlBadge).exists()).toBe(hasBadge);
|
|
|
|
expect(state.findComponent(GlLoadingIcon).exists()).toBe(loading);
|
2021-01-29 00:20:46 +05:30
|
|
|
|
2022-07-23 23:45:48 +05:30
|
|
|
if (hasBadge) {
|
|
|
|
const badge = wrapper.findByTestId(`state-badge-${name}`);
|
|
|
|
|
|
|
|
expect(getBinding(badge.element, 'gl-tooltip')).toBeDefined();
|
|
|
|
expect(badge.attributes('title')).toMatchInterpolatedText(toolTipText);
|
2021-01-29 00:20:46 +05:30
|
|
|
}
|
|
|
|
},
|
|
|
|
);
|
|
|
|
|
|
|
|
it.each`
|
|
|
|
updateTime | lineNumber
|
|
|
|
${'updated 2 days ago'} | ${0}
|
|
|
|
${'updated 5 days ago'} | ${1}
|
|
|
|
${'user-3 updated 4 days ago'} | ${2}
|
|
|
|
${'updated 6 days ago'} | ${3}
|
|
|
|
`('displays the time "$updateTime" for line "$lineNumber"', ({ updateTime, lineNumber }) => {
|
|
|
|
const states = wrapper.findAll('[data-testid="terraform-states-table-updated"]');
|
|
|
|
|
|
|
|
const state = states.at(lineNumber);
|
|
|
|
|
|
|
|
expect(state.text()).toMatchInterpolatedText(updateTime);
|
|
|
|
});
|
2021-02-22 17:27:13 +05:30
|
|
|
|
|
|
|
it.each`
|
|
|
|
pipelineText | toolTipAdded | lineNumber
|
|
|
|
${''} | ${false} | ${0}
|
|
|
|
${''} | ${false} | ${1}
|
|
|
|
${'#3 failed Job status'} | ${true} | ${2}
|
|
|
|
${'#4 passed Job status'} | ${true} | ${3}
|
|
|
|
`(
|
|
|
|
'displays the pipeline information for line "$lineNumber"',
|
|
|
|
({ pipelineText, toolTipAdded, lineNumber }) => {
|
|
|
|
const states = wrapper.findAll('[data-testid="terraform-states-table-pipeline"]');
|
|
|
|
const state = states.at(lineNumber);
|
|
|
|
|
2022-11-25 23:54:43 +05:30
|
|
|
expect(state.findComponent(GlTooltip).exists()).toBe(toolTipAdded);
|
2021-02-22 17:27:13 +05:30
|
|
|
expect(state.text()).toMatchInterpolatedText(pipelineText);
|
|
|
|
},
|
|
|
|
);
|
|
|
|
|
|
|
|
it('displays no actions dropdown', () => {
|
|
|
|
expect(findActions().length).toEqual(0);
|
|
|
|
});
|
|
|
|
|
2021-03-11 19:13:27 +05:30
|
|
|
it.each`
|
|
|
|
errorMessage | lineNumber
|
|
|
|
${defaultProps.states[0].errorMessages[0]} | ${0}
|
|
|
|
${defaultProps.states[3].errorMessages[0]} | ${1}
|
|
|
|
`('displays table error message "$errorMessage"', ({ errorMessage, lineNumber }) => {
|
|
|
|
const states = wrapper.findAll('[data-testid="terraform-states-table-error"]');
|
|
|
|
const state = states.at(lineNumber);
|
|
|
|
|
|
|
|
expect(state.text()).toBe(errorMessage);
|
|
|
|
});
|
|
|
|
|
2021-02-22 17:27:13 +05:30
|
|
|
describe('when user is a terraform administrator', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
return createComponent({
|
|
|
|
terraformAdmin: true,
|
|
|
|
...defaultProps,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('displays an actions dropdown for each state', () => {
|
|
|
|
expect(findActions().length).toEqual(defaultProps.states.length);
|
|
|
|
});
|
|
|
|
});
|
2021-01-29 00:20:46 +05:30
|
|
|
});
|