Skip to content

Commit

Permalink
avniproject/avni-client#1544 | Add a functional and performance test …
Browse files Browse the repository at this point in the history
…for formElementGroup.nonVoidedFormElements
  • Loading branch information
himeshr committed Nov 8, 2024
1 parent c702faf commit 9f4dfb4
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion test/application/FormElementGroupTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down Expand Up @@ -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;
}
});

0 comments on commit 9f4dfb4

Please sign in to comment.