This repository has been archived by the owner on Apr 17, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #200 from nialldonnellyfh/RHMAP-12426_Fix-Section-…
…Dropdown Rhmap 12426 fix section dropdown
- Loading branch information
Showing
4 changed files
with
143 additions
and
16 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -44,4 +44,117 @@ describe("Page model", function() { | |
done(); | ||
}); | ||
}); | ||
|
||
describe("Section Breaks", function() { | ||
|
||
function getSectionBreakFormJSON(formId, includeFirstSection) { | ||
|
||
var firstSectionBreak = { | ||
_id: "sectionid1", | ||
type: "sectionBreak", | ||
name: "Section 1", | ||
description: "This is section 1" | ||
}; | ||
|
||
var form = { | ||
"_id": formId, | ||
"name": "Test Default Value Form", | ||
"createdBy": "[email protected]", | ||
"pages": [{ | ||
_id: "page1id", | ||
name: "This is page 1", | ||
fields: [ | ||
{ | ||
_id: "fieldid1", | ||
type: "text", | ||
name: "Text Field", | ||
description: "This is a text field in section 1" | ||
}, | ||
{ | ||
_id: "sectionid2", | ||
type: "sectionBreak", | ||
name: "Section 2", | ||
description: "This is section 2 in page 1" | ||
}, | ||
{ | ||
_id: "numberfieldid", | ||
type: "number", | ||
name: "Number Field", | ||
description: "This is a number field in section 2" | ||
} | ||
] | ||
}], | ||
"pageRef": {"page1id": 0}, | ||
"fieldRef": { | ||
"sectionid1": {"page": 0, "field": 0}, | ||
"fieldid1": {"page": 0, "field": 1}, | ||
"sectionid2": {"page": 0, "field": 2}, | ||
"numberfieldid": {"page": 0, "field": 3} | ||
} | ||
}; | ||
|
||
if(includeFirstSection) { | ||
form.pages[0].fields.unshift(firstSectionBreak); | ||
} | ||
|
||
|
||
return form; | ||
} | ||
|
||
it("pages should return unique section IDs", function(done) { | ||
|
||
var formId = "sectionbreakformid"; | ||
var sectionBreakForm = getSectionBreakFormJSON(formId, true); | ||
|
||
var Form = appForm.models.Form; | ||
|
||
new Form({ | ||
formId: formId, | ||
rawMode: true, | ||
rawData: sectionBreakForm | ||
}, function(err, formModel) { | ||
assert.ok(!err, "Expected no error intialising form"); | ||
|
||
var pageModel = formModel.getPageModelById("page1id"); | ||
|
||
var sections = pageModel.getSections(); | ||
|
||
var expectedSection1Id = "sectionid1"; | ||
var expectedSection2Id = "sectionid2"; | ||
|
||
assert.equal("fieldid1", sections[expectedSection1Id].fields[0].getFieldId()); | ||
assert.equal("numberfieldid", sections[expectedSection2Id].fields[0].getFieldId()); | ||
done(); | ||
}); | ||
}); | ||
|
||
it("pages should add a default section first if not specified", function(done) { | ||
|
||
var formId = "sectionbreakformidnofirstsection"; | ||
var sectionBreakForm = getSectionBreakFormJSON(formId, false); | ||
|
||
var Form = appForm.models.Form; | ||
|
||
new Form({ | ||
formId: formId, | ||
rawMode: true, | ||
rawData: sectionBreakForm | ||
}, function(err, formModel) { | ||
assert.ok(!err, "Expected no error intialising form"); | ||
|
||
var pageModel = formModel.getPageModelById("page1id"); | ||
|
||
var sections = pageModel.getSections(); | ||
|
||
var expectedSection1Id = "sectionBreakpage1id0"; | ||
var expectedSection2Id = "sectionid2"; | ||
|
||
assert.equal("fieldid1", sections[expectedSection1Id].fields[0].getFieldId()); | ||
assert.equal("numberfieldid", sections[expectedSection2Id].fields[0].getFieldId()); | ||
done(); | ||
}); | ||
}); | ||
|
||
|
||
}); | ||
}); |