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

422 lines
11 KiB
JavaScript
Raw Normal View History

2020-01-01 13:55:28 +05:30
import { mount } from '@vue/test-utils';
2022-04-04 11:22:00 +05:30
import { nextTick } from 'vue';
2021-03-11 19:13:27 +05:30
import CanaryUpdateModal from '~/environments/components/canary_update_modal.vue';
import DeployBoard from '~/environments/components/deploy_board.vue';
2020-01-01 13:55:28 +05:30
import EnvironmentTable from '~/environments/components/environments_table.vue';
2021-03-08 18:12:59 +05:30
import eventHub from '~/environments/event_hub';
import { folder, deployBoardMockData } from './mock_data';
2020-01-01 13:55:28 +05:30
const eeOnlyProps = {
userCalloutsPath: '/callouts',
lockPromotionSvgPath: '/assets/illustrations/lock-promotion.svg',
helpCanaryDeploymentsPath: 'help/canary-deployments',
};
2018-03-17 18:26:18 +05:30
describe('Environment table', () => {
2020-01-01 13:55:28 +05:30
let wrapper;
2017-08-17 22:00:37 +05:30
2020-01-01 13:55:28 +05:30
const factory = (options = {}) => {
// This destroys any wrappers created before a nested call to factory reassigns it
if (wrapper && wrapper.destroy) {
wrapper.destroy();
}
wrapper = mount(EnvironmentTable, {
...options,
});
2019-07-07 11:18:12 +05:30
};
2017-08-17 22:00:37 +05:30
beforeEach(() => {
2020-01-01 13:55:28 +05:30
factory({
propsData: {
environments: [folder],
...eeOnlyProps,
},
});
2018-03-17 18:26:18 +05:30
});
afterEach(() => {
2020-01-01 13:55:28 +05:30
wrapper.destroy();
2017-08-17 22:00:37 +05:30
});
2021-03-08 18:12:59 +05:30
it('Should render a table', async () => {
const mockItem = {
name: 'review',
folderName: 'review',
size: 3,
isFolder: true,
environment_path: 'url',
};
await factory({
propsData: {
environments: [mockItem],
userCalloutsPath: '/callouts',
lockPromotionSvgPath: '/assets/illustrations/lock-promotion.svg',
helpCanaryDeploymentsPath: 'help/canary-deployments',
},
});
2020-01-01 13:55:28 +05:30
expect(wrapper.classes()).toContain('ci-table');
2017-08-17 22:00:37 +05:30
});
2019-07-07 11:18:12 +05:30
2021-03-08 18:12:59 +05:30
it('should render deploy board container when data is provided', async () => {
const mockItem = {
name: 'review',
size: 1,
environment_path: 'url',
logs_path: 'url',
id: 1,
hasDeployBoard: true,
deployBoardData: deployBoardMockData,
isDeployBoardVisible: true,
isLoadingDeployBoard: false,
isEmptyDeployBoard: false,
};
await factory({
propsData: {
environments: [mockItem],
canCreateDeployment: false,
userCalloutsPath: '/callouts',
lockPromotionSvgPath: '/assets/illustrations/lock-promotion.svg',
helpCanaryDeploymentsPath: 'help/canary-deployments',
},
});
expect(wrapper.find('.js-deploy-board-row').exists()).toBe(true);
expect(wrapper.find('.deploy-board-icon').exists()).toBe(true);
});
2021-06-08 01:23:25 +05:30
it('should render deploy board container when data is provided for children', async () => {
const mockItem = {
name: 'review',
size: 1,
environment_path: 'url',
logs_path: 'url',
id: 1,
isFolder: true,
isOpen: true,
children: [
{
name: 'review/test',
hasDeployBoard: true,
deployBoardData: deployBoardMockData,
isDeployBoardVisible: true,
isLoadingDeployBoard: false,
isEmptyDeployBoard: false,
},
],
};
await factory({
propsData: {
environments: [mockItem],
canCreateDeployment: false,
userCalloutsPath: '/callouts',
lockPromotionSvgPath: '/assets/illustrations/lock-promotion.svg',
helpCanaryDeploymentsPath: 'help/canary-deployments',
},
});
expect(wrapper.find('.js-deploy-board-row').exists()).toBe(true);
expect(wrapper.find('.deploy-board-icon').exists()).toBe(true);
});
2022-06-21 17:19:12 +05:30
it('should toggle deploy board visibility when arrow is clicked', async () => {
2021-03-08 18:12:59 +05:30
const mockItem = {
name: 'review',
size: 1,
environment_path: 'url',
id: 1,
hasDeployBoard: true,
deployBoardData: {
instances: [{ status: 'ready', tooltip: 'foo' }],
abort_url: 'url',
rollback_url: 'url',
completion: 100,
is_completed: true,
canary_ingress: { canary_weight: 60 },
},
isDeployBoardVisible: false,
};
eventHub.$on('toggleDeployBoard', (env) => {
expect(env.id).toEqual(mockItem.id);
});
factory({
propsData: {
environments: [mockItem],
userCalloutsPath: '/callouts',
lockPromotionSvgPath: '/assets/illustrations/lock-promotion.svg',
helpCanaryDeploymentsPath: 'help/canary-deployments',
},
});
2022-06-21 17:19:12 +05:30
await wrapper.find('.deploy-board-icon').trigger('click');
2021-03-08 18:12:59 +05:30
});
2021-06-08 01:23:25 +05:30
it('should set the environment to change and weight when a change canary weight event is recevied', async () => {
2021-03-08 18:12:59 +05:30
const mockItem = {
name: 'review',
size: 1,
environment_path: 'url',
logs_path: 'url',
id: 1,
hasDeployBoard: true,
deployBoardData: deployBoardMockData,
isDeployBoardVisible: true,
isLoadingDeployBoard: false,
isEmptyDeployBoard: false,
};
await factory({
propsData: {
environments: [mockItem],
canCreateDeployment: false,
userCalloutsPath: '/callouts',
lockPromotionSvgPath: '/assets/illustrations/lock-promotion.svg',
helpCanaryDeploymentsPath: 'help/canary-deployments',
},
});
wrapper.find(DeployBoard).vm.$emit('changeCanaryWeight', 40);
2022-04-04 11:22:00 +05:30
await nextTick();
2021-03-08 18:12:59 +05:30
expect(wrapper.find(CanaryUpdateModal).props()).toMatchObject({
weight: 40,
environment: mockItem,
});
});
2019-07-07 11:18:12 +05:30
describe('sortEnvironments', () => {
it('should sort environments by last updated', () => {
const mockItems = [
{
name: 'old',
size: 3,
isFolder: false,
last_deployment: {
created_at: new Date(2019, 0, 5).toISOString(),
},
},
{
name: 'new',
size: 3,
isFolder: false,
last_deployment: {
created_at: new Date(2019, 1, 5).toISOString(),
},
},
{
name: 'older',
size: 3,
isFolder: false,
last_deployment: {
created_at: new Date(2018, 0, 5).toISOString(),
},
},
{
name: 'an environment with no deployment',
},
];
2020-01-01 13:55:28 +05:30
factory({
propsData: {
environments: mockItems,
...eeOnlyProps,
},
2019-07-07 11:18:12 +05:30
});
const [old, newer, older, noDeploy] = mockItems;
2020-01-01 13:55:28 +05:30
expect(wrapper.vm.sortEnvironments(mockItems)).toEqual([newer, old, older, noDeploy]);
2019-07-07 11:18:12 +05:30
});
it('should push environments with no deployments to the bottom', () => {
const mockItems = [
{
name: 'production',
size: 1,
id: 2,
state: 'available',
external_url: 'https://google.com/production',
environment_type: null,
last_deployment: null,
has_stop_action: false,
environment_path: '/Commit451/lab-coat/environments/2',
stop_path: '/Commit451/lab-coat/environments/2/stop',
folder_path: '/Commit451/lab-coat/environments/folders/production',
created_at: '2019-01-17T16:26:10.064Z',
updated_at: '2019-01-17T16:27:37.717Z',
can_stop: true,
},
{
name: 'review/225addcibuildstatus',
size: 2,
isFolder: true,
isLoadingFolderContent: false,
folderName: 'review',
isOpen: false,
children: [],
id: 12,
state: 'available',
external_url: 'https://google.com/review/225addcibuildstatus',
environment_type: 'review',
last_deployment: null,
has_stop_action: false,
environment_path: '/Commit451/lab-coat/environments/12',
stop_path: '/Commit451/lab-coat/environments/12/stop',
folder_path: '/Commit451/lab-coat/environments/folders/review',
created_at: '2019-01-17T16:27:37.877Z',
updated_at: '2019-01-17T16:27:37.883Z',
can_stop: true,
},
{
name: 'staging',
size: 1,
id: 1,
state: 'available',
external_url: 'https://google.com/staging',
environment_type: null,
last_deployment: {
created_at: '2019-01-17T16:26:15.125Z',
scheduled_actions: [],
},
},
];
2020-01-01 13:55:28 +05:30
factory({
propsData: {
environments: mockItems,
...eeOnlyProps,
},
2019-07-07 11:18:12 +05:30
});
const [prod, review, staging] = mockItems;
2020-01-01 13:55:28 +05:30
expect(wrapper.vm.sortEnvironments(mockItems)).toEqual([review, staging, prod]);
2019-07-07 11:18:12 +05:30
});
it('should sort environments by folder first', () => {
const mockItems = [
{
name: 'old',
size: 3,
isFolder: false,
last_deployment: {
created_at: new Date(2019, 0, 5).toISOString(),
},
},
{
name: 'new',
size: 3,
isFolder: false,
last_deployment: {
created_at: new Date(2019, 1, 5).toISOString(),
},
},
{
name: 'older',
size: 3,
isFolder: true,
children: [],
},
];
2020-01-01 13:55:28 +05:30
factory({
propsData: {
environments: mockItems,
...eeOnlyProps,
},
2019-07-07 11:18:12 +05:30
});
const [old, newer, older] = mockItems;
2020-01-01 13:55:28 +05:30
expect(wrapper.vm.sortEnvironments(mockItems)).toEqual([older, newer, old]);
2019-07-07 11:18:12 +05:30
});
it('should break ties by name', () => {
const mockItems = [
{
name: 'old',
isFolder: false,
},
{
name: 'new',
isFolder: false,
},
{
folderName: 'older',
isFolder: true,
},
];
2020-01-01 13:55:28 +05:30
factory({
propsData: {
environments: mockItems,
...eeOnlyProps,
},
2019-07-07 11:18:12 +05:30
});
const [old, newer, older] = mockItems;
2020-01-01 13:55:28 +05:30
expect(wrapper.vm.sortEnvironments(mockItems)).toEqual([older, newer, old]);
2019-07-07 11:18:12 +05:30
});
});
describe('sortedEnvironments', () => {
it('it should sort children as well', () => {
const mockItems = [
{
name: 'production',
last_deployment: null,
},
{
name: 'review/225addcibuildstatus',
isFolder: true,
folderName: 'review',
isOpen: true,
children: [
{
name: 'review/225addcibuildstatus',
last_deployment: {
created_at: '2019-01-17T16:26:15.125Z',
},
},
{
2021-06-08 01:23:25 +05:30
name: 'review/main',
2019-07-07 11:18:12 +05:30
last_deployment: {
created_at: '2019-02-17T16:26:15.125Z',
},
},
],
},
{
name: 'staging',
last_deployment: {
created_at: '2019-01-17T16:26:15.125Z',
},
},
];
const [production, review, staging] = mockItems;
2021-06-08 01:23:25 +05:30
const [addcibuildstatus, main] = mockItems[1].children;
2019-07-07 11:18:12 +05:30
2020-01-01 13:55:28 +05:30
factory({
propsData: {
environments: mockItems,
...eeOnlyProps,
},
2019-07-07 11:18:12 +05:30
});
2021-03-08 18:12:59 +05:30
expect(wrapper.vm.sortedEnvironments.map((env) => env.name)).toEqual([
2019-07-07 11:18:12 +05:30
review.name,
staging.name,
production.name,
]);
2021-06-08 01:23:25 +05:30
expect(wrapper.vm.sortedEnvironments[0].children).toEqual([main, addcibuildstatus]);
2019-07-07 11:18:12 +05:30
});
});
2017-08-17 22:00:37 +05:30
});