Skip to content

Commit

Permalink
[O2B-1152] Auto fill environments and lhcFills in log reply (#1434)
Browse files Browse the repository at this point in the history
* [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
  • Loading branch information
AnoeBanoe authored Mar 1, 2024
1 parent e222334 commit f83fff0
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 3 deletions.
12 changes: 10 additions & 2 deletions lib/public/views/Logs/Create/LogReplyModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,13 @@ export class LogReplyModel extends LogCreationModel {
}

/**
* Inherit the title, tags and runs from the parent log
* Inherit the title, tags, runs, environments and lhcFills from the parent log
*
* @param {Log} parentLog the parent log
* @return {void}
*/
inheritFromParentLog(parentLog) {
const { title, tags, runs } = parentLog;
const { title, tags, runs, environments, lhcFills } = parentLog;

this.title = `${title}`;

Expand All @@ -62,6 +62,14 @@ export class LogReplyModel extends LogCreationModel {
if (!this.runNumbers) {
this.runNumbers = runs.map(({ runNumber }) => runNumber).join(', ');
}

if (!this.environments) {
this.environments = environments.map(({ id }) => id).join(', ');
}

if (!this.lhcFills) {
this.lhcFills = lhcFills.map(({ fillNumber }) => fillNumber).join(', ');
}
}

/**
Expand Down
20 changes: 20 additions & 0 deletions test/public/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,26 @@ module.exports.fillInput = async (page, inputSelector, value, events = ['input']
}, inputSelector, value, events);
};

/**
* Evaluate and return the value content of a given element handler
* @param {{evaluate}} inputElementHandler the puppeteer handler of the element to inspect
* @returns {Promise<XPathResult>} the html content
*/
const getInputValue = async (inputElementHandler) => await inputElementHandler.evaluate((input) => input.value);

/**
* Expect an element to have a given value
*
* @param {Object} page Puppeteer page object.
* @param {string} selector Css selector.
* @param {string} value value to search for.
* @return {Promise<void>} resolves once the value has been checked
*/
module.exports.expectInputValue = async (page, selector, value) => {
await page.waitForSelector(selector, { timeout: 200 });
expect(await getInputValue(await page.$(selector))).to.equal(value);
};

/**
* Check the differences between the provided expected parameters and the parameters actually received
*
Expand Down
10 changes: 9 additions & 1 deletion test/public/logs/create.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
*/

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

it('Should successfully display the autofilled runs, environments and lhcFills when replying', async () => {
await goToPage(page, 'log-reply&parentLogId=119');

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');
await expectInputValue(page, 'input#environments', 'Dxi029djX, eZF99lH6');
await expectInputValue(page, 'input#lhc-fills', '1, 4, 6');
});

it('can disable submit with invalid data', async () => {
const invalidTitle = 'A';
const validTitle = 'A valid title';
Expand Down

0 comments on commit f83fff0

Please sign in to comment.