start of e2e tests

This commit is contained in:
Alec Maier
2020-04-29 22:56:23 -04:00
parent 7cdd5aa675
commit 717b5324bf
10 changed files with 225 additions and 64 deletions

93
spec/SpecHelper.js Normal file
View File

@@ -0,0 +1,93 @@
let socket;
// Jasmine lifecycle hooks
beforeEach(() => {
cleanupPlayground();
// jasmine.addMatchers({ /* provide matcher function here if you want to, I guess */});
});
beforeAll(() => {
if(window.location.search.includes("socket=true")) {
socket = io();
}
});
afterEach(() => {
/*
if(socket !== undefined) {
socket.emit("test result",parseTestResults());
}
How to get only the newest result? No clue right now.
*/
});
afterAll(() => {
resportResultsOnSocket();
});
// Utility functions
const parseTestResults = function() {
const resultsElement = document.querySelector("span.jasmine-overall-result.jasmine-bar");
if(resultsElement !== null) {
const results = /.*(\d+) specs.*(\d+) failure.*(\d+).*/.exec(resultsElement.textContent);
const total = parseInt(results[1]);
const failures = parseInt(results[2]);
const pending = parseInt(results[3]);
return Promise.resolve({
"totalCount": total,
"failureCount": failures,
"pendingCount": pending
});
} else {
let maxRetries = 60;
return new Promise((resolve, reject) => {
const resultsInterval = setInterval(() => {
maxRetries--;
const resultsElem = document.querySelector("span.jasmine-overall-result.jasmine-bar");
if (maxRetries === 0) {
reject("Required results element not found.");
} else {
if (resultsElem !== null) {
const results = /.*(\d+) spec.*(\d+) failure.*(\d+).*/.exec(resultsElem.textContent);
const pendingResults = /.*(\d+) pending.*/.exec(resultsElem.textContent);
const total = parseInt(results[1]);
const failures = parseInt(results[2]);
const pending = pendingResults ? parseInt(pendingResults[1]) : 0;
clearInterval(resultsInterval);
resolve({
"totalCount": total,
"failureCount": failures,
"pendingCount": pending
});
}
}
}, 500);
});
}
};
export const addStubElement = function(element) {
document.getElementById("playground").appendChild(element);
};
export const cleanupPlayground = function() {
document.getElementById("playground").innerHTML = "";
};
export const resportResultsOnSocket = function() {
if(socket === undefined) {
socket = io();
}
parseTestResults().then((results) => {
socket.emit("all-results",results);
}).catch((e) => {console.error(e);});
};

37
spec/e2e/SetupSpec.js Normal file
View File

@@ -0,0 +1,37 @@
import { addStubElement } from "../SpecHelper.js"
import { setup } from "../../static/setup.js"
describe("Home page", function() {
beforeEach(function() {
});
it("should render the set of standard and custom roles", function() {
// arrange
let goodCards = document.createElement("div");
goodCards.setAttribute("id", "card-select-good");
let evilCards = document.createElement("div");
evilCards.setAttribute("id", "card-select-evil");
let roles = document.createElement("div");
roles.setAttribute("id", "roles");
let customRoles = document.createElement("div");
customRoles.setAttribute("id", "custom-roles");
addStubElement(goodCards);
addStubElement(evilCards);
addStubElement(roles);
addStubElement(customRoles);
// act
setup.renderAvailableCards(false);
//assert
expect(document.getElementById("card-0")).toBeDefined();
});
});

View File

@@ -1,5 +1,5 @@
{
"spec_dir": "spec/unit",
"spec_dir": "spec/unit/",
"spec_files": [
"**/*[sS]pec.js"
],
@@ -8,4 +8,4 @@
],
"stopSpecOnExpectationFailure": false,
"random": true
}
}