2019-12-10 10:07:52 -05:00
|
|
|
import { mount } from '@vue/test-utils';
|
|
|
|
import EnvironmentTable from '~/environments/components/environments_table.vue';
|
|
|
|
import { folder } from './mock_data';
|
|
|
|
|
|
|
|
const eeOnlyProps = {
|
|
|
|
canaryDeploymentFeatureId: 'canary_deployment',
|
|
|
|
showCanaryDeploymentCallout: true,
|
|
|
|
userCalloutsPath: '/callouts',
|
|
|
|
lockPromotionSvgPath: '/assets/illustrations/lock-promotion.svg',
|
|
|
|
helpCanaryDeploymentsPath: 'help/canary-deployments',
|
|
|
|
};
|
2017-11-23 07:04:03 -05:00
|
|
|
|
|
|
|
describe('Environment table', () => {
|
2019-12-10 10:07:52 -05:00
|
|
|
let wrapper;
|
2017-02-13 11:11:11 -05:00
|
|
|
|
2019-12-10 10:07:52 -05:00
|
|
|
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-03-08 05:01:46 -05:00
|
|
|
};
|
|
|
|
|
2017-02-13 11:11:11 -05:00
|
|
|
beforeEach(() => {
|
2019-12-10 10:07:52 -05:00
|
|
|
factory({
|
|
|
|
propsData: {
|
|
|
|
environments: [folder],
|
|
|
|
canReadEnvironment: true,
|
|
|
|
...eeOnlyProps,
|
|
|
|
},
|
|
|
|
});
|
2017-11-23 07:04:03 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => {
|
2019-12-10 10:07:52 -05:00
|
|
|
wrapper.destroy();
|
2017-02-13 11:11:11 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
it('Should render a table', () => {
|
2019-12-10 10:07:52 -05:00
|
|
|
expect(wrapper.classes()).toContain('ci-table');
|
2017-02-13 11:11:11 -05:00
|
|
|
});
|
Sort Environments in Table by Last Updated
Ensure folders push to the top, if both have no last update, sort by
name.
The sorting algorithm should sort in the following priorities:
1. folders first,
2. last updated descending,
3. by name ascending,
the sorting algorithm must:
1. Sort by name ascending,
2. Reverse (sort by name descending),
3. Sort by last deployment ascending,
4. Reverse (last deployment descending, name ascending),
5. Put folders first.
It is done this way, as `underscore`'s sort API is very basic: simple
comparisons, sorting by ascending only.
2019-02-11 10:25:10 -05:00
|
|
|
|
|
|
|
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',
|
|
|
|
},
|
|
|
|
];
|
|
|
|
|
2019-12-10 10:07:52 -05:00
|
|
|
factory({
|
|
|
|
propsData: {
|
|
|
|
environments: mockItems,
|
|
|
|
canReadEnvironment: true,
|
|
|
|
...eeOnlyProps,
|
|
|
|
},
|
Sort Environments in Table by Last Updated
Ensure folders push to the top, if both have no last update, sort by
name.
The sorting algorithm should sort in the following priorities:
1. folders first,
2. last updated descending,
3. by name ascending,
the sorting algorithm must:
1. Sort by name ascending,
2. Reverse (sort by name descending),
3. Sort by last deployment ascending,
4. Reverse (last deployment descending, name ascending),
5. Put folders first.
It is done this way, as `underscore`'s sort API is very basic: simple
comparisons, sorting by ascending only.
2019-02-11 10:25:10 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
const [old, newer, older, noDeploy] = mockItems;
|
|
|
|
|
2019-12-10 10:07:52 -05:00
|
|
|
expect(wrapper.vm.sortEnvironments(mockItems)).toEqual([newer, old, older, noDeploy]);
|
Sort Environments in Table by Last Updated
Ensure folders push to the top, if both have no last update, sort by
name.
The sorting algorithm should sort in the following priorities:
1. folders first,
2. last updated descending,
3. by name ascending,
the sorting algorithm must:
1. Sort by name ascending,
2. Reverse (sort by name descending),
3. Sort by last deployment ascending,
4. Reverse (last deployment descending, name ascending),
5. Put folders first.
It is done this way, as `underscore`'s sort API is very basic: simple
comparisons, sorting by ascending only.
2019-02-11 10:25:10 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
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: [],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
];
|
|
|
|
|
2019-12-10 10:07:52 -05:00
|
|
|
factory({
|
|
|
|
propsData: {
|
|
|
|
environments: mockItems,
|
|
|
|
canReadEnvironment: true,
|
|
|
|
...eeOnlyProps,
|
|
|
|
},
|
Sort Environments in Table by Last Updated
Ensure folders push to the top, if both have no last update, sort by
name.
The sorting algorithm should sort in the following priorities:
1. folders first,
2. last updated descending,
3. by name ascending,
the sorting algorithm must:
1. Sort by name ascending,
2. Reverse (sort by name descending),
3. Sort by last deployment ascending,
4. Reverse (last deployment descending, name ascending),
5. Put folders first.
It is done this way, as `underscore`'s sort API is very basic: simple
comparisons, sorting by ascending only.
2019-02-11 10:25:10 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
const [prod, review, staging] = mockItems;
|
|
|
|
|
2019-12-10 10:07:52 -05:00
|
|
|
expect(wrapper.vm.sortEnvironments(mockItems)).toEqual([review, staging, prod]);
|
Sort Environments in Table by Last Updated
Ensure folders push to the top, if both have no last update, sort by
name.
The sorting algorithm should sort in the following priorities:
1. folders first,
2. last updated descending,
3. by name ascending,
the sorting algorithm must:
1. Sort by name ascending,
2. Reverse (sort by name descending),
3. Sort by last deployment ascending,
4. Reverse (last deployment descending, name ascending),
5. Put folders first.
It is done this way, as `underscore`'s sort API is very basic: simple
comparisons, sorting by ascending only.
2019-02-11 10:25:10 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
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: [],
|
|
|
|
},
|
|
|
|
];
|
|
|
|
|
2019-12-10 10:07:52 -05:00
|
|
|
factory({
|
|
|
|
propsData: {
|
|
|
|
environments: mockItems,
|
|
|
|
canReadEnvironment: true,
|
|
|
|
...eeOnlyProps,
|
|
|
|
},
|
Sort Environments in Table by Last Updated
Ensure folders push to the top, if both have no last update, sort by
name.
The sorting algorithm should sort in the following priorities:
1. folders first,
2. last updated descending,
3. by name ascending,
the sorting algorithm must:
1. Sort by name ascending,
2. Reverse (sort by name descending),
3. Sort by last deployment ascending,
4. Reverse (last deployment descending, name ascending),
5. Put folders first.
It is done this way, as `underscore`'s sort API is very basic: simple
comparisons, sorting by ascending only.
2019-02-11 10:25:10 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
const [old, newer, older] = mockItems;
|
|
|
|
|
2019-12-10 10:07:52 -05:00
|
|
|
expect(wrapper.vm.sortEnvironments(mockItems)).toEqual([older, newer, old]);
|
Sort Environments in Table by Last Updated
Ensure folders push to the top, if both have no last update, sort by
name.
The sorting algorithm should sort in the following priorities:
1. folders first,
2. last updated descending,
3. by name ascending,
the sorting algorithm must:
1. Sort by name ascending,
2. Reverse (sort by name descending),
3. Sort by last deployment ascending,
4. Reverse (last deployment descending, name ascending),
5. Put folders first.
It is done this way, as `underscore`'s sort API is very basic: simple
comparisons, sorting by ascending only.
2019-02-11 10:25:10 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should break ties by name', () => {
|
|
|
|
const mockItems = [
|
|
|
|
{
|
|
|
|
name: 'old',
|
|
|
|
isFolder: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'new',
|
|
|
|
isFolder: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
folderName: 'older',
|
|
|
|
isFolder: true,
|
|
|
|
},
|
|
|
|
];
|
|
|
|
|
2019-12-10 10:07:52 -05:00
|
|
|
factory({
|
|
|
|
propsData: {
|
|
|
|
environments: mockItems,
|
|
|
|
canReadEnvironment: true,
|
|
|
|
...eeOnlyProps,
|
|
|
|
},
|
Sort Environments in Table by Last Updated
Ensure folders push to the top, if both have no last update, sort by
name.
The sorting algorithm should sort in the following priorities:
1. folders first,
2. last updated descending,
3. by name ascending,
the sorting algorithm must:
1. Sort by name ascending,
2. Reverse (sort by name descending),
3. Sort by last deployment ascending,
4. Reverse (last deployment descending, name ascending),
5. Put folders first.
It is done this way, as `underscore`'s sort API is very basic: simple
comparisons, sorting by ascending only.
2019-02-11 10:25:10 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
const [old, newer, older] = mockItems;
|
|
|
|
|
2019-12-10 10:07:52 -05:00
|
|
|
expect(wrapper.vm.sortEnvironments(mockItems)).toEqual([older, newer, old]);
|
Sort Environments in Table by Last Updated
Ensure folders push to the top, if both have no last update, sort by
name.
The sorting algorithm should sort in the following priorities:
1. folders first,
2. last updated descending,
3. by name ascending,
the sorting algorithm must:
1. Sort by name ascending,
2. Reverse (sort by name descending),
3. Sort by last deployment ascending,
4. Reverse (last deployment descending, name ascending),
5. Put folders first.
It is done this way, as `underscore`'s sort API is very basic: simple
comparisons, sorting by ascending only.
2019-02-11 10:25:10 -05:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
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',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'review/master',
|
|
|
|
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;
|
|
|
|
const [addcibuildstatus, master] = mockItems[1].children;
|
|
|
|
|
2019-12-10 10:07:52 -05:00
|
|
|
factory({
|
|
|
|
propsData: {
|
|
|
|
environments: mockItems,
|
|
|
|
canReadEnvironment: true,
|
|
|
|
...eeOnlyProps,
|
|
|
|
},
|
Sort Environments in Table by Last Updated
Ensure folders push to the top, if both have no last update, sort by
name.
The sorting algorithm should sort in the following priorities:
1. folders first,
2. last updated descending,
3. by name ascending,
the sorting algorithm must:
1. Sort by name ascending,
2. Reverse (sort by name descending),
3. Sort by last deployment ascending,
4. Reverse (last deployment descending, name ascending),
5. Put folders first.
It is done this way, as `underscore`'s sort API is very basic: simple
comparisons, sorting by ascending only.
2019-02-11 10:25:10 -05:00
|
|
|
});
|
|
|
|
|
2019-12-10 10:07:52 -05:00
|
|
|
expect(wrapper.vm.sortedEnvironments.map(env => env.name)).toEqual([
|
Sort Environments in Table by Last Updated
Ensure folders push to the top, if both have no last update, sort by
name.
The sorting algorithm should sort in the following priorities:
1. folders first,
2. last updated descending,
3. by name ascending,
the sorting algorithm must:
1. Sort by name ascending,
2. Reverse (sort by name descending),
3. Sort by last deployment ascending,
4. Reverse (last deployment descending, name ascending),
5. Put folders first.
It is done this way, as `underscore`'s sort API is very basic: simple
comparisons, sorting by ascending only.
2019-02-11 10:25:10 -05:00
|
|
|
review.name,
|
|
|
|
staging.name,
|
|
|
|
production.name,
|
|
|
|
]);
|
|
|
|
|
2019-12-10 10:07:52 -05:00
|
|
|
expect(wrapper.vm.sortedEnvironments[0].children).toEqual([master, addcibuildstatus]);
|
Sort Environments in Table by Last Updated
Ensure folders push to the top, if both have no last update, sort by
name.
The sorting algorithm should sort in the following priorities:
1. folders first,
2. last updated descending,
3. by name ascending,
the sorting algorithm must:
1. Sort by name ascending,
2. Reverse (sort by name descending),
3. Sort by last deployment ascending,
4. Reverse (last deployment descending, name ascending),
5. Put folders first.
It is done this way, as `underscore`'s sort API is very basic: simple
comparisons, sorting by ascending only.
2019-02-11 10:25:10 -05:00
|
|
|
});
|
|
|
|
});
|
2017-02-13 11:11:11 -05:00
|
|
|
});
|