debian-mirror-gitlab/spec/javascripts/clusters/components/application_row_spec.js

407 lines
14 KiB
JavaScript
Raw Normal View History

2018-03-17 18:26:18 +05:30
import Vue from 'vue';
import eventHub from '~/clusters/event_hub';
2019-03-02 22:35:43 +05:30
import { APPLICATION_STATUS, REQUEST_SUBMITTED, REQUEST_FAILURE } from '~/clusters/constants';
2018-03-17 18:26:18 +05:30
import applicationRow from '~/clusters/components/application_row.vue';
2019-05-30 16:15:17 +05:30
import mountComponent from 'spec/helpers/vue_mount_component_helper';
2018-03-17 18:26:18 +05:30
import { DEFAULT_APPLICATION_STATE } from '../services/mock_data';
describe('Application Row', () => {
let vm;
let ApplicationRow;
beforeEach(() => {
ApplicationRow = Vue.extend(applicationRow);
});
afterEach(() => {
vm.$destroy();
});
describe('Title', () => {
it('shows title', () => {
vm = mountComponent(ApplicationRow, {
...DEFAULT_APPLICATION_STATE,
titleLink: null,
});
const title = vm.$el.querySelector('.js-cluster-application-title');
expect(title.tagName).toEqual('SPAN');
expect(title.textContent.trim()).toEqual(DEFAULT_APPLICATION_STATE.title);
});
it('shows title link', () => {
expect(DEFAULT_APPLICATION_STATE.titleLink).toBeDefined();
vm = mountComponent(ApplicationRow, {
...DEFAULT_APPLICATION_STATE,
});
const title = vm.$el.querySelector('.js-cluster-application-title');
expect(title.tagName).toEqual('A');
expect(title.textContent.trim()).toEqual(DEFAULT_APPLICATION_STATE.title);
});
});
describe('Install button', () => {
it('has indeterminate state on page load', () => {
vm = mountComponent(ApplicationRow, {
...DEFAULT_APPLICATION_STATE,
status: null,
});
expect(vm.installButtonLabel).toBeUndefined();
});
2019-03-02 22:35:43 +05:30
it('has install button', () => {
const installationBtn = vm.$el.querySelector('.js-cluster-application-install-button');
expect(installationBtn).not.toBe(null);
});
2018-11-18 11:00:15 +05:30
it('has disabled "Install" when APPLICATION_STATUS.NOT_INSTALLABLE', () => {
2018-03-17 18:26:18 +05:30
vm = mountComponent(ApplicationRow, {
...DEFAULT_APPLICATION_STATE,
2018-11-18 11:00:15 +05:30
status: APPLICATION_STATUS.NOT_INSTALLABLE,
2018-03-17 18:26:18 +05:30
});
expect(vm.installButtonLabel).toEqual('Install');
expect(vm.installButtonLoading).toEqual(false);
expect(vm.installButtonDisabled).toEqual(true);
});
2018-11-18 11:00:15 +05:30
it('has enabled "Install" when APPLICATION_STATUS.INSTALLABLE', () => {
2018-03-17 18:26:18 +05:30
vm = mountComponent(ApplicationRow, {
...DEFAULT_APPLICATION_STATE,
2018-11-18 11:00:15 +05:30
status: APPLICATION_STATUS.INSTALLABLE,
2018-03-17 18:26:18 +05:30
});
expect(vm.installButtonLabel).toEqual('Install');
expect(vm.installButtonLoading).toEqual(false);
expect(vm.installButtonDisabled).toEqual(false);
});
2018-11-18 11:00:15 +05:30
it('has loading "Installing" when APPLICATION_STATUS.SCHEDULED', () => {
2018-03-17 18:26:18 +05:30
vm = mountComponent(ApplicationRow, {
...DEFAULT_APPLICATION_STATE,
2018-11-18 11:00:15 +05:30
status: APPLICATION_STATUS.SCHEDULED,
2018-03-17 18:26:18 +05:30
});
expect(vm.installButtonLabel).toEqual('Installing');
expect(vm.installButtonLoading).toEqual(true);
expect(vm.installButtonDisabled).toEqual(true);
});
2018-11-18 11:00:15 +05:30
it('has loading "Installing" when APPLICATION_STATUS.INSTALLING', () => {
2018-03-17 18:26:18 +05:30
vm = mountComponent(ApplicationRow, {
...DEFAULT_APPLICATION_STATE,
2018-11-18 11:00:15 +05:30
status: APPLICATION_STATUS.INSTALLING,
2018-03-17 18:26:18 +05:30
});
expect(vm.installButtonLabel).toEqual('Installing');
expect(vm.installButtonLoading).toEqual(true);
expect(vm.installButtonDisabled).toEqual(true);
});
2019-03-02 22:35:43 +05:30
it('has loading "Installing" when REQUEST_SUBMITTED', () => {
vm = mountComponent(ApplicationRow, {
...DEFAULT_APPLICATION_STATE,
status: APPLICATION_STATUS.INSTALLABLE,
requestStatus: REQUEST_SUBMITTED,
});
expect(vm.installButtonLabel).toEqual('Installing');
expect(vm.installButtonLoading).toEqual(true);
expect(vm.installButtonDisabled).toEqual(true);
});
2018-11-18 11:00:15 +05:30
it('has disabled "Installed" when APPLICATION_STATUS.INSTALLED', () => {
2018-03-17 18:26:18 +05:30
vm = mountComponent(ApplicationRow, {
...DEFAULT_APPLICATION_STATE,
2018-11-18 11:00:15 +05:30
status: APPLICATION_STATUS.INSTALLED,
2018-03-17 18:26:18 +05:30
});
expect(vm.installButtonLabel).toEqual('Installed');
expect(vm.installButtonLoading).toEqual(false);
expect(vm.installButtonDisabled).toEqual(true);
});
2018-12-13 13:39:08 +05:30
it('has disabled "Installed" when APPLICATION_STATUS.UPDATING', () => {
vm = mountComponent(ApplicationRow, {
...DEFAULT_APPLICATION_STATE,
status: APPLICATION_STATUS.UPDATING,
});
expect(vm.installButtonLabel).toEqual('Installed');
expect(vm.installButtonLoading).toEqual(false);
expect(vm.installButtonDisabled).toEqual(true);
});
2018-11-18 11:00:15 +05:30
it('has enabled "Install" when APPLICATION_STATUS.ERROR', () => {
2018-03-17 18:26:18 +05:30
vm = mountComponent(ApplicationRow, {
...DEFAULT_APPLICATION_STATE,
2018-11-18 11:00:15 +05:30
status: APPLICATION_STATUS.ERROR,
2018-03-17 18:26:18 +05:30
});
expect(vm.installButtonLabel).toEqual('Install');
expect(vm.installButtonLoading).toEqual(false);
expect(vm.installButtonDisabled).toEqual(false);
});
it('has enabled "Install" when REQUEST_FAILURE (so you can try installing again)', () => {
vm = mountComponent(ApplicationRow, {
...DEFAULT_APPLICATION_STATE,
2018-11-18 11:00:15 +05:30
status: APPLICATION_STATUS.INSTALLABLE,
2018-03-17 18:26:18 +05:30
requestStatus: REQUEST_FAILURE,
});
expect(vm.installButtonLabel).toEqual('Install');
expect(vm.installButtonLoading).toEqual(false);
expect(vm.installButtonDisabled).toEqual(false);
});
it('clicking install button emits event', () => {
2019-05-30 16:15:17 +05:30
spyOn(eventHub, '$emit');
2018-03-17 18:26:18 +05:30
vm = mountComponent(ApplicationRow, {
...DEFAULT_APPLICATION_STATE,
2018-11-18 11:00:15 +05:30
status: APPLICATION_STATUS.INSTALLABLE,
2018-03-17 18:26:18 +05:30
});
const installButton = vm.$el.querySelector('.js-cluster-application-install-button');
installButton.click();
2018-11-08 19:23:39 +05:30
expect(eventHub.$emit).toHaveBeenCalledWith('installApplication', {
id: DEFAULT_APPLICATION_STATE.id,
params: {},
});
});
it('clicking install button when installApplicationRequestParams are provided emits event', () => {
2019-05-30 16:15:17 +05:30
spyOn(eventHub, '$emit');
2018-11-08 19:23:39 +05:30
vm = mountComponent(ApplicationRow, {
...DEFAULT_APPLICATION_STATE,
2018-11-18 11:00:15 +05:30
status: APPLICATION_STATUS.INSTALLABLE,
2018-11-08 19:23:39 +05:30
installApplicationRequestParams: { hostname: 'jupyter' },
});
const installButton = vm.$el.querySelector('.js-cluster-application-install-button');
installButton.click();
expect(eventHub.$emit).toHaveBeenCalledWith('installApplication', {
id: DEFAULT_APPLICATION_STATE.id,
params: { hostname: 'jupyter' },
});
2018-03-17 18:26:18 +05:30
});
it('clicking disabled install button emits nothing', () => {
2019-05-30 16:15:17 +05:30
spyOn(eventHub, '$emit');
2018-03-17 18:26:18 +05:30
vm = mountComponent(ApplicationRow, {
...DEFAULT_APPLICATION_STATE,
2018-11-18 11:00:15 +05:30
status: APPLICATION_STATUS.INSTALLING,
2018-03-17 18:26:18 +05:30
});
const installButton = vm.$el.querySelector('.js-cluster-application-install-button');
expect(vm.installButtonDisabled).toEqual(true);
installButton.click();
expect(eventHub.$emit).not.toHaveBeenCalled();
});
});
2019-03-02 22:35:43 +05:30
describe('Upgrade button', () => {
it('has indeterminate state on page load', () => {
vm = mountComponent(ApplicationRow, {
...DEFAULT_APPLICATION_STATE,
status: null,
});
const upgradeBtn = vm.$el.querySelector('.js-cluster-application-upgrade-button');
expect(upgradeBtn).toBe(null);
});
it('has enabled "Upgrade" when "upgradeAvailable" is true', () => {
vm = mountComponent(ApplicationRow, {
...DEFAULT_APPLICATION_STATE,
upgradeAvailable: true,
});
const upgradeBtn = vm.$el.querySelector('.js-cluster-application-upgrade-button');
expect(upgradeBtn).not.toBe(null);
expect(upgradeBtn.innerHTML).toContain('Upgrade');
});
2019-05-30 16:15:17 +05:30
it('has enabled "Retry upgrade" when APPLICATION_STATUS.UPDATE_ERRORED', () => {
2019-03-02 22:35:43 +05:30
vm = mountComponent(ApplicationRow, {
...DEFAULT_APPLICATION_STATE,
status: APPLICATION_STATUS.UPDATE_ERRORED,
});
const upgradeBtn = vm.$el.querySelector('.js-cluster-application-upgrade-button');
expect(upgradeBtn).not.toBe(null);
expect(vm.upgradeFailed).toBe(true);
2019-05-30 16:15:17 +05:30
expect(upgradeBtn.innerHTML).toContain('Retry upgrade');
2019-03-02 22:35:43 +05:30
});
2019-05-30 16:15:17 +05:30
it('has disabled "Retry upgrade" when APPLICATION_STATUS.UPDATING', () => {
2019-03-02 22:35:43 +05:30
vm = mountComponent(ApplicationRow, {
...DEFAULT_APPLICATION_STATE,
status: APPLICATION_STATUS.UPDATING,
});
const upgradeBtn = vm.$el.querySelector('.js-cluster-application-upgrade-button');
expect(upgradeBtn).not.toBe(null);
expect(vm.isUpgrading).toBe(true);
2019-05-30 16:15:17 +05:30
expect(upgradeBtn.innerHTML).toContain('Upgrading');
2019-03-02 22:35:43 +05:30
});
it('clicking upgrade button emits event', () => {
2019-05-30 16:15:17 +05:30
spyOn(eventHub, '$emit');
2019-03-02 22:35:43 +05:30
vm = mountComponent(ApplicationRow, {
...DEFAULT_APPLICATION_STATE,
status: APPLICATION_STATUS.UPDATE_ERRORED,
});
const upgradeBtn = vm.$el.querySelector('.js-cluster-application-upgrade-button');
upgradeBtn.click();
expect(eventHub.$emit).toHaveBeenCalledWith('upgradeApplication', {
id: DEFAULT_APPLICATION_STATE.id,
params: {},
});
});
it('clicking disabled upgrade button emits nothing', () => {
2019-05-30 16:15:17 +05:30
spyOn(eventHub, '$emit');
2019-03-02 22:35:43 +05:30
vm = mountComponent(ApplicationRow, {
...DEFAULT_APPLICATION_STATE,
status: APPLICATION_STATUS.UPDATING,
});
const upgradeBtn = vm.$el.querySelector('.js-cluster-application-upgrade-button');
upgradeBtn.click();
expect(eventHub.$emit).not.toHaveBeenCalled();
});
it('displays an error message if application upgrade failed', () => {
vm = mountComponent(ApplicationRow, {
...DEFAULT_APPLICATION_STATE,
title: 'GitLab Runner',
status: APPLICATION_STATUS.UPDATE_ERRORED,
});
const failureMessage = vm.$el.querySelector(
'.js-cluster-application-upgrade-failure-message',
);
expect(failureMessage).not.toBe(null);
expect(failureMessage.innerHTML).toContain(
2019-05-30 16:15:17 +05:30
'Something went wrong when upgrading GitLab Runner. Please check the logs and try again.',
2019-03-02 22:35:43 +05:30
);
});
});
describe('Version', () => {
it('displays a version number if application has been upgraded', () => {
const version = '0.1.45';
vm = mountComponent(ApplicationRow, {
...DEFAULT_APPLICATION_STATE,
status: APPLICATION_STATUS.UPDATED,
version,
});
const upgradeDetails = vm.$el.querySelector('.js-cluster-application-upgrade-details');
const versionEl = vm.$el.querySelector('.js-cluster-application-upgrade-version');
expect(upgradeDetails.innerHTML).toContain('Upgraded');
expect(versionEl).not.toBe(null);
expect(versionEl.innerHTML).toContain(version);
});
it('contains a link to the chart repo if application has been upgraded', () => {
const version = '0.1.45';
const chartRepo = 'https://gitlab.com/charts/gitlab-runner';
vm = mountComponent(ApplicationRow, {
...DEFAULT_APPLICATION_STATE,
status: APPLICATION_STATUS.UPDATED,
chartRepo,
version,
});
const versionEl = vm.$el.querySelector('.js-cluster-application-upgrade-version');
expect(versionEl.href).toEqual(chartRepo);
expect(versionEl.target).toEqual('_blank');
});
it('does not display a version number if application upgrade failed', () => {
const version = '0.1.45';
vm = mountComponent(ApplicationRow, {
...DEFAULT_APPLICATION_STATE,
status: APPLICATION_STATUS.UPDATE_ERRORED,
version,
});
const upgradeDetails = vm.$el.querySelector('.js-cluster-application-upgrade-details');
const versionEl = vm.$el.querySelector('.js-cluster-application-upgrade-version');
expect(upgradeDetails.innerHTML).toContain('failed');
expect(versionEl).toBe(null);
});
});
2018-03-17 18:26:18 +05:30
describe('Error block', () => {
it('does not show error block when there is no error', () => {
vm = mountComponent(ApplicationRow, {
...DEFAULT_APPLICATION_STATE,
status: null,
requestStatus: null,
});
2018-12-13 13:39:08 +05:30
const generalErrorMessage = vm.$el.querySelector(
'.js-cluster-application-general-error-message',
);
2018-03-17 18:26:18 +05:30
expect(generalErrorMessage).toBeNull();
});
2018-11-18 11:00:15 +05:30
it('shows status reason when APPLICATION_STATUS.ERROR', () => {
2018-03-17 18:26:18 +05:30
const statusReason = 'We broke it 0.0';
vm = mountComponent(ApplicationRow, {
...DEFAULT_APPLICATION_STATE,
2018-11-18 11:00:15 +05:30
status: APPLICATION_STATUS.ERROR,
2018-03-17 18:26:18 +05:30
statusReason,
});
2018-12-13 13:39:08 +05:30
const generalErrorMessage = vm.$el.querySelector(
'.js-cluster-application-general-error-message',
);
const statusErrorMessage = vm.$el.querySelector(
'.js-cluster-application-status-error-message',
);
expect(generalErrorMessage.textContent.trim()).toEqual(
`Something went wrong while installing ${DEFAULT_APPLICATION_STATE.title}`,
);
2018-03-17 18:26:18 +05:30
expect(statusErrorMessage.textContent.trim()).toEqual(statusReason);
});
it('shows request reason when REQUEST_FAILURE', () => {
const requestReason = 'We broke thre request 0.0';
vm = mountComponent(ApplicationRow, {
...DEFAULT_APPLICATION_STATE,
2018-11-18 11:00:15 +05:30
status: APPLICATION_STATUS.INSTALLABLE,
2018-03-17 18:26:18 +05:30
requestStatus: REQUEST_FAILURE,
requestReason,
});
2018-12-13 13:39:08 +05:30
const generalErrorMessage = vm.$el.querySelector(
'.js-cluster-application-general-error-message',
);
const requestErrorMessage = vm.$el.querySelector(
'.js-cluster-application-request-error-message',
);
expect(generalErrorMessage.textContent.trim()).toEqual(
`Something went wrong while installing ${DEFAULT_APPLICATION_STATE.title}`,
);
2018-03-17 18:26:18 +05:30
expect(requestErrorMessage.textContent.trim()).toEqual(requestReason);
});
});
});