From f83fff0fb1538343c840ea4043d3de071ba6d093 Mon Sep 17 00:00:00 2001 From: Anwar Hamdi <132836494+AnoeBanoe@users.noreply.github.com> Date: Fri, 1 Mar 2024 14:39:26 +0100 Subject: [PATCH] [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 --- lib/public/views/Logs/Create/LogReplyModel.js | 12 +++++++++-- test/public/defaults.js | 20 +++++++++++++++++++ test/public/logs/create.test.js | 10 +++++++++- 3 files changed, 39 insertions(+), 3 deletions(-) diff --git a/lib/public/views/Logs/Create/LogReplyModel.js b/lib/public/views/Logs/Create/LogReplyModel.js index 164a43daea..21745d283c 100644 --- a/lib/public/views/Logs/Create/LogReplyModel.js +++ b/lib/public/views/Logs/Create/LogReplyModel.js @@ -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}`; @@ -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(', '); + } } /** diff --git a/test/public/defaults.js b/test/public/defaults.js index 2549360584..ec0a5c2897 100644 --- a/test/public/defaults.js +++ b/test/public/defaults.js @@ -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} 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} 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 * diff --git a/test/public/logs/create.test.js b/test/public/logs/create.test.js index d723456e88..6c4daaa3e1 100644 --- a/test/public/logs/create.test.js +++ b/test/public/logs/create.test.js @@ -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'); @@ -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';