first commit
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
// see https://playwright.dev/docs/api/class-electronapplication
|
||||
// https://github.com/microsoft/playwright/issues/6347#issuecomment-1085850728
|
||||
// https://www.anycodings.com/1questions/958135/can-i-set-the-date-for-playwright-browser
|
||||
const { _electron: electron } = require("playwright");
|
||||
|
||||
exports.startApplication = async (configFilename, systemDate = null, electronParams = ["js/electron.js"]) => {
|
||||
global.electronApp = null;
|
||||
global.page = null;
|
||||
process.env.MM_CONFIG_FILE = configFilename;
|
||||
process.env.TZ = "GMT";
|
||||
global.electronApp = await electron.launch({ args: electronParams });
|
||||
|
||||
await global.electronApp.firstWindow();
|
||||
|
||||
for (const win of global.electronApp.windows()) {
|
||||
const title = await win.title();
|
||||
expect(["MagicMirror²", "DevTools"]).toContain(title);
|
||||
if (title === "MagicMirror²") {
|
||||
global.page = win;
|
||||
if (systemDate) {
|
||||
await global.page.evaluate((systemDate) => {
|
||||
Date.now = () => {
|
||||
return new Date(systemDate);
|
||||
};
|
||||
}, systemDate);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
exports.stopApplication = async () => {
|
||||
if (global.electronApp) {
|
||||
await global.electronApp.close();
|
||||
}
|
||||
global.electronApp = null;
|
||||
global.page = null;
|
||||
};
|
||||
|
||||
exports.getElement = async (selector) => {
|
||||
expect(global.page);
|
||||
let elem = global.page.locator(selector);
|
||||
await elem.waitFor();
|
||||
expect(elem).not.toBe(null);
|
||||
return elem;
|
||||
};
|
||||
@@ -0,0 +1,19 @@
|
||||
const { injectMockData } = require("../../utils/weather_mocker");
|
||||
const helpers = require("./global-setup");
|
||||
|
||||
exports.getText = async (element, result) => {
|
||||
const elem = await helpers.getElement(element);
|
||||
await expect(elem).not.toBe(null);
|
||||
const text = await elem.textContent();
|
||||
await expect(
|
||||
text
|
||||
.trim()
|
||||
.replace(/(\r\n|\n|\r)/gm, "")
|
||||
.replace(/[ ]+/g, " ")
|
||||
).toBe(result);
|
||||
};
|
||||
|
||||
exports.startApp = async (configFileNameName, systemDate) => {
|
||||
injectMockData(configFileNameName);
|
||||
await helpers.startApplication("", systemDate);
|
||||
};
|
||||
Reference in New Issue
Block a user