| import { IMenuPathInfo, processMenuPath } from "@/UI/Navigation/Menu/Menu"; |
| import * as PluginToTest from "./PluginToTest"; |
| import { TestCmdList } from "./TestCmdList"; |
| import { PluginParentClass } from "@/Plugins/Parents/PluginParentClass/PluginParentClass"; |
| import { store } from "@/Store"; |
| import { slugify } from "@/Core/Utils/StringUtils"; |
| import { ITest, ITestCommand, TestCommand } from "./TestInterfaces"; |
| import { |
| TestClick, |
| TestWait, |
| TestWaitUntilNotRegex, |
| TestWaitUntilRegex, |
| addTestsToCmdList, |
| } from "./TestCommands"; |
|
|
| type IConvertedTest = { [key: string]: ITestCommand[] }; |
|
|
| |
| |
| |
| |
| |
| |
| export function openPluginCmds(plugin: any): ITestCommand[] { |
| |
| const menuData = processMenuPath(plugin.menuPath) as IMenuPathInfo[]; |
| if (menuData === null || menuData === undefined) { |
| return []; |
| } |
| const lastMenuData = menuData.pop(); |
| const lastSel = |
| ".navbar #menu-plugin-" + |
| plugin.pluginId + |
| "-" + |
| slugify(lastMenuData?.text as string); |
| |
| |
| |
| if (menuData.length > 1) { |
| menuData.splice(1, 1); |
| } |
| const sels = menuData?.map( |
| (x, i) => ".navbar #menu" + (i + 1).toString() + "-" + slugify(x.text) |
| ); |
| const cmds: ITestCommand[] = []; |
| |
| const hamburgerButton = document.querySelector( |
| "#hamburger-button" |
| ) as HTMLDivElement; |
| const hamburgerButtonVisible = |
| hamburgerButton !== null && |
| hamburgerButton !== undefined && |
| getComputedStyle(hamburgerButton).display !== "none"; |
| if (hamburgerButtonVisible) { |
| cmds.push(new TestClick("#hamburger-button").cmd); |
| } |
| cmds.push( |
| ...sels.map((sel) => new TestClick(sel).cmd), |
| new TestWait(1).cmd, |
| new TestClick(lastSel).cmd, |
| new TestWait(1).cmd |
| ); |
| return cmds; |
| } |
|
|
| |
| |
| |
| |
| |
| |
| |
| function addTestDefaults( |
| convertedTests: IConvertedTest[], |
| plugin: PluginParentClass |
| ) { |
| const { pluginId } = plugin; |
| if (convertedTests.length === 0) { |
| convertedTests.push({} as IConvertedTest); |
| } |
| |
| for (const test of convertedTests) { |
| |
| test.beforePluginOpens = test.beforePluginOpens || []; |
| |
| test.pluginOpen = test.pluginOpen || []; |
| |
| |
| if (!test.closePlugin) { |
| test.closePlugin = plugin.noPopup |
| ? [] |
| : [new TestClick(`#modal-${pluginId} .action-btn`).cmd]; |
| } |
| |
| |
| if (!plugin.noPopup) { |
| const waitCmd = new TestWaitUntilNotRegex( |
| "body", |
| 'class="modal-open"' |
| ).cmd; |
| if (test.afterPluginCloses) { |
| test.afterPluginCloses.unshift(waitCmd); |
| } else { |
| test.afterPluginCloses = [waitCmd]; |
| } |
| } |
| |
| |
| if (!test.afterPluginCloses) { |
| |
| test.afterPluginCloses = []; |
| if (plugin.logJob) { |
| test.afterPluginCloses.push( |
| new TestWaitUntilRegex( |
| "#log", |
| "Job " + pluginId + '.*?" started' |
| ).cmd |
| ); |
| } |
| } |
| |
| if ( |
| test.afterPluginCloses.length > 0 && |
| test.afterPluginCloses[test.afterPluginCloses.length - 1].cmd === |
| TestCommand.Wait |
| ) { |
| throw new Error("Last command cannot be a wait."); |
| } |
| |
| test.afterPluginCloses.push(new TestWait(1).cmd); |
| } |
| } |
|
|
| |
| |
| |
| |
| function makeFakeMouse() { |
| |
| |
| |
| const style = document.createElement("style"); |
| style.innerHTML = ` |
| .custom-cursor { |
| position: absolute; |
| width: 37px; |
| height: 50px; |
| background-size: 100% 100%; |
| pointer-events: none; |
| z-index: 10000; |
| background-image: url('fake_cursor.png'); |
| } |
| `; |
| document.head.appendChild(style); |
| |
| const cursor = document.createElement("div"); |
| cursor.className = "custom-cursor"; |
| cursor.id = "customCursor"; |
| document.body.appendChild(cursor); |
| |
| cursor.style.left = "-100px"; |
| cursor.style.top = "-100px"; |
| document.addEventListener("mousemove", function (e) { |
| const cursor = document.getElementById("customCursor"); |
| if (!cursor) { |
| return; |
| } |
| |
| cursor.style.left = e.pageX + "px"; |
| cursor.style.top = e.pageY + "px"; |
| }); |
| } |
|
|
| |
| |
| |
| |
| |
| |
| export async function createTestCmdsIfTestSpecified(plugin: any) { |
| if (PluginToTest.pluginToTest !== plugin.pluginId) { |
| return; |
| } |
| if (plugin.pluginId === "") { |
| return; |
| } |
| let tests: ITest | ITest[] = await plugin.getTests(); |
| makeFakeMouse(); |
| |
| if (!Array.isArray(tests)) { |
| tests = [tests]; |
| } |
|
|
| |
| |
| if (tests.length > 1 && PluginToTest.pluginTestIndex === undefined) { |
| store.commit("setVar", { |
| name: "cmds", |
| val: JSON.stringify([ |
| { |
| cmd: TestCommand.AddTests, |
| data: tests.length, |
| }, |
| ]), |
| module: "test", |
| }); |
| return; |
| } |
|
|
| |
| const testToRun = tests[PluginToTest.pluginTestIndex || 0]; |
|
|
| |
| const convertedTest: IConvertedTest = {}; |
| for (const key in testToRun) { |
| const testStepFunc = testToRun[key as keyof ITest]; |
| if (typeof testStepFunc === "function") { |
| const testCmdListInstance = testStepFunc(); |
| if (testCmdListInstance instanceof TestCmdList) { |
| convertedTest[key] = testCmdListInstance.cmds; |
| } |
| } |
| } |
|
|
| const convertedTests = [convertedTest]; |
| addTestDefaults(convertedTests, plugin); |
|
|
| |
| |
| if (plugin.menuPath === null) { |
| addTestsToCmdList([]); |
| return; |
| } |
|
|
| const finalTestCommands = convertedTests[0]; |
| const cmds = [ |
| ...(finalTestCommands.beforePluginOpens as ITestCommand[]), |
| ...openPluginCmds(plugin), |
| ...(finalTestCommands.pluginOpen as ITestCommand[]), |
| new TestWait(1).cmd, |
| ...(finalTestCommands.closePlugin as ITestCommand[]), |
| ...(finalTestCommands.afterPluginCloses as ITestCommand[]), |
| new TestWait(0.5).cmd, |
| ] as ITestCommand[]; |
| addTestsToCmdList(cmds); |
| |
| |
| |
| |
| |
| } |
|
|