2018-10-03 11:29:07 -04:00
|
|
|
import * as getters from '~/jobs/store/getters';
|
|
|
|
import state from '~/jobs/store/state';
|
|
|
|
|
|
|
|
describe('Job Store Getters', () => {
|
|
|
|
let localState;
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
localState = state();
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('headerTime', () => {
|
|
|
|
describe('when the job has started key', () => {
|
|
|
|
it('returns started key', () => {
|
|
|
|
const started = '2018-08-31T16:20:49.023Z';
|
|
|
|
localState.job.started = started;
|
|
|
|
|
|
|
|
expect(getters.headerTime(localState)).toEqual(started);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('when the job does not have started key', () => {
|
|
|
|
it('returns created_at key', () => {
|
|
|
|
const created = '2018-08-31T16:20:49.023Z';
|
|
|
|
localState.job.created_at = created;
|
2018-10-09 14:03:09 -04:00
|
|
|
|
2018-10-03 11:29:07 -04:00
|
|
|
expect(getters.headerTime(localState)).toEqual(created);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('shouldRenderCalloutMessage', () => {
|
|
|
|
describe('with status and callout message', () => {
|
|
|
|
it('returns true', () => {
|
|
|
|
localState.job.callout_message = 'Callout message';
|
|
|
|
localState.job.status = { icon: 'passed' };
|
|
|
|
|
|
|
|
expect(getters.shouldRenderCalloutMessage(localState)).toEqual(true);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('without status & with callout message', () => {
|
|
|
|
it('returns false', () => {
|
|
|
|
localState.job.callout_message = 'Callout message';
|
2018-10-09 14:03:09 -04:00
|
|
|
|
2018-10-03 11:29:07 -04:00
|
|
|
expect(getters.shouldRenderCalloutMessage(localState)).toEqual(false);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('with status & without callout message', () => {
|
|
|
|
it('returns false', () => {
|
|
|
|
localState.job.status = { icon: 'passed' };
|
|
|
|
|
|
|
|
expect(getters.shouldRenderCalloutMessage(localState)).toEqual(false);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2018-10-12 11:26:04 -04:00
|
|
|
describe('shouldRenderTriggeredLabel', () => {
|
|
|
|
describe('when started equals null', () => {
|
2018-10-03 11:29:07 -04:00
|
|
|
it('returns false', () => {
|
2018-10-12 11:26:04 -04:00
|
|
|
localState.job.started = null;
|
2018-10-09 14:03:09 -04:00
|
|
|
|
2018-10-12 11:26:04 -04:00
|
|
|
expect(getters.shouldRenderTriggeredLabel(localState)).toEqual(false);
|
2018-10-03 11:29:07 -04:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('when started equals string', () => {
|
|
|
|
it('returns true', () => {
|
|
|
|
localState.job.started = '2018-08-31T16:20:49.023Z';
|
2018-10-09 14:03:09 -04:00
|
|
|
|
2018-10-12 11:26:04 -04:00
|
|
|
expect(getters.shouldRenderTriggeredLabel(localState)).toEqual(true);
|
2018-10-03 11:29:07 -04:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('hasEnvironment', () => {
|
|
|
|
describe('without `deployment_status`', () => {
|
|
|
|
it('returns false', () => {
|
|
|
|
expect(getters.hasEnvironment(localState)).toEqual(false);
|
|
|
|
});
|
|
|
|
});
|
2018-10-04 08:59:57 -04:00
|
|
|
|
2018-10-03 11:29:07 -04:00
|
|
|
describe('with an empty object for `deployment_status`', () => {
|
|
|
|
it('returns false', () => {
|
|
|
|
localState.job.deployment_status = {};
|
2018-10-09 14:03:09 -04:00
|
|
|
|
2018-10-03 11:29:07 -04:00
|
|
|
expect(getters.hasEnvironment(localState)).toEqual(false);
|
|
|
|
});
|
|
|
|
});
|
2018-10-04 08:59:57 -04:00
|
|
|
|
2018-10-03 11:29:07 -04:00
|
|
|
describe('when `deployment_status` is defined and not empty', () => {
|
|
|
|
it('returns true', () => {
|
|
|
|
localState.job.deployment_status = {
|
|
|
|
status: 'creating',
|
|
|
|
environment: {
|
|
|
|
last_deployment: {},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
expect(getters.hasEnvironment(localState)).toEqual(true);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2018-10-04 08:59:57 -04:00
|
|
|
|
|
|
|
describe('hasTrace', () => {
|
|
|
|
describe('when has_trace is true', () => {
|
|
|
|
it('returns true', () => {
|
|
|
|
localState.job.has_trace = true;
|
|
|
|
localState.job.status = {};
|
|
|
|
|
|
|
|
expect(getters.hasTrace(localState)).toEqual(true);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('when job is running', () => {
|
|
|
|
it('returns true', () => {
|
|
|
|
localState.job.has_trace = false;
|
|
|
|
localState.job.status = { group: 'running' };
|
|
|
|
|
|
|
|
expect(getters.hasTrace(localState)).toEqual(true);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('when has_trace is false and job is not running', () => {
|
|
|
|
it('returns false', () => {
|
|
|
|
localState.job.has_trace = false;
|
|
|
|
localState.job.status = { group: 'pending' };
|
|
|
|
|
|
|
|
expect(getters.hasTrace(localState)).toEqual(false);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('emptyStateIllustration', () => {
|
|
|
|
describe('with defined illustration', () => {
|
|
|
|
it('returns the state illustration object', () => {
|
|
|
|
localState.job.status = {
|
|
|
|
illustration: {
|
|
|
|
path: 'foo',
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
expect(getters.emptyStateIllustration(localState)).toEqual({ path: 'foo' });
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('when illustration is not defined', () => {
|
|
|
|
it('returns an empty object', () => {
|
|
|
|
expect(getters.emptyStateIllustration(localState)).toEqual({});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2019-03-07 04:50:36 -05:00
|
|
|
describe('shouldRenderSharedRunnerLimitWarning', () => {
|
|
|
|
describe('without runners information', () => {
|
|
|
|
it('returns false', () => {
|
|
|
|
expect(getters.shouldRenderSharedRunnerLimitWarning(localState)).toEqual(false);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('with runners information', () => {
|
|
|
|
describe('when used quota is less than limit', () => {
|
|
|
|
it('returns false', () => {
|
|
|
|
localState.job.runners = {
|
|
|
|
quota: {
|
|
|
|
used: 33,
|
|
|
|
limit: 2000,
|
|
|
|
},
|
|
|
|
available: true,
|
|
|
|
online: true,
|
|
|
|
};
|
|
|
|
|
|
|
|
expect(getters.shouldRenderSharedRunnerLimitWarning(localState)).toEqual(false);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('when used quota is equal to limit', () => {
|
|
|
|
it('returns true', () => {
|
|
|
|
localState.job.runners = {
|
|
|
|
quota: {
|
|
|
|
used: 2000,
|
|
|
|
limit: 2000,
|
|
|
|
},
|
|
|
|
available: true,
|
|
|
|
online: true,
|
|
|
|
};
|
|
|
|
|
|
|
|
expect(getters.shouldRenderSharedRunnerLimitWarning(localState)).toEqual(true);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('when used quota is bigger than limit', () => {
|
|
|
|
it('returns true', () => {
|
|
|
|
localState.job.runners = {
|
|
|
|
quota: {
|
|
|
|
used: 2002,
|
|
|
|
limit: 2000,
|
|
|
|
},
|
|
|
|
available: true,
|
|
|
|
online: true,
|
|
|
|
};
|
|
|
|
|
|
|
|
expect(getters.shouldRenderSharedRunnerLimitWarning(localState)).toEqual(true);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2018-10-25 07:53:00 -04:00
|
|
|
describe('hasRunnersForProject', () => {
|
|
|
|
describe('with available and offline runners', () => {
|
2018-10-04 08:59:57 -04:00
|
|
|
it('returns true', () => {
|
|
|
|
localState.job.runners = {
|
2018-10-25 07:53:00 -04:00
|
|
|
available: true,
|
2018-10-30 16:28:31 -04:00
|
|
|
online: false,
|
2018-10-04 08:59:57 -04:00
|
|
|
};
|
|
|
|
|
2018-10-25 07:53:00 -04:00
|
|
|
expect(getters.hasRunnersForProject(localState)).toEqual(true);
|
2018-10-04 08:59:57 -04:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2018-10-25 07:53:00 -04:00
|
|
|
describe('with non available runners', () => {
|
2018-10-04 08:59:57 -04:00
|
|
|
it('returns false', () => {
|
|
|
|
localState.job.runners = {
|
|
|
|
available: false,
|
2018-10-30 16:28:31 -04:00
|
|
|
online: false,
|
2018-10-04 08:59:57 -04:00
|
|
|
};
|
|
|
|
|
2018-10-25 07:53:00 -04:00
|
|
|
expect(getters.hasRunnersForProject(localState)).toEqual(false);
|
2018-10-04 08:59:57 -04:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2018-10-25 07:53:00 -04:00
|
|
|
describe('with online runners', () => {
|
2018-10-04 08:59:57 -04:00
|
|
|
it('returns false', () => {
|
|
|
|
localState.job.runners = {
|
2018-10-25 07:53:00 -04:00
|
|
|
available: false,
|
2018-10-30 16:28:31 -04:00
|
|
|
online: true,
|
2018-10-04 08:59:57 -04:00
|
|
|
};
|
|
|
|
|
2018-10-25 07:53:00 -04:00
|
|
|
expect(getters.hasRunnersForProject(localState)).toEqual(false);
|
2018-10-04 08:59:57 -04:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2018-10-03 11:29:07 -04:00
|
|
|
});
|