Skip to content

Commit f83fff0

Browse files
authored
[O2B-1152] Auto fill environments and lhcFills in log reply (#1434)
* [O2B-1152] Added logic for auto filling environments and lhcfills when replying to a log * [O2B-1152] Added test for auto filling environments and lhcfills when replying to a log * [O2B-1152] Small dockblock change * [O2B-1152] No export for getValue, also named more specific. * [O2B-1152] Small name fix
1 parent e222334 commit f83fff0

3 files changed

Lines changed: 39 additions & 3 deletions

File tree

lib/public/views/Logs/Create/LogReplyModel.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,13 @@ export class LogReplyModel extends LogCreationModel {
4545
}
4646

4747
/**
48-
* Inherit the title, tags and runs from the parent log
48+
* Inherit the title, tags, runs, environments and lhcFills from the parent log
4949
*
5050
* @param {Log} parentLog the parent log
5151
* @return {void}
5252
*/
5353
inheritFromParentLog(parentLog) {
54-
const { title, tags, runs } = parentLog;
54+
const { title, tags, runs, environments, lhcFills } = parentLog;
5555

5656
this.title = `${title}`;
5757

@@ -62,6 +62,14 @@ export class LogReplyModel extends LogCreationModel {
6262
if (!this.runNumbers) {
6363
this.runNumbers = runs.map(({ runNumber }) => runNumber).join(', ');
6464
}
65+
66+
if (!this.environments) {
67+
this.environments = environments.map(({ id }) => id).join(', ');
68+
}
69+
70+
if (!this.lhcFills) {
71+
this.lhcFills = lhcFills.map(({ fillNumber }) => fillNumber).join(', ');
72+
}
6573
}
6674

6775
/**

test/public/defaults.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -414,6 +414,26 @@ module.exports.fillInput = async (page, inputSelector, value, events = ['input']
414414
}, inputSelector, value, events);
415415
};
416416

417+
/**
418+
* Evaluate and return the value content of a given element handler
419+
* @param {{evaluate}} inputElementHandler the puppeteer handler of the element to inspect
420+
* @returns {Promise<XPathResult>} the html content
421+
*/
422+
const getInputValue = async (inputElementHandler) => await inputElementHandler.evaluate((input) => input.value);
423+
424+
/**
425+
* Expect an element to have a given value
426+
*
427+
* @param {Object} page Puppeteer page object.
428+
* @param {string} selector Css selector.
429+
* @param {string} value value to search for.
430+
* @return {Promise<void>} resolves once the value has been checked
431+
*/
432+
module.exports.expectInputValue = async (page, selector, value) => {
433+
await page.waitForSelector(selector, { timeout: 200 });
434+
expect(await getInputValue(await page.$(selector))).to.equal(value);
435+
};
436+
417437
/**
418438
* Check the differences between the provided expected parameters and the parameters actually received
419439
*

test/public/logs/create.test.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
*/
1313

1414
const chai = require('chai');
15-
const { defaultBefore, defaultAfter, goToPage } = require('../defaults');
15+
const { defaultBefore, defaultAfter, goToPage, expectInputValue } = require('../defaults');
1616
const path = require('path');
1717
const { GetAllLogsUseCase } = require('../../../lib/usecases/log/index.js');
1818
const { pressElement, expectInnerText, fillInput, checkMismatchingUrlParam, waitForTimeout, waitForNavigation } = require('../defaults.js');
@@ -107,6 +107,14 @@ module.exports = () => {
107107
expect(await checkMismatchingUrlParam(page, { ['log-details']: '1' }));
108108
});
109109

110+
it('Should successfully display the autofilled runs, environments and lhcFills when replying', async () => {
111+
await goToPage(page, 'log-reply&parentLogId=119');
112+
113+
await expectInputValue(page, 'input#run-numbers', '2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22');
114+
await expectInputValue(page, 'input#environments', 'Dxi029djX, eZF99lH6');
115+
await expectInputValue(page, 'input#lhc-fills', '1, 4, 6');
116+
});
117+
110118
it('can disable submit with invalid data', async () => {
111119
const invalidTitle = 'A';
112120
const validTitle = 'A valid title';

0 commit comments

Comments
 (0)