-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f469e6a
commit 83512ca
Showing
28 changed files
with
422 additions
and
178 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"compilerOptions": { | ||
"module": "ES2022", | ||
"moduleResolution": "node", | ||
"target": "ES2022" | ||
}, | ||
"exclude": ["node_modules", "**/node_modules/*"], | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,13 @@ | ||
# Note 001: | ||
# Note#001: | ||
|
||
TiddlyWiki will not update $edit widget if it has focus even when the edited field changed. | ||
That's expected behavior, to avoid the widget from updating while typing in it. | ||
This is a bit of a bummer for our tests which involve things being open in another window, | ||
so as a solution we force blur on the inputs. | ||
so as a solution we force blur on the inputs. | ||
|
||
# Note#002: | ||
|
||
Playwright fixture support works great when used with TypeScript but is a bit of a hell if | ||
you try to use pure JS. The solution used to have proper code completion in VSCode | ||
was taken from [this comment](https://github.com/microsoft/playwright/issues/7890#issuecomment-1369828521) | ||
by **Andrew Hobson** on Playwright's GitHub issues. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,46 +1,98 @@ | ||
// @ts-check | ||
import { sep, resolve } from 'path'; | ||
import { expect } from 'playwright/test'; | ||
|
||
const docsPath = resolve(`${process.cwd()}${sep}docs${sep}`); | ||
// Windows requires adding a slash at the start, while Linux already has it baked in | ||
const crossPlatformDocsPath = docsPath.replace(/^\/+/, ''); | ||
|
||
/** | ||
* @typedef {object} EditionEntry | ||
* @property {string} suffix Suffix to add to the `index.html` file | ||
* @property {string} version Version used for asserting the correct file was loaded | ||
* @property {boolean} hasCodeMirror Whether this version includes code mirror | ||
*/ | ||
|
||
/** | ||
* @type {Object.<string, EditionEntry>} | ||
*/ | ||
const SUPPORTED_EDITIONS = { | ||
tw522: getEdition('', '5.2.2', false), | ||
tw522CodeMirror: getEdition('-cm', '5.2.2-CodeMirror', true), | ||
tw530: getEdition('-530', '5.3.0', false), | ||
tw530CodeMirror: getEdition('-530-cm', '5.3.0-CodeMirror', true), | ||
tw531: getEdition('-531', '5.3.1', false), | ||
tw531CodeMirror: getEdition('-531-cm', '5.3.1-CodeMirror', true), | ||
}; | ||
|
||
/** | ||
* Selects and initializes a specific version of Tiddly Wiki for testing | ||
*/ | ||
export class EditionSelector { | ||
/** | ||
* @param {import('playwright-core').Page} page | ||
*/ | ||
constructor(page) { | ||
this.page = page; | ||
} | ||
|
||
tw522 = async page => this.#goto(page, '', '5.2.2'); | ||
tw522CodeMirror = async page => this.#goto(page, '-cm', '5.2.2-CodeMirror'); | ||
tw530 = async page => this.#goto(page, '-530', '5.3.0'); | ||
tw530CodeMirror = async page => this.#goto(page, '-530-cm', '5.3.0-CodeMirror'); | ||
tw531 = async page => this.#goto(page, '-531', '5.3.1'); | ||
tw531CodeMirror = async page => this.#goto(page, '-531-cm', '5.3.1-CodeMirror'); | ||
/** | ||
* Initializes the given TiddlyWiki edition | ||
* | ||
* @param {string} editionName | ||
* @param {import('playwright-core').Page} [page] | ||
* @return {Promise<void>} | ||
*/ | ||
initByName = async (editionName, page = undefined) => { | ||
const edition = SUPPORTED_EDITIONS[editionName]; | ||
|
||
initByName = async (name, page) => { | ||
if (typeof this[name] !== 'function') { | ||
throw new Error(`Unsupported edition '${name}'`); | ||
if (!edition) { | ||
throw new Error(`Unsupported edition '${editionName}'`); | ||
} | ||
|
||
await this[name](page); | ||
await this.#init(page, edition.suffix, edition.version); | ||
} | ||
|
||
#goto = async (page, suffix, expectedVersion) => { | ||
/** | ||
* @param {import('playwright-core').Page|undefined} page | ||
* @param {string} suffix | ||
* @param {string} expectedVersion | ||
*/ | ||
#init = async (page, suffix, expectedVersion) => { | ||
page = page ?? this.page; | ||
|
||
await page.goto(`file:///${crossPlatformDocsPath}/index${suffix}.html`); | ||
await expect(page).toHaveTitle(/Evidently Cube TiddlyWiki5 Plugin Showcase/); | ||
await expect(page.locator('[data-test-id="tw-edition"]')).toHaveText(expectedVersion, {timeout: 300}); | ||
}; | ||
|
||
static getEditions(codeMirrorFilter) { | ||
return [ | ||
codeMirrorFilter !== true ? 'tw522' : null, | ||
codeMirrorFilter !== false ? 'tw522CodeMirror' : null, | ||
codeMirrorFilter !== true ? 'tw530' : null, | ||
codeMirrorFilter !== false ? 'tw530CodeMirror' : null, | ||
codeMirrorFilter !== true ? 'tw531' : null, | ||
codeMirrorFilter !== false ? 'tw531CodeMirror' : null, | ||
].filter(x => x); | ||
/** | ||
* Returns a list of TW editions that can be passed to `initByName`. | ||
* | ||
* @param {boolean|undefined} codeMirrorFilter If set to true or false will respectively return editions that | ||
* include Code Mirror or ones that don't. When undefined/left empty it returns all editions. | ||
* | ||
* @returns {string[]} | ||
*/ | ||
static getEditions(codeMirrorFilter = undefined) { | ||
return Object.keys(SUPPORTED_EDITIONS) | ||
.filter(id => { | ||
const edition = SUPPORTED_EDITIONS[id]; | ||
|
||
return codeMirrorFilter === undefined || edition.hasCodeMirror === codeMirrorFilter | ||
}); | ||
} | ||
} | ||
|
||
/** | ||
* Utility to build a list of supported editions. | ||
* | ||
* @param {string} suffix | ||
* @param {string} version | ||
* @param {boolean} hasCodeMirror | ||
* | ||
* @returns {EditionEntry} | ||
*/ | ||
function getEdition(suffix, version, hasCodeMirror) { | ||
return {suffix, version, hasCodeMirror}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,42 @@ | ||
import fs from 'fs'; | ||
import {sep, resolve} from 'path'; | ||
// @ts-check | ||
import { TiddlerStore } from './TiddlerStore'; | ||
|
||
/** | ||
* Handy function to change certain configuration options in TiddlyWiki without having to pass | ||
* tiddler names. | ||
*/ | ||
export class TiddlyWikiConfig { | ||
/** | ||
* @param {import("@playwright/test").Page} page | ||
* @param {import('playwright/test').Page} page | ||
* @param {TiddlerStore} store | ||
*/ | ||
constructor(page, store) { | ||
this.page = page; | ||
this.store = store; | ||
} | ||
|
||
/** | ||
* Created a configurator for another page object. | ||
* @param {import('playwright/test').Page} page | ||
* @returns TiddlyWikiConfig | ||
*/ | ||
forPage(page) { | ||
return new TiddlyWikiConfig(page, this.store.forPage(page)); | ||
} | ||
|
||
/** | ||
* Controls whether framed editor is used or not. | ||
* @param {boolean} bool | ||
*/ | ||
async useFramedEditor(bool) { | ||
this.store.updateTiddler('$:/config/TextEditor/EnableToolbar', {text: bool ? 'yes' : 'no'}, true); | ||
return this.store.updateTiddler('$:/config/TextEditor/EnableToolbar', {text: bool ? 'yes' : 'no'}, true); | ||
} | ||
|
||
/** | ||
* Controls whether Code Mirror's Auto Close Tags plugin is active | ||
* @param {boolean} bool | ||
*/ | ||
async codeMirrorAutoCloseTags(bool) { | ||
this.store.updateTiddler('$:/config/codemirror/autoCloseTags', {text: bool ? 'true' : 'false'}, true); | ||
return this.store.updateTiddler('$:/config/codemirror/autoCloseTags', {text: bool ? 'true' : 'false'}, true); | ||
} | ||
} |
Oops, something went wrong.