File size: 2,365 Bytes
71174bc | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 | import { addVueXStoreModule } from "@/Store";
import { getMoleculesFromStore, setStoreVar } from "@/Store/StoreExternalAccess";
import { setPluginToTest } from "./PluginToTest";
import { getUrlParam } from "@/Core/UrlParams";
import { SelectedType } from "@/UI/Navigation/TreeView/TreeInterfaces";
/**
* If running a selenium test, this function will set things up.
*/
export function setupTests() {
// Get test from url
const name = getUrlParam("test");
if (name === null) {
// You're not running a test
return;
}
// Note that isTest now resides in GlobalVars.ts to avoid circular
// dependencies.
const idx = getUrlParam("index");
setPluginToTest(name, idx === null ? undefined : parseInt(idx, 10));
/**
* Detects any javascript errors and logs them. Selenium can read these. See
* https://www.tutorialspoint.com/How-to-catch-all-JavaScript-errors
*
* @param {string | Event} msg The error message.
* @param {string | undefined} url The url of the error.
* @param {number | undefined} line The line number of the error.
*/
window.onerror = function (
msg: string | Event,
url: string | undefined,
line: number | undefined
) {
const e = msg + "\n" + url + "\n" + "Line " + line?.toString();
setStoreVar("error", e, "test");
};
addVueXStoreModule("test", {
cmds: "",
error: "",
msgs: "",
});
/* It's a test to see if the error handler works. */
// setTimeout(() => {
// // eslint-disable-next-line @typescript-eslint/ban-ts-comment
// // @ts-ignore
// sdfdsfdsf;
// }, 5000);
}
/**
* Expands the navigator tree so all molecules are visible. Easier to test.
*/
export function expandAndShowAllMolsInTree() {
// Get all molecules.
// The setTimeout was causing a race condition where test commands
// would execute before the tree was expanded in the data model.
// Vue's reactivity will handle the DOM update. Test commands should
// use `waitUntilRegex` to wait for the DOM to reflect the new state.
// setTimeout(() => {
getMoleculesFromStore().flattened.forEach((mol) => {
mol.treeExpanded = true;
mol.visible = true;
mol.selected = SelectedType.False;
});
// }, 500);
} |