Merge pull request #130 from danieldupriest/fix-tests

Fix broken unit tests
This commit is contained in:
Daniel Dupriest 2019-03-10 18:58:40 -07:00 committed by GitHub
commit 1ebd953057
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 38 additions and 14 deletions

View file

@ -404,12 +404,6 @@ function displayListOfReports(parsedData) {
bodyRow.insertCell(0).innerHTML = title; bodyRow.insertCell(0).innerHTML = title;
bodyRow.insertCell(1).innerHTML = dateCreated; bodyRow.insertCell(1).innerHTML = dateCreated;
/*
let stateCell = bodyRow.insertCell(2);
stateCell.innerHTML = state;
stateCell.classList.add("d-none", "d-lg-table-cell"); // Column visible only on large displays
*/
// Create edit/view button // Create edit/view button
let actionButton = document.createElement("button"); let actionButton = document.createElement("button");
actionButton.type = "submit"; actionButton.type = "submit";

View file

@ -9,7 +9,9 @@
</head> </head>
<body> <body>
<div id="qunit"></div> <div id="qunit"></div>
<div id="qunit-fixture"> <div id="qunit-fixture"></div>
<template id="report-table">
<div class="card-body"> <div class="card-body">
<div class="text-center"> <div class="text-center">
<i class="fas fa-spinner fa-3x fa-spin"></i> <i class="fas fa-spinner fa-3x fa-spin"></i>
@ -27,6 +29,9 @@
</tbody> </tbody>
</table> </table>
</div> </div>
</template>
<template id="new-report">
<div class="modal fade" id="newReportModal" tabindex="-1" role="dialog"> <div class="modal fade" id="newReportModal" tabindex="-1" role="dialog">
<div class="modal-dialog modal-lg" role="document"> <div class="modal-dialog modal-lg" role="document">
<div class="modal-content"> <div class="modal-content">
@ -46,11 +51,15 @@
</div> </div>
<div class="modal-footer"> <div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button> <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary submit-report-button">Submit Report</button> <button type="button" class="btn btn-primary finalize-report">Finalize Report</button>
<button type="button" class="btn btn-primary review-report">Submit for Review</button>
</div> </div>
</div> </div>
</div> </div>
</div> </div>
</template>
<template id="edit-report">
<div class="modal fade" id="editReportModal" tabindex="-1" role="dialog"> <div class="modal fade" id="editReportModal" tabindex="-1" role="dialog">
<div class="modal-dialog modal-lg" role="document"> <div class="modal-dialog modal-lg" role="document">
<div class="modal-content"> <div class="modal-content">
@ -71,12 +80,14 @@
<div class="modal-footer"> <div class="modal-footer">
<button type="button" class="btn btn-danger delete-report">Delete Report</button> <button type="button" class="btn btn-danger delete-report">Delete Report</button>
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button> <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary submit-report-button">Submit Report</button> <button type="button" class="btn btn-primary finalize-report">Finalize Report</button>
<button type="button" class="btn btn-primary review-report">Submit for Review</button>
</div> </div>
</div> </div>
</div> </div>
</div> </div>
</div> </template>
<script src="https://code.jquery.com/qunit/qunit-2.9.2.js"></script> <script src="https://code.jquery.com/qunit/qunit-2.9.2.js"></script>
<script> <script>
@ -390,6 +401,10 @@
QUnit.module("createReportForm"); QUnit.module("createReportForm");
QUnit.test("new report renders", function(assert) { QUnit.test("new report renders", function(assert) {
let qunitFixture = document.getElementById("qunit-fixture");
let newReport = document.getElementById("new-report");
let clone = document.importNode(newReport.content, true);
qunitFixture.appendChild(clone);
createReportForm(testReport, reportType.NEW); createReportForm(testReport, reportType.NEW);
let newReportModal = document.getElementById("newReportModal"); let newReportModal = document.getElementById("newReportModal");
let expectedHTML = typeNewExpectedHTML; let expectedHTML = typeNewExpectedHTML;
@ -397,6 +412,10 @@
}); });
QUnit.test("edit report renders", function(assert) { QUnit.test("edit report renders", function(assert) {
let qunitFixture = document.getElementById("qunit-fixture");
let editReport = document.getElementById("edit-report");
let clone = document.importNode(editReport.content, true);
qunitFixture.appendChild(clone);
createReportForm(testReport, reportType.EDIT); createReportForm(testReport, reportType.EDIT);
let editReportModal = document.getElementById("editReportModal"); let editReportModal = document.getElementById("editReportModal");
let expectedHTML = typeEditExpectedHTML; let expectedHTML = typeEditExpectedHTML;
@ -405,6 +424,9 @@
QUnit.test("undefined report does not render", function(assert) { QUnit.test("undefined report does not render", function(assert) {
let qunitFixture = document.getElementById("qunit-fixture"); let qunitFixture = document.getElementById("qunit-fixture");
let newReport = document.getElementById("new-report");
let clone = document.importNode(newReport.content, true);
qunitFixture.appendChild(clone);
let expectedHTML = qunitFixture.outerHTML; let expectedHTML = qunitFixture.outerHTML;
createReportForm(testReport, undefined); createReportForm(testReport, undefined);
assert.deepEqual(qunitFixture.outerHTML, expectedHTML, "report forms and expectedHTML are identical") assert.deepEqual(qunitFixture.outerHTML, expectedHTML, "report forms and expectedHTML are identical")
@ -412,7 +434,14 @@
// BEGIN displayListOfReports unit tests // BEGIN displayListOfReports unit tests
QUnit.module("displayListOfReports"); QUnit.module("displayListOfReports", {
beforeEach: function() {
let qunitFixture = document.getElementById("qunit-fixture");
let reportTable = document.getElementById("report-table");
let clone = document.importNode(reportTable.content, true);
qunitFixture.appendChild(clone);
}
});
QUnit.test("empty reports", function(assert) { QUnit.test("empty reports", function(assert) {
let expectedHTML = `<div class="card-body"><h5 class="text-center">No reports found.</h5></div>`; let expectedHTML = `<div class="card-body"><h5 class="text-center">No reports found.</h5></div>`;
@ -430,7 +459,6 @@
assert.deepEqual(cardBody.outerHTML.replace(/>\s+</g, "><"), expectedHTML, "card body and expectedHTML are identical"); assert.deepEqual(cardBody.outerHTML.replace(/>\s+</g, "><"), expectedHTML, "card body and expectedHTML are identical");
}); });
QUnit.test("two editable reports", function(assert) { QUnit.test("two editable reports", function(assert) {
let parsedData = {"reports": [{"date_created": "2019-03-05T08:00:00Z", "title": "TEST1", "reference_number": "1234", "date_submitted": "2019-03-05T08:00:00Z", "user_id": 2, "submitted": false, "report_pk": 4}, {"date_created": "2019-03-05T08:00:00Z", "title": "TEST2", "reference_number": "12345", "date_submitted": "2019-03-05T08:00:00Z", "user_id": 2, "submitted": false, "report_pk": 5}]}; let parsedData = {"reports": [{"date_created": "2019-03-05T08:00:00Z", "title": "TEST1", "reference_number": "1234", "date_submitted": "2019-03-05T08:00:00Z", "user_id": 2, "submitted": false, "report_pk": 4}, {"date_created": "2019-03-05T08:00:00Z", "title": "TEST2", "reference_number": "12345", "date_submitted": "2019-03-05T08:00:00Z", "user_id": 2, "submitted": false, "report_pk": 5}]};
let expectedHTML = displayReportsTwoReportsExpected; let expectedHTML = displayReportsTwoReportsExpected;

File diff suppressed because one or more lines are too long