let formGroup = createFormGroup(sectionIdStr, field);
let expectedHTML = `<divclass="form-group row"><labelclass="col-sm-4 col-form"for="section-1-after_trip">Have you taken this trip already?: </label><divclass="col-sm-6"><selectname="after_trip"id="section-1-after_trip"class="form-control"><optionvalue="true">Yes</option><optionvalue="false"selected="selected">No</option></select></div></div>`
assert.deepEqual(formGroup.outerHTML, expectedHTML, "boolean false renders as no option selected");
let formGroup = createFormGroup(sectionIdStr, field);
let expectedHTML = `<divclass="form-group row"><labelclass="col-sm-4 col-form"for="section-1-after_trip">Have you taken this trip already?: </label><divclass="col-sm-6"><selectname="after_trip"id="section-1-after_trip"class="form-control"><optionvalue="true"selected="selected">Yes</option><optionvalue="false">No</option></select></div></div>`
assert.deepEqual(formGroup.outerHTML, expectedHTML, "boolean true renders as yes option selected");
QUnit.test("decimal input group initialized to default", function(assert) {
let sectionIdStr = "section-1-";
let field = {
"value": "0.00",
"field_type": "decimal",
"label": "Lowest fare",
"field_name": "lowest_fare"
};
let formGroup = createFormGroup(sectionIdStr, field);
let value = formGroup.querySelector("#section-1-lowest_fare").value;
assert.deepEqual(value, "", "decimal input initialized to 0.00 has null value");
});
QUnit.test("decimal input group initialized to value", function(assert) {
let sectionIdStr = "section-1-";
let field = {
"value": "1337",
"field_type": "decimal",
"label": "Lowest fare",
"field_name": "lowest_fare"
};
let formGroup = createFormGroup(sectionIdStr, field);
let value = formGroup.querySelector("#section-1-lowest_fare").value;
assert.deepEqual(value, field.value, "decimal input initialized to 1337 has value 1337");
});
// END: Test rendering of fields with type decimal
// BEGIN: Test rendering of fields with type integer
QUnit.test("integer input group renders", function(assert) {
let sectionIdStr = "section-1-";
let field = {
"value": 0,
"field_type": "integer",
"label": "Number of full days of travel",
"field_name": "full_days"
};
let formGroup = createFormGroup(sectionIdStr, field);
let expectedHTML = `<divclass="form-group row"><labelclass="col-sm-4 col-form"for="section-1-full_days">Number of full days of travel: </label><divclass="col-sm-6"><inputname="full_days"id="section-1-full_days"type="number"class="form-control"step="1"min="0"></div></div>`
QUnit.test("integer input group initialized to default", function(assert) {
let sectionIdStr = "section-1-";
let field = {
"value": 0,
"field_type": "integer",
"label": "Number of full days of travel",
"field_name": "full_days"
};
let formGroup = createFormGroup(sectionIdStr, field);
let value = formGroup.querySelector("#section-1-full_days").value;
assert.deepEqual(value, "", "integer input initialized to 0 has null value");
});
QUnit.test("integer input group initialized to value", function(assert) {
let sectionIdStr = "section-1-";
let field = {
"value": 1234,
"field_type": "integer",
"label": "Number of full days of travel",
"field_name": "full_days"
};
let formGroup = createFormGroup(sectionIdStr, field);
let value = formGroup.querySelector("#section-1-full_days").value;
assert.deepEqual(value, field.value.toString(), "integer input initialized to 1234 has string value 1234");
});
// END: Test rendering of fields with type integer
// BEGIN: Test rendering of fields with type file
QUnit.test("file input group renders", function(assert) {
let sectionIdStr = "section-1-";
let field = {
"value": "",
"field_type": "file",
"label": "Screenshot of invoice",
"field_name": "invoice_screenshot"
};
let formGroup = createFormGroup(sectionIdStr, field);
let expectedHTML = `<divclass="form-group row"><labelclass="col-sm-4 col-form"for="section-1-invoice_screenshot">Screenshot of invoice: </label><divclass="col-sm-6"><inputname="invoice_screenshot"id="section-1-invoice_screenshot"type="file"class="form-control-file"><pclass="form-text"></p></div></div>`