2018-11-20 20:47:30 +05:30
|
|
|
import * as types from '~/jobs/store/mutation_types';
|
2021-03-11 19:13:27 +05:30
|
|
|
import mutations from '~/jobs/store/mutations';
|
|
|
|
import state from '~/jobs/store/state';
|
2018-11-20 20:47:30 +05:30
|
|
|
|
|
|
|
describe('Jobs Store Mutations', () => {
|
|
|
|
let stateCopy;
|
2021-09-30 23:02:18 +05:30
|
|
|
let origGon;
|
2018-11-20 20:47:30 +05:30
|
|
|
|
|
|
|
const html =
|
|
|
|
'I, [2018-08-17T22:57:45.707325 #1841] INFO -- : Writing /builds/ab89e95b0fa0b9272ea0c797b76908f24d36992630e9325273a4ce3.png<br>I';
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
stateCopy = state();
|
2021-09-30 23:02:18 +05:30
|
|
|
|
|
|
|
origGon = window.gon;
|
|
|
|
|
|
|
|
window.gon = { features: { infinitelyCollapsibleSections: false } };
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
window.gon = origGon;
|
2018-11-20 20:47:30 +05:30
|
|
|
});
|
|
|
|
|
2018-12-05 23:21:45 +05:30
|
|
|
describe('SET_JOB_ENDPOINT', () => {
|
|
|
|
it('should set jobEndpoint', () => {
|
|
|
|
mutations[types.SET_JOB_ENDPOINT](stateCopy, 'job/21312321.json');
|
2018-12-13 13:39:08 +05:30
|
|
|
|
2018-12-05 23:21:45 +05:30
|
|
|
expect(stateCopy.jobEndpoint).toEqual('job/21312321.json');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2018-12-13 13:39:08 +05:30
|
|
|
describe('HIDE_SIDEBAR', () => {
|
|
|
|
it('should set isSidebarOpen to false', () => {
|
|
|
|
mutations[types.HIDE_SIDEBAR](stateCopy);
|
2018-11-20 20:47:30 +05:30
|
|
|
|
2018-12-13 13:39:08 +05:30
|
|
|
expect(stateCopy.isSidebarOpen).toEqual(false);
|
2018-11-20 20:47:30 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2018-12-13 13:39:08 +05:30
|
|
|
describe('SHOW_SIDEBAR', () => {
|
|
|
|
it('should set isSidebarOpen to true', () => {
|
|
|
|
mutations[types.SHOW_SIDEBAR](stateCopy);
|
|
|
|
|
|
|
|
expect(stateCopy.isSidebarOpen).toEqual(true);
|
2018-11-20 20:47:30 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2021-11-18 22:05:49 +05:30
|
|
|
describe('RECEIVE_JOB_LOG_SUCCESS', () => {
|
|
|
|
describe('when job log has state', () => {
|
|
|
|
it('sets jobLogState', () => {
|
2018-11-20 20:47:30 +05:30
|
|
|
const stateLog =
|
|
|
|
'eyJvZmZzZXQiOjczNDQ1MSwibl9vcGVuX3RhZ3MiOjAsImZnX2NvbG9yIjpudWxsLCJiZ19jb2xvciI6bnVsbCwic3R5bGVfbWFzayI6MH0=';
|
2021-11-18 22:05:49 +05:30
|
|
|
mutations[types.RECEIVE_JOB_LOG_SUCCESS](stateCopy, {
|
2018-11-20 20:47:30 +05:30
|
|
|
state: stateLog,
|
|
|
|
});
|
2018-12-13 13:39:08 +05:30
|
|
|
|
2021-11-18 22:05:49 +05:30
|
|
|
expect(stateCopy.jobLogState).toEqual(stateLog);
|
2018-11-20 20:47:30 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2021-11-18 22:05:49 +05:30
|
|
|
describe('when jobLogSize is smaller than the total size', () => {
|
|
|
|
it('sets isJobLogSizeVisible to true', () => {
|
|
|
|
mutations[types.RECEIVE_JOB_LOG_SUCCESS](stateCopy, { total: 51184600, size: 1231 });
|
2018-11-20 20:47:30 +05:30
|
|
|
|
2021-11-18 22:05:49 +05:30
|
|
|
expect(stateCopy.isJobLogSizeVisible).toEqual(true);
|
2018-11-20 20:47:30 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2021-11-18 22:05:49 +05:30
|
|
|
describe('when jobLogSize is bigger than the total size', () => {
|
|
|
|
it('sets isJobLogSizeVisible to false', () => {
|
|
|
|
const copy = { ...stateCopy, jobLogSize: 5118460, size: 2321312 };
|
2018-11-20 20:47:30 +05:30
|
|
|
|
2021-11-18 22:05:49 +05:30
|
|
|
mutations[types.RECEIVE_JOB_LOG_SUCCESS](copy, { total: 511846 });
|
2018-11-20 20:47:30 +05:30
|
|
|
|
2021-11-18 22:05:49 +05:30
|
|
|
expect(copy.isJobLogSizeVisible).toEqual(false);
|
2018-11-20 20:47:30 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2021-11-18 22:05:49 +05:30
|
|
|
it('sets job log size and isJobLogComplete', () => {
|
|
|
|
mutations[types.RECEIVE_JOB_LOG_SUCCESS](stateCopy, {
|
2018-11-20 20:47:30 +05:30
|
|
|
append: true,
|
|
|
|
html,
|
|
|
|
size: 511846,
|
|
|
|
complete: true,
|
2019-12-21 20:55:43 +05:30
|
|
|
lines: [],
|
2018-11-20 20:47:30 +05:30
|
|
|
});
|
2018-12-13 13:39:08 +05:30
|
|
|
|
2021-11-18 22:05:49 +05:30
|
|
|
expect(stateCopy.jobLogSize).toEqual(511846);
|
|
|
|
expect(stateCopy.isJobLogComplete).toEqual(true);
|
2018-11-20 20:47:30 +05:30
|
|
|
});
|
2019-12-21 20:55:43 +05:30
|
|
|
|
|
|
|
describe('with new job log', () => {
|
|
|
|
describe('log.lines', () => {
|
|
|
|
describe('when append is true', () => {
|
|
|
|
it('sets the parsed log ', () => {
|
2021-11-18 22:05:49 +05:30
|
|
|
mutations[types.RECEIVE_JOB_LOG_SUCCESS](stateCopy, {
|
2019-12-21 20:55:43 +05:30
|
|
|
append: true,
|
|
|
|
size: 511846,
|
|
|
|
complete: true,
|
|
|
|
lines: [
|
|
|
|
{
|
|
|
|
offset: 1,
|
|
|
|
content: [{ text: 'Running with gitlab-runner 11.12.1 (5a147c92)' }],
|
|
|
|
},
|
|
|
|
],
|
|
|
|
});
|
|
|
|
|
2021-11-18 22:05:49 +05:30
|
|
|
expect(stateCopy.jobLog).toEqual([
|
2019-12-21 20:55:43 +05:30
|
|
|
{
|
|
|
|
offset: 1,
|
|
|
|
content: [{ text: 'Running with gitlab-runner 11.12.1 (5a147c92)' }],
|
|
|
|
lineNumber: 0,
|
|
|
|
},
|
|
|
|
]);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('when it is defined', () => {
|
|
|
|
it('sets the parsed log ', () => {
|
2021-11-18 22:05:49 +05:30
|
|
|
mutations[types.RECEIVE_JOB_LOG_SUCCESS](stateCopy, {
|
2019-12-21 20:55:43 +05:30
|
|
|
append: false,
|
|
|
|
size: 511846,
|
|
|
|
complete: true,
|
|
|
|
lines: [
|
|
|
|
{ offset: 0, content: [{ text: 'Running with gitlab-runner 11.11.1 (5a147c92)' }] },
|
|
|
|
],
|
|
|
|
});
|
|
|
|
|
2021-11-18 22:05:49 +05:30
|
|
|
expect(stateCopy.jobLog).toEqual([
|
2019-12-21 20:55:43 +05:30
|
|
|
{
|
|
|
|
offset: 0,
|
|
|
|
content: [{ text: 'Running with gitlab-runner 11.11.1 (5a147c92)' }],
|
|
|
|
lineNumber: 0,
|
|
|
|
},
|
|
|
|
]);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('when it is null', () => {
|
|
|
|
it('sets the default value', () => {
|
2021-11-18 22:05:49 +05:30
|
|
|
mutations[types.RECEIVE_JOB_LOG_SUCCESS](stateCopy, {
|
2019-12-21 20:55:43 +05:30
|
|
|
append: true,
|
|
|
|
html,
|
|
|
|
size: 511846,
|
|
|
|
complete: false,
|
|
|
|
lines: null,
|
|
|
|
});
|
|
|
|
|
2021-11-18 22:05:49 +05:30
|
|
|
expect(stateCopy.jobLog).toEqual([]);
|
2019-12-21 20:55:43 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2018-11-20 20:47:30 +05:30
|
|
|
});
|
|
|
|
|
2021-11-18 22:05:49 +05:30
|
|
|
describe('SET_JOB_LOG_TIMEOUT', () => {
|
|
|
|
it('sets the jobLogTimeout id', () => {
|
2020-03-13 15:44:24 +05:30
|
|
|
const id = 7;
|
2018-12-13 13:39:08 +05:30
|
|
|
|
2021-11-18 22:05:49 +05:30
|
|
|
expect(stateCopy.jobLogTimeout).not.toEqual(id);
|
2020-03-13 15:44:24 +05:30
|
|
|
|
2021-11-18 22:05:49 +05:30
|
|
|
mutations[types.SET_JOB_LOG_TIMEOUT](stateCopy, id);
|
2020-03-13 15:44:24 +05:30
|
|
|
|
2021-11-18 22:05:49 +05:30
|
|
|
expect(stateCopy.jobLogTimeout).toEqual(id);
|
2018-11-20 20:47:30 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2021-11-18 22:05:49 +05:30
|
|
|
describe('STOP_POLLING_JOB_LOG', () => {
|
|
|
|
it('sets isJobLogComplete to true', () => {
|
|
|
|
mutations[types.STOP_POLLING_JOB_LOG](stateCopy);
|
2018-12-13 13:39:08 +05:30
|
|
|
|
2021-11-18 22:05:49 +05:30
|
|
|
expect(stateCopy.isJobLogComplete).toEqual(true);
|
2018-11-20 20:47:30 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2019-12-04 20:38:33 +05:30
|
|
|
describe('TOGGLE_COLLAPSIBLE_LINE', () => {
|
|
|
|
it('toggles the `isClosed` property of the provided object', () => {
|
|
|
|
const section = { isClosed: true };
|
|
|
|
mutations[types.TOGGLE_COLLAPSIBLE_LINE](stateCopy, section);
|
|
|
|
expect(section.isClosed).toEqual(false);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2018-11-20 20:47:30 +05:30
|
|
|
describe('REQUEST_JOB', () => {
|
|
|
|
it('sets isLoading to true', () => {
|
|
|
|
mutations[types.REQUEST_JOB](stateCopy);
|
|
|
|
|
|
|
|
expect(stateCopy.isLoading).toEqual(true);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('RECEIVE_JOB_SUCCESS', () => {
|
|
|
|
it('sets is loading to false', () => {
|
2018-12-05 23:21:45 +05:30
|
|
|
mutations[types.RECEIVE_JOB_SUCCESS](stateCopy, { id: 1312321 });
|
2018-12-13 13:39:08 +05:30
|
|
|
|
2018-11-20 20:47:30 +05:30
|
|
|
expect(stateCopy.isLoading).toEqual(false);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('sets hasError to false', () => {
|
2018-12-05 23:21:45 +05:30
|
|
|
mutations[types.RECEIVE_JOB_SUCCESS](stateCopy, { id: 1312321 });
|
2018-12-13 13:39:08 +05:30
|
|
|
|
2018-11-20 20:47:30 +05:30
|
|
|
expect(stateCopy.hasError).toEqual(false);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('sets job data', () => {
|
2018-12-05 23:21:45 +05:30
|
|
|
mutations[types.RECEIVE_JOB_SUCCESS](stateCopy, { id: 1312321 });
|
2018-12-13 13:39:08 +05:30
|
|
|
|
2018-11-20 20:47:30 +05:30
|
|
|
expect(stateCopy.job).toEqual({ id: 1312321 });
|
|
|
|
});
|
2018-12-05 23:21:45 +05:30
|
|
|
|
|
|
|
it('sets selectedStage when the selectedStage is empty', () => {
|
|
|
|
expect(stateCopy.selectedStage).toEqual('');
|
|
|
|
mutations[types.RECEIVE_JOB_SUCCESS](stateCopy, { id: 1312321, stage: 'deploy' });
|
2018-12-13 13:39:08 +05:30
|
|
|
|
2018-12-05 23:21:45 +05:30
|
|
|
expect(stateCopy.selectedStage).toEqual('deploy');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('does not set selectedStage when the selectedStage is not More', () => {
|
|
|
|
stateCopy.selectedStage = 'notify';
|
2018-12-13 13:39:08 +05:30
|
|
|
|
2018-12-05 23:21:45 +05:30
|
|
|
expect(stateCopy.selectedStage).toEqual('notify');
|
|
|
|
mutations[types.RECEIVE_JOB_SUCCESS](stateCopy, { id: 1312321, stage: 'deploy' });
|
2018-12-13 13:39:08 +05:30
|
|
|
|
2018-12-05 23:21:45 +05:30
|
|
|
expect(stateCopy.selectedStage).toEqual('notify');
|
|
|
|
});
|
2018-11-20 20:47:30 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
describe('RECEIVE_JOB_ERROR', () => {
|
|
|
|
it('resets job data', () => {
|
|
|
|
mutations[types.RECEIVE_JOB_ERROR](stateCopy);
|
|
|
|
|
|
|
|
expect(stateCopy.isLoading).toEqual(false);
|
|
|
|
expect(stateCopy.job).toEqual({});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('REQUEST_JOBS_FOR_STAGE', () => {
|
2019-09-04 21:01:54 +05:30
|
|
|
it('sets isLoadingJobs to true', () => {
|
2018-12-05 23:21:45 +05:30
|
|
|
mutations[types.REQUEST_JOBS_FOR_STAGE](stateCopy, { name: 'deploy' });
|
2018-12-13 13:39:08 +05:30
|
|
|
|
2018-11-20 20:47:30 +05:30
|
|
|
expect(stateCopy.isLoadingJobs).toEqual(true);
|
|
|
|
});
|
2018-12-05 23:21:45 +05:30
|
|
|
|
|
|
|
it('sets selectedStage', () => {
|
|
|
|
mutations[types.REQUEST_JOBS_FOR_STAGE](stateCopy, { name: 'deploy' });
|
2018-12-13 13:39:08 +05:30
|
|
|
|
2018-12-05 23:21:45 +05:30
|
|
|
expect(stateCopy.selectedStage).toEqual('deploy');
|
|
|
|
});
|
2018-11-20 20:47:30 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
describe('RECEIVE_JOBS_FOR_STAGE_SUCCESS', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
mutations[types.RECEIVE_JOBS_FOR_STAGE_SUCCESS](stateCopy, [{ name: 'karma' }]);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('sets isLoadingJobs to false', () => {
|
|
|
|
expect(stateCopy.isLoadingJobs).toEqual(false);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('sets jobs', () => {
|
|
|
|
expect(stateCopy.jobs).toEqual([{ name: 'karma' }]);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('RECEIVE_JOBS_FOR_STAGE_ERROR', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
mutations[types.RECEIVE_JOBS_FOR_STAGE_ERROR](stateCopy);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('sets isLoadingJobs to false', () => {
|
|
|
|
expect(stateCopy.isLoadingJobs).toEqual(false);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('resets jobs', () => {
|
|
|
|
expect(stateCopy.jobs).toEqual([]);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2021-09-30 23:02:18 +05:30
|
|
|
|
|
|
|
describe('Job Store mutations, feature flag ON', () => {
|
|
|
|
let stateCopy;
|
|
|
|
let origGon;
|
|
|
|
|
|
|
|
const html =
|
|
|
|
'I, [2018-08-17T22:57:45.707325 #1841] INFO -- : Writing /builds/ab89e95b0fa0b9272ea0c797b76908f24d36992630e9325273a4ce3.png<br>I';
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
stateCopy = state();
|
|
|
|
|
|
|
|
origGon = window.gon;
|
|
|
|
|
|
|
|
window.gon = { features: { infinitelyCollapsibleSections: true } };
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
window.gon = origGon;
|
|
|
|
});
|
|
|
|
|
2021-11-18 22:05:49 +05:30
|
|
|
describe('RECEIVE_JOB_LOG_SUCCESS', () => {
|
2021-09-30 23:02:18 +05:30
|
|
|
describe('with new job log', () => {
|
|
|
|
describe('log.lines', () => {
|
|
|
|
describe('when append is true', () => {
|
|
|
|
it('sets the parsed log ', () => {
|
2021-11-18 22:05:49 +05:30
|
|
|
mutations[types.RECEIVE_JOB_LOG_SUCCESS](stateCopy, {
|
2021-09-30 23:02:18 +05:30
|
|
|
append: true,
|
|
|
|
size: 511846,
|
|
|
|
complete: true,
|
|
|
|
lines: [
|
|
|
|
{
|
|
|
|
offset: 1,
|
|
|
|
content: [{ text: 'Running with gitlab-runner 11.12.1 (5a147c92)' }],
|
|
|
|
},
|
|
|
|
],
|
|
|
|
});
|
|
|
|
|
2021-11-18 22:05:49 +05:30
|
|
|
expect(stateCopy.jobLog).toEqual([
|
2021-09-30 23:02:18 +05:30
|
|
|
{
|
|
|
|
offset: 1,
|
|
|
|
content: [{ text: 'Running with gitlab-runner 11.12.1 (5a147c92)' }],
|
|
|
|
lineNumber: 1,
|
|
|
|
},
|
|
|
|
]);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('when lines are defined', () => {
|
|
|
|
it('sets the parsed log ', () => {
|
2021-11-18 22:05:49 +05:30
|
|
|
mutations[types.RECEIVE_JOB_LOG_SUCCESS](stateCopy, {
|
2021-09-30 23:02:18 +05:30
|
|
|
append: false,
|
|
|
|
size: 511846,
|
|
|
|
complete: true,
|
|
|
|
lines: [
|
|
|
|
{ offset: 0, content: [{ text: 'Running with gitlab-runner 11.11.1 (5a147c92)' }] },
|
|
|
|
],
|
|
|
|
});
|
|
|
|
|
2021-11-18 22:05:49 +05:30
|
|
|
expect(stateCopy.jobLog).toEqual([
|
2021-09-30 23:02:18 +05:30
|
|
|
{
|
|
|
|
offset: 0,
|
|
|
|
content: [{ text: 'Running with gitlab-runner 11.11.1 (5a147c92)' }],
|
|
|
|
lineNumber: 1,
|
|
|
|
},
|
|
|
|
]);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('when lines are null', () => {
|
|
|
|
it('sets the default value', () => {
|
2021-11-18 22:05:49 +05:30
|
|
|
mutations[types.RECEIVE_JOB_LOG_SUCCESS](stateCopy, {
|
2021-09-30 23:02:18 +05:30
|
|
|
append: true,
|
|
|
|
html,
|
|
|
|
size: 511846,
|
|
|
|
complete: false,
|
|
|
|
lines: null,
|
|
|
|
});
|
|
|
|
|
2021-11-18 22:05:49 +05:30
|
|
|
expect(stateCopy.jobLog).toEqual([]);
|
2021-09-30 23:02:18 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|