2019-12-10 10:07:52 -05:00
|
|
|
import { mount } from '@vue/test-utils';
|
2022-04-19 11:08:32 -04:00
|
|
|
import { GlAvatarLink, GlAvatar } from '@gitlab/ui';
|
2021-02-14 13:09:20 -05:00
|
|
|
import { cloneDeep } from 'lodash';
|
2019-12-10 10:07:52 -05:00
|
|
|
import { format } from 'timeago.js';
|
2021-08-04 02:09:49 -04:00
|
|
|
import { mockTracking, unmockTracking, triggerEvent } from 'helpers/tracking_helper';
|
|
|
|
import ActionsComponent from '~/environments/components/environment_actions.vue';
|
2021-02-14 13:09:20 -05:00
|
|
|
import DeleteComponent from '~/environments/components/environment_delete.vue';
|
2021-08-04 02:09:49 -04:00
|
|
|
import ExternalUrlComponent from '~/environments/components/environment_external_url.vue';
|
2019-12-10 10:07:52 -05:00
|
|
|
import EnvironmentItem from '~/environments/components/environment_item.vue';
|
2020-01-03 04:07:33 -05:00
|
|
|
import PinComponent from '~/environments/components/environment_pin.vue';
|
2021-08-04 02:09:49 -04:00
|
|
|
import RollbackComponent from '~/environments/components/environment_rollback.vue';
|
|
|
|
import StopComponent from '~/environments/components/environment_stop.vue';
|
|
|
|
import TerminalButtonComponent from '~/environments/components/environment_terminal_button.vue';
|
2020-08-31 08:10:39 -04:00
|
|
|
import { differenceInMilliseconds } from '~/lib/utils/datetime_utility';
|
2019-12-10 10:07:52 -05:00
|
|
|
import { environment, folder, tableData } from './mock_data';
|
|
|
|
|
|
|
|
describe('Environment item', () => {
|
|
|
|
let wrapper;
|
2021-08-04 02:09:49 -04:00
|
|
|
let tracking;
|
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(EnvironmentItem, {
|
|
|
|
...options,
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
factory({
|
|
|
|
propsData: {
|
|
|
|
model: environment,
|
|
|
|
tableData,
|
|
|
|
},
|
|
|
|
});
|
2021-08-04 02:09:49 -04:00
|
|
|
|
|
|
|
tracking = mockTracking(undefined, wrapper.element, jest.spyOn);
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
unmockTracking();
|
2019-12-10 10:07:52 -05:00
|
|
|
});
|
|
|
|
|
2020-01-03 04:07:33 -05:00
|
|
|
const findAutoStop = () => wrapper.find('.js-auto-stop');
|
2020-12-09 10:10:12 -05:00
|
|
|
const findUpcomingDeployment = () => wrapper.find('[data-testid="upcoming-deployment"]');
|
2022-04-19 11:08:32 -04:00
|
|
|
const findLastDeployment = () => wrapper.find('[data-testid="environment-deployment-id-cell"]');
|
2020-12-09 10:10:12 -05:00
|
|
|
const findUpcomingDeploymentContent = () =>
|
|
|
|
wrapper.find('[data-testid="upcoming-deployment-content"]');
|
|
|
|
const findUpcomingDeploymentStatusLink = () =>
|
|
|
|
wrapper.find('[data-testid="upcoming-deployment-status-link"]');
|
2022-04-19 11:08:32 -04:00
|
|
|
const findLastDeploymentAvatarLink = () => findLastDeployment().findComponent(GlAvatarLink);
|
|
|
|
const findLastDeploymentAvatar = () => findLastDeployment().findComponent(GlAvatar);
|
|
|
|
const findUpcomingDeploymentAvatarLink = () =>
|
|
|
|
findUpcomingDeployment().findComponent(GlAvatarLink);
|
|
|
|
const findUpcomingDeploymentAvatar = () => findUpcomingDeployment().findComponent(GlAvatar);
|
2020-01-03 04:07:33 -05:00
|
|
|
|
2019-12-10 10:07:52 -05:00
|
|
|
afterEach(() => {
|
|
|
|
wrapper.destroy();
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('when item is not folder', () => {
|
|
|
|
it('should render environment name', () => {
|
|
|
|
expect(wrapper.find('.environment-name').text()).toContain(environment.name);
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('With deployment', () => {
|
|
|
|
it('should render deployment internal id', () => {
|
|
|
|
expect(wrapper.find('.deployment-column span').text()).toContain(
|
2022-07-14 17:09:55 -04:00
|
|
|
environment.last_deployment.iid.toString(),
|
2019-12-10 10:07:52 -05:00
|
|
|
);
|
|
|
|
|
|
|
|
expect(wrapper.find('.deployment-column span').text()).toContain('#');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should render last deployment date', () => {
|
2019-12-12 04:07:48 -05:00
|
|
|
const formattedDate = format(environment.last_deployment.deployed_at);
|
2019-12-10 10:07:52 -05:00
|
|
|
|
2019-12-12 04:07:48 -05:00
|
|
|
expect(wrapper.find('.environment-created-date-timeago').text()).toContain(formattedDate);
|
2019-12-10 10:07:52 -05:00
|
|
|
});
|
|
|
|
|
2020-03-25 05:08:11 -04:00
|
|
|
it('should not render the delete button', () => {
|
2021-08-04 02:09:49 -04:00
|
|
|
expect(wrapper.findComponent(DeleteComponent).exists()).toBe(false);
|
2020-03-25 05:08:11 -04:00
|
|
|
});
|
|
|
|
|
2019-12-10 10:07:52 -05:00
|
|
|
describe('With user information', () => {
|
|
|
|
it('should render user avatar with link to profile', () => {
|
2022-04-19 11:08:32 -04:00
|
|
|
const avatarLink = findLastDeploymentAvatarLink();
|
|
|
|
const avatar = findLastDeploymentAvatar();
|
2022-08-02 11:09:10 -04:00
|
|
|
const { username, avatar_url: src, web_url } = environment.last_deployment.user;
|
2022-04-19 11:08:32 -04:00
|
|
|
|
|
|
|
expect(avatarLink.attributes('href')).toBe(web_url);
|
|
|
|
expect(avatar.props()).toMatchObject({
|
2022-08-02 11:09:10 -04:00
|
|
|
src,
|
2022-04-19 11:08:32 -04:00
|
|
|
entityName: username,
|
|
|
|
});
|
|
|
|
expect(avatar.attributes()).toMatchObject({
|
|
|
|
title: username,
|
|
|
|
alt: `${username}'s avatar`,
|
|
|
|
});
|
2019-12-10 10:07:52 -05:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('With build url', () => {
|
|
|
|
it('should link to build url provided', () => {
|
|
|
|
expect(wrapper.find('.build-link').attributes('href')).toEqual(
|
|
|
|
environment.last_deployment.deployable.build_path,
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should render deployable name and id', () => {
|
|
|
|
expect(wrapper.find('.build-link').attributes('href')).toEqual(
|
|
|
|
environment.last_deployment.deployable.build_path,
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('With commit information', () => {
|
|
|
|
it('should render commit component', () => {
|
|
|
|
expect(wrapper.find('.js-commit-component')).toBeDefined();
|
|
|
|
});
|
|
|
|
});
|
2020-01-03 04:07:33 -05:00
|
|
|
|
2020-12-09 10:10:12 -05:00
|
|
|
describe('When the envionment has an upcoming deployment', () => {
|
|
|
|
describe('When the upcoming deployment has a deployable', () => {
|
|
|
|
it('should render the build ID and user', () => {
|
2022-04-19 11:08:32 -04:00
|
|
|
const avatarLink = findUpcomingDeploymentAvatarLink();
|
|
|
|
const avatar = findUpcomingDeploymentAvatar();
|
2022-08-02 11:09:10 -04:00
|
|
|
const { username, avatar_url: src, web_url } = environment.upcoming_deployment.user;
|
2022-04-19 11:08:32 -04:00
|
|
|
|
|
|
|
expect(findUpcomingDeploymentContent().text()).toMatchInterpolatedText('#27 by');
|
|
|
|
expect(avatarLink.attributes('href')).toBe(web_url);
|
|
|
|
expect(avatar.props()).toMatchObject({
|
2022-08-02 11:09:10 -04:00
|
|
|
src,
|
2022-04-19 11:08:32 -04:00
|
|
|
entityName: username,
|
|
|
|
});
|
2020-12-09 10:10:12 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should render a status icon with a link and tooltip', () => {
|
|
|
|
expect(findUpcomingDeploymentStatusLink().exists()).toBe(true);
|
|
|
|
|
|
|
|
expect(findUpcomingDeploymentStatusLink().attributes().href).toBe(
|
|
|
|
'/root/environment-test/-/jobs/892',
|
|
|
|
);
|
|
|
|
|
|
|
|
expect(findUpcomingDeploymentStatusLink().attributes().title).toBe(
|
|
|
|
'Deployment running',
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('When the deployment does not have a deployable', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
const environmentWithoutDeployable = cloneDeep(environment);
|
|
|
|
delete environmentWithoutDeployable.upcoming_deployment.deployable;
|
|
|
|
|
|
|
|
factory({
|
|
|
|
propsData: {
|
|
|
|
model: environmentWithoutDeployable,
|
|
|
|
tableData,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2022-04-19 11:08:32 -04:00
|
|
|
it('should still render the build ID and user avatar', () => {
|
|
|
|
const avatarLink = findUpcomingDeploymentAvatarLink();
|
|
|
|
const avatar = findUpcomingDeploymentAvatar();
|
2022-08-02 11:09:10 -04:00
|
|
|
const { username, avatar_url: src, web_url } = environment.upcoming_deployment.user;
|
2022-04-19 11:08:32 -04:00
|
|
|
|
|
|
|
expect(findUpcomingDeploymentContent().text()).toMatchInterpolatedText('#27 by');
|
|
|
|
expect(avatarLink.attributes('href')).toBe(web_url);
|
|
|
|
expect(avatar.props()).toMatchObject({
|
2022-08-02 11:09:10 -04:00
|
|
|
src,
|
2022-04-19 11:08:32 -04:00
|
|
|
entityName: username,
|
|
|
|
});
|
2020-12-09 10:10:12 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should not render the status icon', () => {
|
|
|
|
expect(findUpcomingDeploymentStatusLink().exists()).toBe(false);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('Without upcoming deployment', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
const environmentWithoutUpcomingDeployment = cloneDeep(environment);
|
|
|
|
delete environmentWithoutUpcomingDeployment.upcoming_deployment;
|
|
|
|
|
|
|
|
factory({
|
|
|
|
propsData: {
|
|
|
|
model: environmentWithoutUpcomingDeployment,
|
|
|
|
tableData,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should not render anything in the upcoming deployment column', () => {
|
|
|
|
expect(findUpcomingDeploymentContent().exists()).toBe(false);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2020-01-03 04:07:33 -05:00
|
|
|
describe('Without auto-stop date', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
factory({
|
|
|
|
propsData: {
|
|
|
|
model: environment,
|
|
|
|
tableData,
|
|
|
|
shouldShowAutoStopDate: true,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should not render a date', () => {
|
|
|
|
expect(findAutoStop().exists()).toBe(false);
|
|
|
|
});
|
|
|
|
|
2020-03-25 05:08:11 -04:00
|
|
|
it('should not render the auto-stop button', () => {
|
2021-08-04 02:09:49 -04:00
|
|
|
expect(wrapper.findComponent(PinComponent).exists()).toBe(false);
|
2020-01-03 04:07:33 -05:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('With auto-stop date', () => {
|
|
|
|
describe('in the future', () => {
|
2021-08-04 02:09:49 -04:00
|
|
|
let pin;
|
|
|
|
|
2020-01-03 04:07:33 -05:00
|
|
|
const futureDate = new Date(Date.now() + 100000);
|
|
|
|
beforeEach(() => {
|
|
|
|
factory({
|
|
|
|
propsData: {
|
|
|
|
model: {
|
|
|
|
...environment,
|
|
|
|
auto_stop_at: futureDate,
|
|
|
|
},
|
|
|
|
tableData,
|
|
|
|
shouldShowAutoStopDate: true,
|
|
|
|
},
|
|
|
|
});
|
2021-08-04 02:09:49 -04:00
|
|
|
tracking = mockTracking(undefined, wrapper.element, jest.spyOn);
|
|
|
|
|
|
|
|
pin = wrapper.findComponent(PinComponent);
|
2020-01-03 04:07:33 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
it('renders the date', () => {
|
|
|
|
expect(findAutoStop().text()).toContain(format(futureDate));
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should render the auto-stop button', () => {
|
2021-08-04 02:09:49 -04:00
|
|
|
expect(pin.exists()).toBe(true);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should tracks clicks', () => {
|
|
|
|
pin.trigger('click');
|
|
|
|
|
|
|
|
expect(tracking).toHaveBeenCalledWith('_category_', 'click_button', {
|
|
|
|
label: 'environment_pin',
|
|
|
|
});
|
2020-01-03 04:07:33 -05:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('in the past', () => {
|
2020-08-31 08:10:39 -04:00
|
|
|
const pastDate = new Date(differenceInMilliseconds(100000));
|
2020-01-03 04:07:33 -05:00
|
|
|
beforeEach(() => {
|
|
|
|
factory({
|
|
|
|
propsData: {
|
|
|
|
model: {
|
|
|
|
...environment,
|
|
|
|
auto_stop_at: pastDate,
|
|
|
|
},
|
|
|
|
tableData,
|
|
|
|
shouldShowAutoStopDate: true,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should not render a date', () => {
|
|
|
|
expect(findAutoStop().exists()).toBe(false);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should not render the suto-stop button', () => {
|
2021-08-04 02:09:49 -04:00
|
|
|
expect(wrapper.findComponent(PinComponent).exists()).toBe(false);
|
2020-01-03 04:07:33 -05:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2019-12-10 10:07:52 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
describe('With manual actions', () => {
|
2021-08-04 02:09:49 -04:00
|
|
|
let actions;
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
actions = wrapper.findComponent(ActionsComponent);
|
|
|
|
});
|
|
|
|
|
2019-12-10 10:07:52 -05:00
|
|
|
it('should render actions component', () => {
|
2021-08-04 02:09:49 -04:00
|
|
|
expect(actions.exists()).toBe(true);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should track clicks', () => {
|
|
|
|
actions.trigger('click');
|
|
|
|
expect(tracking).toHaveBeenCalledWith('_category_', 'click_dropdown', {
|
|
|
|
label: 'environment_actions',
|
|
|
|
});
|
2019-12-10 10:07:52 -05:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('With external URL', () => {
|
2021-08-04 02:09:49 -04:00
|
|
|
let externalUrl;
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
externalUrl = wrapper.findComponent(ExternalUrlComponent);
|
|
|
|
});
|
|
|
|
|
2019-12-10 10:07:52 -05:00
|
|
|
it('should render external url component', () => {
|
2021-08-04 02:09:49 -04:00
|
|
|
expect(externalUrl.exists()).toBe(true);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should track clicks', () => {
|
|
|
|
externalUrl.trigger('click');
|
|
|
|
expect(tracking).toHaveBeenCalledWith('_category_', 'click_button', {
|
|
|
|
label: 'environment_url',
|
|
|
|
});
|
2019-12-10 10:07:52 -05:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('With stop action', () => {
|
2021-08-04 02:09:49 -04:00
|
|
|
let stop;
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
stop = wrapper.findComponent(StopComponent);
|
|
|
|
});
|
|
|
|
|
2019-12-10 10:07:52 -05:00
|
|
|
it('should render stop action component', () => {
|
2021-08-04 02:09:49 -04:00
|
|
|
expect(stop.exists()).toBe(true);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should track clicks', () => {
|
|
|
|
stop.trigger('click');
|
|
|
|
expect(tracking).toHaveBeenCalledWith('_category_', 'click_button', {
|
|
|
|
label: 'environment_stop',
|
|
|
|
});
|
2019-12-10 10:07:52 -05:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('With retry action', () => {
|
2021-08-04 02:09:49 -04:00
|
|
|
let rollback;
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
rollback = wrapper.findComponent(RollbackComponent);
|
|
|
|
});
|
|
|
|
|
2019-12-10 10:07:52 -05:00
|
|
|
it('should render rollback component', () => {
|
2021-08-04 02:09:49 -04:00
|
|
|
expect(rollback.exists()).toBe(true);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should track clicks', () => {
|
|
|
|
rollback.trigger('click');
|
|
|
|
expect(tracking).toHaveBeenCalledWith('_category_', 'click_button', {
|
|
|
|
label: 'environment_rollback',
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('With terminal path', () => {
|
|
|
|
let terminal;
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
terminal = wrapper.findComponent(TerminalButtonComponent);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should render terminal action component', () => {
|
|
|
|
expect(terminal.exists()).toBe(true);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should track clicks', () => {
|
|
|
|
triggerEvent(terminal.element);
|
|
|
|
expect(tracking).toHaveBeenCalledWith('_category_', 'click_button', {
|
|
|
|
label: 'environment_terminal',
|
|
|
|
});
|
2019-12-10 10:07:52 -05:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('When item is folder', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
factory({
|
|
|
|
propsData: {
|
|
|
|
model: folder,
|
|
|
|
tableData,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
wrapper.destroy();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should render folder icon and name', () => {
|
|
|
|
expect(wrapper.find('.folder-name').text()).toContain(folder.name);
|
|
|
|
expect(wrapper.find('.folder-icon')).toBeDefined();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should render the number of children in a badge', () => {
|
2022-07-14 17:09:55 -04:00
|
|
|
expect(wrapper.find('.folder-name .badge').text()).toContain(folder.size.toString());
|
2019-12-10 10:07:52 -05:00
|
|
|
});
|
2020-12-09 10:10:12 -05:00
|
|
|
|
|
|
|
it('should not render the "Upcoming deployment" column', () => {
|
|
|
|
expect(findUpcomingDeployment().exists()).toBe(false);
|
|
|
|
});
|
2021-06-21 17:08:33 -04:00
|
|
|
|
|
|
|
it('should set the name cell to be full width', () => {
|
|
|
|
expect(wrapper.find('[data-testid="environment-name-cell"]').classes('section-100')).toBe(
|
|
|
|
true,
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should hide non-folder properties', () => {
|
2022-04-19 11:08:32 -04:00
|
|
|
expect(findLastDeployment().exists()).toBe(false);
|
2021-06-21 17:08:33 -04:00
|
|
|
expect(wrapper.find('[data-testid="environment-build-cell"]').exists()).toBe(false);
|
|
|
|
});
|
2019-12-10 10:07:52 -05:00
|
|
|
});
|
2020-03-25 05:08:11 -04:00
|
|
|
|
|
|
|
describe('When environment can be deleted', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
factory({
|
|
|
|
propsData: {
|
|
|
|
model: {
|
|
|
|
can_delete: true,
|
|
|
|
delete_path: 'http://0.0.0.0:3000/api/v4/projects/8/environments/45',
|
|
|
|
},
|
|
|
|
tableData,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should render the delete button', () => {
|
2021-08-04 02:09:49 -04:00
|
|
|
expect(wrapper.findComponent(DeleteComponent).exists()).toBe(true);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should trigger a tracking event', async () => {
|
|
|
|
tracking = mockTracking(undefined, wrapper.element, jest.spyOn);
|
|
|
|
|
|
|
|
await wrapper.findComponent(DeleteComponent).trigger('click');
|
|
|
|
|
|
|
|
expect(tracking).toHaveBeenCalledWith('_category_', 'click_button', {
|
|
|
|
label: 'environment_delete',
|
|
|
|
});
|
2020-03-25 05:08:11 -04:00
|
|
|
});
|
|
|
|
});
|
2019-12-10 10:07:52 -05:00
|
|
|
});
|