From 9f4dfb4ce047c63144c0c39219fc3db9d797a5dd Mon Sep 17 00:00:00 2001 From: himeshr Date: Fri, 8 Nov 2024 19:41:17 +0530 Subject: [PATCH] avniproject/avni-client#1544 | Add a functional and performance test for formElementGroup.nonVoidedFormElements --- test/application/FormElementGroupTest.js | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/test/application/FormElementGroupTest.js b/test/application/FormElementGroupTest.js index 3126bf5..8aa2811 100644 --- a/test/application/FormElementGroupTest.js +++ b/test/application/FormElementGroupTest.js @@ -5,6 +5,7 @@ import FormElement from "openchs-models/src/application/FormElement"; import FormElementStatus from "../../src/application/FormElementStatus"; import FormElementGroup from "../../src/application/FormElementGroup"; import ObservationsHolder from "../../src/ObservationsHolder"; +import _ from 'lodash'; describe('FormElementGroupTest', () => { it('previous and next', () => { @@ -92,12 +93,26 @@ describe('FormElementGroupTest', () => { assert.isTrue(isEmpty); }); - function createFormElement(uuid, answers = []) { + it('findNonVoidedFormElements', () => { + let formElements = _.range(10000).map(idx => createFormElement('ABC'+idx, [], + idx % 10===0, idx % 5 === 0 && idx - 5 > 0 ? idx - 5 : null )); + let formElementGroup = new FormElementGroup(); + formElementGroup.formElements = formElements; + let startTime = performance.now() + let nonVoidedFormElements = formElementGroup.nonVoidedFormElements(); + let endTime = performance.now() + assert.equal(nonVoidedFormElements.length, 9000); + assert.isTrue(endTime - startTime < 100, 'Test should have completed within 100 milliseconds'); + }); + + function createFormElement(uuid, answers = [], isVoided = false, parentGroupUuid = null) { let x = new FormElement(); x.uuid = uuid; x.getRawAnswers = function () { return answers; } + x.voided = isVoided; + x.groupUuid = parentGroupUuid; return x; } });