2021-11-29 04:09:01 +00:00
|
|
|
import { Page, Locator } from 'playwright'
|
2021-11-24 08:04:14 +00:00
|
|
|
import { expect } from '@playwright/test'
|
2021-11-29 04:09:01 +00:00
|
|
|
import process from 'process'
|
2021-11-24 08:04:14 +00:00
|
|
|
|
2021-11-29 04:09:01 +00:00
|
|
|
export const IsMac = process.platform === 'darwin'
|
|
|
|
export const IsLinux = process.platform === 'linux'
|
|
|
|
export const IsWindows = process.platform === 'win32'
|
2021-11-24 08:04:14 +00:00
|
|
|
|
|
|
|
export function randomString(length: number) {
|
|
|
|
const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
|
|
|
|
|
|
|
|
let result = '';
|
|
|
|
const charactersLength = characters.length;
|
|
|
|
for (let i = 0; i < length; i++) {
|
|
|
|
result += characters.charAt(Math.floor(Math.random() * charactersLength));
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2021-11-29 04:09:01 +00:00
|
|
|
export async function appFirstLoaded(page: Page) {
|
|
|
|
await page.waitForSelector('text=This is a demo graph, changes will not be saved until you open a local folder')
|
|
|
|
}
|
|
|
|
|
2021-11-24 08:04:14 +00:00
|
|
|
export async function createRandomPage(page: Page) {
|
|
|
|
const randomTitle = randomString(20)
|
|
|
|
|
2021-12-10 03:55:48 +00:00
|
|
|
// Click #search-button
|
2021-12-08 13:13:57 +00:00
|
|
|
await page.click('#search-button')
|
2021-11-24 08:04:14 +00:00
|
|
|
// Fill [placeholder="Search or create page"]
|
|
|
|
await page.fill('[placeholder="Search or create page"]', randomTitle)
|
|
|
|
// Click text=/.*New page: "new page".*/
|
|
|
|
await page.click('text=/.*New page: ".*/')
|
|
|
|
// wait for textarea of first block
|
|
|
|
await page.waitForSelector(':nth-match(textarea, 1)', { state: 'visible' })
|
2022-01-05 13:05:05 +00:00
|
|
|
|
|
|
|
return randomTitle;
|
2021-11-24 08:04:14 +00:00
|
|
|
}
|
|
|
|
|
2021-12-20 08:21:07 +00:00
|
|
|
/**
|
2021-12-21 00:29:22 +00:00
|
|
|
* Locate the last block in the inner editor
|
2021-12-20 08:21:07 +00:00
|
|
|
* @param page The Playwright Page object.
|
|
|
|
* @returns The locator of the last block.
|
|
|
|
*/
|
2021-12-21 00:29:22 +00:00
|
|
|
export async function lastInnerBlock(page: Page): Promise<Locator> {
|
2021-11-24 08:04:14 +00:00
|
|
|
// discard any popups
|
|
|
|
await page.keyboard.press('Escape')
|
|
|
|
// click last block
|
2021-12-21 00:29:22 +00:00
|
|
|
await page.click('.page-blocks-inner .ls-block >> nth=-1')
|
|
|
|
// wait for textarea
|
|
|
|
await page.waitForSelector(':nth-match(textarea, 1)', { state: 'visible' })
|
|
|
|
|
|
|
|
return page.locator(':nth-match(textarea, 1)')
|
|
|
|
}
|
|
|
|
|
|
|
|
export async function lastBlock(page: Page): Promise<Locator> {
|
|
|
|
// discard any popups
|
|
|
|
await page.keyboard.press('Escape')
|
|
|
|
// click last block
|
|
|
|
await page.click('.ls-block >> nth=-1')
|
2021-11-24 08:04:14 +00:00
|
|
|
// wait for textarea
|
|
|
|
await page.waitForSelector(':nth-match(textarea, 1)', { state: 'visible' })
|
2021-11-29 04:09:01 +00:00
|
|
|
|
|
|
|
return page.locator(':nth-match(textarea, 1)')
|
2021-11-24 08:04:14 +00:00
|
|
|
}
|
|
|
|
|
2021-12-20 08:21:07 +00:00
|
|
|
/**
|
2021-12-21 00:29:22 +00:00
|
|
|
* Create and locate a new block at the end of the inner editor
|
2021-12-20 08:21:07 +00:00
|
|
|
* @param page The Playwright Page object
|
|
|
|
* @returns The locator of the last block
|
|
|
|
*/
|
2021-12-21 00:29:22 +00:00
|
|
|
export async function newInnerBlock(page: Page): Promise<Locator> {
|
|
|
|
await lastInnerBlock(page)
|
|
|
|
await page.press(':nth-match(textarea, 1)', 'Enter')
|
|
|
|
|
|
|
|
return page.locator(':nth-match(textarea, 1)')
|
|
|
|
}
|
|
|
|
|
|
|
|
export async function newBlock(page: Page): Promise<Locator> {
|
|
|
|
await lastBlock(page)
|
2021-11-24 08:04:14 +00:00
|
|
|
await page.press(':nth-match(textarea, 1)', 'Enter')
|
2021-11-29 04:09:01 +00:00
|
|
|
|
|
|
|
return page.locator(':nth-match(textarea, 1)')
|
2021-11-24 08:04:14 +00:00
|
|
|
}
|
2021-12-11 15:50:17 +00:00
|
|
|
|
|
|
|
export async function escapeToCodeEditor(page: Page): Promise<void> {
|
|
|
|
await page.press('.block-editor textarea', 'Escape')
|
|
|
|
await page.waitForSelector('.CodeMirror pre', { state: 'visible' })
|
|
|
|
|
|
|
|
await page.waitForTimeout(500)
|
|
|
|
await page.click('.CodeMirror pre')
|
|
|
|
await page.waitForTimeout(500)
|
|
|
|
|
|
|
|
await page.waitForSelector('.CodeMirror textarea', { state: 'visible' })
|
|
|
|
}
|
|
|
|
|
|
|
|
export async function escapeToBlockEditor(page: Page): Promise<void> {
|
|
|
|
await page.waitForTimeout(500)
|
|
|
|
await page.click('.CodeMirror pre')
|
|
|
|
await page.waitForTimeout(500)
|
|
|
|
|
|
|
|
await page.press('.CodeMirror textarea', 'Escape')
|
|
|
|
await page.waitForTimeout(500)
|
|
|
|
}
|
2021-12-30 09:35:20 +00:00
|
|
|
|
2022-01-05 13:05:05 +00:00
|
|
|
export async function setMockedOpenDirPath(
|
|
|
|
page: Page,
|
|
|
|
path?: string
|
|
|
|
): Promise<void> {
|
|
|
|
// set next open directory
|
|
|
|
await page.evaluate(
|
|
|
|
([path]) => {
|
|
|
|
Object.assign(window, {
|
|
|
|
__MOCKED_OPEN_DIR_PATH__: path,
|
|
|
|
})
|
|
|
|
},
|
|
|
|
[path]
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
export async function loadLocalGraph(page: Page, path?: string): Promise<void> {
|
|
|
|
const hasOpenButton = await page.$('#head >> .button >> text=Open')
|
|
|
|
await setMockedOpenDirPath(page, path);
|
|
|
|
if (hasOpenButton) {
|
|
|
|
await page.click('#head >> .button >> text=Open')
|
|
|
|
} else {
|
|
|
|
if (!(await page.$('.ls-left-sidebar-open'))) {
|
|
|
|
await page.click('.cp__header-left-menu.button')
|
|
|
|
}
|
|
|
|
await page.click('#left-sidebar >> #repo-switch')
|
|
|
|
await page.click('text=Add new graph')
|
|
|
|
await page.waitForSelector('h1:has-text("Open a local directory")')
|
|
|
|
await page.click('h1:has-text("Open a local directory")')
|
|
|
|
}
|
|
|
|
|
|
|
|
setMockedOpenDirPath(page, ''); // reset it
|
|
|
|
|
|
|
|
await page.waitForSelector(':has-text("Parsing files")', {
|
|
|
|
state: 'hidden',
|
|
|
|
timeout: 1000 * 60 * 5,
|
|
|
|
})
|
|
|
|
|
|
|
|
await page.waitForFunction('window.document.title != "Loading"')
|
|
|
|
|
|
|
|
console.log('Graph loaded for ' + path)
|
|
|
|
}
|
|
|
|
|
2021-12-30 09:35:20 +00:00
|
|
|
export async function activateNewPage(page: Page) {
|
|
|
|
await page.click('.ls-block >> nth=0')
|
|
|
|
await page.waitForTimeout(500)
|
|
|
|
}
|