diff --git a/eslint.config.mjs b/eslint.config.mjs index 2333270..8a31d75 100644 --- a/eslint.config.mjs +++ b/eslint.config.mjs @@ -3,7 +3,7 @@ import tseslint from 'typescript-eslint'; export default tseslint.config( eslint.configs.recommended, - ...tseslint.configs.recommendedTypeChecked, + ...tseslint.configs.strictTypeChecked, ...tseslint.configs.stylisticTypeChecked, { languageOptions: { @@ -15,22 +15,34 @@ export default tseslint.config( rules: { "@typescript-eslint/consistent-type-assertions": ["error", { assertionStyle: "angle-bracket" }], "@typescript-eslint/prefer-includes": "off", // not in es5 - "@typescript-eslint/prefer-nullish-coalescing": "off", // verbose in es5 - "@typescript-eslint/prefer-optional-chain": "off", // verbose in es5 - "@typescript-eslint/no-inferrable-types": "warn", + "@typescript-eslint/prefer-literal-enum-member": "off", // enums are used as bit flags for clean efficiency + "@typescript-eslint/prefer-nullish-coalescing": "off", // too verbose in es5 + "@typescript-eslint/prefer-optional-chain": "off", // too verbose in es5 + "@typescript-eslint/no-confusing-void-expression": ["error", { ignoreArrowShorthand: true }], + "@typescript-eslint/no-inferrable-types": "warn", "@typescript-eslint/no-unnecessary-condition": "warn", "@typescript-eslint/no-unsafe-enum-comparison": "off", // enums are only used as labelled numbers - "@typescript-eslint/restrict-template-expressions": ["warn", { allowArray: true, allowBoolean: true, allowNullish: true, allowNumber: true }], + "@typescript-eslint/restrict-plus-operands": ["error", { allowNumberAndString: true }], + "@typescript-eslint/restrict-template-expressions": ["error", { allowArray: true, allowBoolean: true, allowNullish: true, allowNumber: true }], "@typescript-eslint/triple-slash-reference": "off", // needed for openrct2 symbols + "@typescript-eslint/unified-signatures": "off", // signatures are split for easier readability + } + }, + { + files: [ + "**/tests/**/*.ts" + ], + rules: { + "@typescript-eslint/dot-notation": "off", // by-passes allowed in tests + "@typescript-eslint/no-non-null-assertion": "off" // allowed in tests } }, { ignores: [ "**/dist/**", "**/lib/**", - "**/tests/**", - "**/rollup.config.js", - "eslint.config.mjs" + "**/*.config.{js,mjs}", + "**/_setup.cjs" ] } ); diff --git a/package.json b/package.json index ae746aa..ba0dc18 100644 --- a/package.json +++ b/package.json @@ -30,13 +30,13 @@ "scripts": { "start": "npm run watch", "watch": "nodemon --watch ./src --ext js,ts --exec \"npm run build:dev\"", - "build": "npm run clean && npm run lint && rollup --config rollup.config.js --environment BUILD:production", + "build": "npm run clean && rollup --config rollup.config.js --environment BUILD:production && npm run lint", "build:dev": "npm run clean && rollup --config rollup.config.js", "build:examples": "npm run for:examples --action=\"run build\"", "install:examples": "npm run for:examples --action=\"install --prefer-offline\"", "install:test-setup": "npm install --prefix ./tests/package/project --prefer-offline --no-audit --no-save", "install:all": "npm run for:all --action=\"install --prefer-offline\"", - "lint": "eslint ./src", + "lint": "eslint", "test": "nyc ava", "version:prerelease": "npm version prerelease --preid=prerelease", "publish:local": "npm run build && npm install --global", diff --git a/rollup.config.js b/rollup.config.js index 1cce885..a61a9eb 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -81,7 +81,12 @@ const config = [ ...(isDev ? {} : { "Log.debug": "//" }) } }), - typescript(), + typescript({ + include: [ + "./lib/**/*.ts", + "./src/**/*.ts", + ] + }), precache(cache.props.props), terser({ compress: { @@ -125,9 +130,8 @@ const config = [ plugins: [ dts({ tsconfig: "./tsconfig.json", - exclude: [ - "./src/**/*.d.ts", - "./tests/**/*" + include: [ + "./src/**/*.ts" ] }) ] diff --git a/src/bindings/binder.ts b/src/bindings/binder.ts index b10fea7..7e039eb 100644 --- a/src/bindings/binder.ts +++ b/src/bindings/binder.ts @@ -1,3 +1,4 @@ +/* eslint-disable @typescript-eslint/no-unnecessary-type-parameters */ import { AnyBindable } from "./anyBindable"; import { TwoWayBindable } from "./twoway/twowayBindable"; @@ -29,8 +30,8 @@ export interface Binder * @param value A store that can be written to for updates. * @param callback An optional callback to be invoked after the callback specified by `key` was invoked. */ - callback(target: T, key: K, value: TwoWayBindable | undefined, callback: ((arg: V) => void) | undefined): void; - callback(target: T, key: K, value: TwoWayBindable | undefined, callback: ((arg: V) => void) | undefined, converter: (...args: P) => V): void; + callback(target: T, key: keyof T, value: TwoWayBindable | undefined, callback: ((arg: V) => void) | undefined): void; + callback(target: T, key: keyof T, value: TwoWayBindable | undefined, callback: ((arg: V) => void) | undefined, converter: (...args: P) => V): void; /** * Reads the specified value and writes it to the target. If the value is a store, a binding diff --git a/src/bindings/stores/compute.ts b/src/bindings/stores/compute.ts index 0831810..93bcb25 100644 --- a/src/bindings/stores/compute.ts +++ b/src/bindings/stores/compute.ts @@ -31,7 +31,7 @@ export function compute(): Store subscribe(stores[idx++], () => { const newComputedValue = getComputedValue(stores, callback); - return dependant.set(newComputedValue); + dependant.set(newComputedValue); }); } return dependant; diff --git a/src/windows/frames/frameContext.ts b/src/windows/frames/frameContext.ts index 946e9a9..258c9d4 100644 --- a/src/windows/frames/frameContext.ts +++ b/src/windows/frames/frameContext.ts @@ -1,3 +1,5 @@ +/* eslint-disable @typescript-eslint/no-unnecessary-type-parameters */ + /** * Defines a context for window or tab events so they can get their widgets by name. */ @@ -18,4 +20,4 @@ export interface FrameContext * Trigger a redraw check for the window or tab to be relayouted in the next tick. */ redraw(): void; -} \ No newline at end of file +} diff --git a/src/windows/frames/frameControl.ts b/src/windows/frames/frameControl.ts index 0b79313..d434f02 100644 --- a/src/windows/frames/frameControl.ts +++ b/src/windows/frames/frameControl.ts @@ -82,6 +82,7 @@ export class FrameControl implements FrameContext, ParentControl(name: string): T | null { const activeWidgets = this._activeWidgets; diff --git a/src/windows/tabs/tabWindow.ts b/src/windows/tabs/tabWindow.ts index 9355d88..041244d 100644 --- a/src/windows/tabs/tabWindow.ts +++ b/src/windows/tabs/tabWindow.ts @@ -60,14 +60,14 @@ export interface TabWindowParams extends BaseWindowParams /** - * Create a new flexiblely designed window that has tabs. An arrow function can be used to create windows to fit a specific viewmodel. + * Create a new flexiblely designed window that has tabs. * * @example * const template = tabwindow({ title: "Hello world!" }) * * template.open() */ -export function tabwindow(params: TabWindowParams): WindowTemplate; +export function tabwindow(params: TabWindowParams): WindowTemplate; /** * Create a new flexiblely designed window that has tabs. An arrow function can be used to create windows to fit a specific viewmodel. * * diff --git a/src/windows/window.ts b/src/windows/window.ts index d4e3cf5..8318e01 100644 --- a/src/windows/window.ts +++ b/src/windows/window.ts @@ -36,9 +36,9 @@ export interface WindowParams extends BaseWindowParams, FlexibleDirectionalLayou * * template.open() */ -export function window(params: WindowParams): WindowTemplate; +export function window(params: WindowParams): WindowTemplate; /** - * Create a new flexiblely designed window with a viewmodel. + * Create a new flexiblely designed window with a viewmodel. An arrow function can be used to create windows to fit a specific viewmodel. * * @example * class MyModel diff --git a/src/windows/windowTemplate.ts b/src/windows/windowTemplate.ts index 32fb015..e944c68 100644 --- a/src/windows/windowTemplate.ts +++ b/src/windows/windowTemplate.ts @@ -3,7 +3,7 @@ import { OpenWindow } from "./openWindow"; /** * A fully created and compressed window template that can now be used. */ -export interface WindowTemplate +export interface WindowTemplate { /** * Opens this window on-screen with the specified details. diff --git a/tests/bindings/isStore.tests.ts b/tests/bindings/isStore.tests.ts index 0c3c595..2f1901e 100644 --- a/tests/bindings/isStore.tests.ts +++ b/tests/bindings/isStore.tests.ts @@ -1,4 +1,3 @@ -/* eslint-disable @typescript-eslint/explicit-function-return-type */ /// import { compute } from "@src/bindings/stores/compute"; import { arrayStore } from "@src/bindings/stores/createArrayStore"; diff --git a/tests/elements/controls/box.tests.ts b/tests/elements/controls/box.tests.ts index 47f5cc3..b0f8a1a 100644 --- a/tests/elements/controls/box.tests.ts +++ b/tests/elements/controls/box.tests.ts @@ -30,14 +30,14 @@ test("Standard properties are set", t => }); template.open(); - const widget1 = mock.createdWindows[0].widgets[0] as GroupBoxWidget; + const widget1 = mock.createdWindows[0].widgets[0]; t.is(widget1.type, "groupbox"); t.is(widget1.x, 4 + 7); t.is(widget1.y, 4 + 7 + 15 - 4); // - 4px default top pad t.is(widget1.width, 50 - 22); t.is(widget1.height, (40 - 22) + 4); // + 4px default top pad - const widget2 = mock.createdWindows[0].widgets[1] as ButtonWidget; + const widget2 = mock.createdWindows[0].widgets[1]; t.is(widget2.type, "button"); t.is(widget2.text, "inside a box!"); t.is(widget2.x, 4 + 7 + 6); // incl. 6px default padding @@ -66,7 +66,7 @@ test("Title changes size and position", t => }); template.open(); - const widget1 = mock.createdWindows[0].widgets[0] as GroupBoxWidget; + const widget1 = mock.createdWindows[0].widgets[0]; t.is(widget1.type, "groupbox"); t.is(widget1.text, "title"); t.is(widget1.x, 4 + 7); @@ -74,7 +74,7 @@ test("Title changes size and position", t => t.is(widget1.width, 50 - 22); t.is(widget1.height, 80 - 22); - const widget2 = mock.createdWindows[0].widgets[1] as ButtonWidget; + const widget2 = mock.createdWindows[0].widgets[1]; t.is(widget2.type, "button"); t.is(widget2.text, "inside a box!"); t.is(widget2.x, 4 + 7 + 6); // incl. 6px default padding @@ -103,14 +103,14 @@ test("Applies padding", t => }); template.open(); - const widget1 = mock.createdWindows[0].widgets[0] as GroupBoxWidget; + const widget1 = mock.createdWindows[0].widgets[0]; t.is(widget1.type, "groupbox"); t.is(widget1.x, 10 + 3); t.is(widget1.y, 10 + 3 + 15 - 4); // - 4px default top pad t.is(widget1.width, 74); t.is(widget1.height, 34 + 4); // + 4px default top pad - const widget2 = mock.createdWindows[0].widgets[1] as ButtonWidget; + const widget2 = mock.createdWindows[0].widgets[1]; t.is(widget2.type, "button"); t.is(widget2.text, "inside a box!"); t.is(widget2.x, 10 + 3 + 6); @@ -139,14 +139,14 @@ test("Box takes size of absolute child", t => }); template.open(); - const widget1 = mock.createdWindows[0].widgets[0] as GroupBoxWidget; + const widget1 = mock.createdWindows[0].widgets[0]; t.is(widget1.type, "groupbox"); t.is(widget1.x, 10); t.is(widget1.y, 10 + 15 - 4); // - 4px default top pad t.is(widget1.width, 120 + 24); t.is(widget1.height, 70 + 24 + 4); // + 4px default top pad - const widget2 = mock.createdWindows[0].widgets[1] as ButtonWidget; + const widget2 = mock.createdWindows[0].widgets[1]; t.is(widget2.type, "button"); t.is(widget2.text, "inside a box!"); t.is(widget2.x, 10 + 12); @@ -174,14 +174,14 @@ test("Box can center child", t => }); template.open(); - const widget1 = mock.createdWindows[0].widgets[0] as GroupBoxWidget; + const widget1 = mock.createdWindows[0].widgets[0]; t.is(widget1.type, "groupbox"); t.is(widget1.x, 40); t.is(widget1.y, 40 + 15 - 4); t.is(widget1.width, 100); t.is(widget1.height, 320 + 4); - const widget2 = mock.createdWindows[0].widgets[1] as ButtonWidget; + const widget2 = mock.createdWindows[0].widgets[1]; t.is(widget2.type, "button"); t.is(widget2.text, "inside a box!"); t.is(widget2.x, 40); @@ -212,7 +212,7 @@ test("Box reacts correctly to child size changes", t => }); template.open(); - const widget1 = mock.createdWindows[0].widgets[0] as GroupBoxWidget; + const widget1 = mock.createdWindows[0].widgets[0]; t.is(widget1.type, "groupbox"); t.is(widget1.x, 4); t.is(widget1.y, 4 + 15 - 4); // - 4px default top pad @@ -220,7 +220,7 @@ test("Box reacts correctly to child size changes", t => t.is(widget1.height, 14 + (2 * 6) + 4); // + 4px default top pad t.not(false, widget1.isVisible); - const widget2 = mock.createdWindows[0].widgets[1] as LabelWidget; + const widget2 = mock.createdWindows[0].widgets[1]; t.is(widget2.type, "label"); t.is(widget2.text, "managing themes"); t.is(widget2.x, 4 + 6); @@ -279,7 +279,7 @@ test("Box reacts correctly to nested child size changes", t => }); template.open(); - const widget1 = mock.createdWindows[0].widgets[0] as GroupBoxWidget; + const widget1 = mock.createdWindows[0].widgets[0]; t.is(widget1.type, "groupbox"); t.is(widget1.x, 20); t.is(widget1.y, 20 + 15 - 4); // - 4px default top pad @@ -287,7 +287,7 @@ test("Box reacts correctly to nested child size changes", t => t.is(widget1.height, 14 + (2 * 6) + 4); // + 4px default top pad t.true(widget1.isVisible); - const widget2 = mock.createdWindows[0].widgets[1] as LabelWidget; + const widget2 = mock.createdWindows[0].widgets[1]; t.is(widget2.type, "label"); t.is(widget2.text, "managing themes"); t.is(widget2.x, 20 + 6); @@ -296,7 +296,7 @@ test("Box reacts correctly to nested child size changes", t => t.is(widget2.height, 14); t.true(widget2.isVisible); - const widget3 = mock.createdWindows[0].widgets[2] as ButtonWidget; + const widget3 = mock.createdWindows[0].widgets[2]; t.is(widget3.type, "button"); t.is(widget3.x, 20); t.is(widget3.y, 20 + (2 * 6) + 4 + 14 + 15); @@ -363,9 +363,9 @@ test("Box does not take space if it starts hidden", t => }); template.open(); - const widget1 = mock.createdWindows[0].widgets[0] as GroupBoxWidget; - const widget2 = mock.createdWindows[0].widgets[1] as LabelWidget; - const widget3 = mock.createdWindows[0].widgets[2] as ButtonWidget; + const widget1 = mock.createdWindows[0].widgets[0]; + const widget2 = mock.createdWindows[0].widgets[1]; + const widget3 = mock.createdWindows[0].widgets[2]; t.false(widget1.isVisible); t.false(widget2.isVisible); @@ -398,4 +398,4 @@ test("Box does not take space if it starts hidden", t => t.is(widget3.y, 20 + (2 * 6) + 4 + 14 + 15); t.is(widget3.width, 300 - (2 * 20)); t.is(widget3.height, 25); -}); \ No newline at end of file +}); diff --git a/tests/elements/controls/button.tests.ts b/tests/elements/controls/button.tests.ts index c8cda56..2269613 100644 --- a/tests/elements/controls/button.tests.ts +++ b/tests/elements/controls/button.tests.ts @@ -1,8 +1,8 @@ /// import { store } from "@src/bindings/stores/createStore"; -import { window } from "@src/windows/window"; import { button } from "@src/elements/controls/button"; +import { window } from "@src/windows/window"; import test from "ava"; import Mock from "openrct2-mocks"; import { call } from "tests/helpers"; @@ -21,7 +21,7 @@ test("Standard properties are set", t => }); template.open(); - const widget = mock.createdWindows[0].widgets[0] as ButtonWidget; + const widget = mock.createdWindows[0].widgets[0]; t.is(widget.type, "button"); t.is(widget.text, "Click me!"); t.true(widget.isPressed); @@ -43,7 +43,7 @@ test("Text is bindable", t => }); template.open(); - const widget = mock.createdWindows[0].widgets[0] as ButtonWidget; + const widget = mock.createdWindows[0].widgets[0]; t.is(widget.text, "bonjour"); text.set("annyeong"); @@ -65,7 +65,7 @@ test("Image is bindable", t => }); template.open(); - const widget = mock.createdWindows[0].widgets[0] as ButtonWidget; + const widget = mock.createdWindows[0].widgets[0]; t.is(widget.image, 334); image.set(543); @@ -87,7 +87,7 @@ test("Is pressed is bindable", t => }); template.open(); - const widget = mock.createdWindows[0].widgets[0] as ButtonWidget; + const widget = mock.createdWindows[0].widgets[0]; t.false(widget.isPressed); pressed.set(true); @@ -109,7 +109,7 @@ test("Click event gets called", t => }); template.open(); - const widget = mock.createdWindows[0].widgets[0] as ButtonDesc; + const widget = mock.createdWindows[0].widgets[0]; t.is(count, 0); call(widget.onClick); diff --git a/tests/elements/controls/checkbox.tests.ts b/tests/elements/controls/checkbox.tests.ts index 1f89c83..52b2ab7 100644 --- a/tests/elements/controls/checkbox.tests.ts +++ b/tests/elements/controls/checkbox.tests.ts @@ -26,7 +26,7 @@ test("Standard properties are set", t => }); template.open(); - const widget = mock.createdWindows[0].widgets[0] as CheckboxWidget; + const widget = mock.createdWindows[0].widgets[0]; t.is(widget.type, "checkbox"); t.is(widget.text, "Check me out"); t.is(widget.tooltip, "checkable!"); @@ -48,7 +48,7 @@ test("Change event gets called", t => }); template.open(); - const widget = mock.createdWindows[0].widgets[0] as CheckboxDesc; + const widget = mock.createdWindows[0].widgets[0]; call(widget.onChange, true); call(widget.onChange, false); call(widget.onChange, true); @@ -74,7 +74,7 @@ test("One-way bindings update checkbox", t => }); template.open(); - const widget = mock.createdWindows[0].widgets[0] as CheckboxDesc; + const widget = mock.createdWindows[0].widgets[0]; t.true(widget.isChecked); t.is(widget.text, "Hello"); t.falsy(widget.onChange); // not assigned @@ -112,7 +112,7 @@ test("Two-way bindings update checkbox", t => }); template.open(); - const widget = mock.createdWindows[0].widgets[0] as CheckboxDesc; + const widget = mock.createdWindows[0].widgets[0]; t.false(widget.isChecked); t.false(isChecked.get()); t.deepEqual(hits, []); @@ -136,4 +136,4 @@ test("Two-way bindings update checkbox", t => t.false(widget.isChecked); t.false(isChecked.get()); t.deepEqual(hits, [ false, true ]); -}); \ No newline at end of file +}); diff --git a/tests/elements/controls/colourPicker.tests.ts b/tests/elements/controls/colourPicker.tests.ts index 0ed8064..7b87e2a 100644 --- a/tests/elements/controls/colourPicker.tests.ts +++ b/tests/elements/controls/colourPicker.tests.ts @@ -1,4 +1,3 @@ -/* eslint-disable @typescript-eslint/no-non-null-assertion */ /// import { store } from "@src/bindings/stores/createStore"; @@ -25,7 +24,7 @@ test("Standard properties are set", t => }); template.open(); - const widget = mock.createdWindows[0].widgets[0] as ColourPickerWidget; + const widget = mock.createdWindows[0].widgets[0]; t.is(widget.type, "colourpicker"); t.is(widget.colour, Colour.BrightYellow); t.is(widget.tooltip, "colourable!"); @@ -46,7 +45,7 @@ test("Colour is bindable", t => }); template.open(); - const widget = mock.createdWindows[0].widgets[0] as ColourPickerWidget; + const widget = mock.createdWindows[0].widgets[0]; t.is(widget.colour, Colour.Aquamarine); colour.set(Colour.OliveGreen); @@ -68,7 +67,7 @@ test("Change event gets called", t => }); template.open(); - const widget = mock.createdWindows[0].widgets[0] as ColourPickerDesc; + const widget = mock.createdWindows[0].widgets[0]; call(widget.onChange, Colour.IcyBlue); call(widget.onChange, Colour.Black); call(widget.onChange, Colour.LightPink); @@ -96,7 +95,7 @@ test("Assigning bound colour should silence on change", t => }); template.open(); - const widget = mock.createdWindows[0].widgets[0] as ColourPickerDesc; + const widget = mock.createdWindows[0].widgets[0]; proxy(widget, "colour", v => call(widget.onChange, v!)); // immitate the ingame bubbled callback t.is(widget.colour, 20); @@ -128,7 +127,7 @@ test("Two-way bindings update colour picker", t => }); template.open(); - const widget = mock.createdWindows[0].widgets[0] as ColourPickerDesc; + const widget = mock.createdWindows[0].widgets[0]; t.is(widget.colour, Colour.BrightPurple); t.is(colour.get(), Colour.BrightPurple); t.deepEqual(hits, []); @@ -152,4 +151,4 @@ test("Two-way bindings update colour picker", t => t.is(widget.colour, Colour.SaturatedGreen); t.is(colour.get(), Colour.SaturatedGreen); t.deepEqual(hits, [ Colour.Teal, Colour.DarkPink ]); -}); \ No newline at end of file +}); diff --git a/tests/elements/controls/dropdown.tests.ts b/tests/elements/controls/dropdown.tests.ts index 65ebc07..cbbd42d 100644 --- a/tests/elements/controls/dropdown.tests.ts +++ b/tests/elements/controls/dropdown.tests.ts @@ -1,5 +1,3 @@ -/* eslint-disable @typescript-eslint/no-non-null-assertion */ -/* eslint-disable @typescript-eslint/no-explicit-any */ /// import { store } from "@src/bindings/stores/createStore"; @@ -25,7 +23,7 @@ test("Standard properties are set", t => }); template.open(); - const widget = mock.createdWindows[0].widgets[0] as DropdownWidget; + const widget = mock.createdWindows[0].widgets[0]; t.is(widget.type, "dropdown"); t.deepEqual(widget.items, [ "a", "b", "c" ]); t.is(widget.selectedIndex, 2); @@ -47,7 +45,7 @@ test("Items are bindable", t => }); template.open(); - const widget = mock.createdWindows[0].widgets[0] as DropdownWidget; + const widget = mock.createdWindows[0].widgets[0]; t.deepEqual(widget.items, [ "a", "b", "c" ]); items.set([ "q", "p" ]); @@ -69,7 +67,7 @@ test("Selected index is bindable", t => }); template.open(); - const widget = mock.createdWindows[0].widgets[0] as DropdownWidget; + const widget = mock.createdWindows[0].widgets[0]; t.is(widget.selectedIndex, 2); selected.set(1); @@ -94,7 +92,7 @@ test("Select event gets called", t => }); template.open(); - const widget = mock.createdWindows[0].widgets[0] as DropdownDesc; + const widget = mock.createdWindows[0].widgets[0]; call(widget.onChange, 1); call(widget.onChange, 2); call(widget.onChange, 0); @@ -118,7 +116,7 @@ test("Disable message shows when disabled", t => }); template.open(); - const widget = mock.createdWindows[0].widgets[0] as DropdownWidget; + const widget = mock.createdWindows[0].widgets[0]; t.deepEqual(widget.items, [ "a", "b" ]); disabled.set(true); @@ -142,7 +140,7 @@ test("Disable message shows when always disabled", t => }); template.open(); - const widget = mock.createdWindows[0].widgets[0] as DropdownWidget; + const widget = mock.createdWindows[0].widgets[0]; t.deepEqual(widget.items, [ "Sorry!" ]); }); @@ -160,7 +158,7 @@ test("Disable message doesn't show when always enabled", t => }); template.open(); - const widget = mock.createdWindows[0].widgets[0] as DropdownWidget; + const widget = mock.createdWindows[0].widgets[0]; t.deepEqual(widget.items, [ "a", "b" ]); }); @@ -181,7 +179,7 @@ test("Disable message shows with items and disabled stores", t => }); template.open(); - const widget = mock.createdWindows[0].widgets[0] as DropdownWidget; + const widget = mock.createdWindows[0].widgets[0]; t.deepEqual(widget.items, []); t.false(widget.isDisabled); @@ -220,7 +218,7 @@ test("Auto disable on single item disables when just one item", t => }); template.open(); - const widget = mock.createdWindows[0].widgets[0] as DropdownWidget; + const widget = mock.createdWindows[0].widgets[0]; t.true(widget.isDisabled); }); @@ -238,7 +236,7 @@ test("Auto disable on single item enabled when more than one item", t => }); template.open(); - const widget = mock.createdWindows[0].widgets[0] as DropdownWidget; + const widget = mock.createdWindows[0].widgets[0]; t.false(widget.isDisabled); }); @@ -256,7 +254,7 @@ test("Auto disable on empty disables when empty", t => }); template.open(); - const widget = mock.createdWindows[0].widgets[0] as DropdownWidget; + const widget = mock.createdWindows[0].widgets[0]; t.true(widget.isDisabled); }); @@ -274,7 +272,7 @@ test("Auto disable on empty enabled when at least one item", t => }); template.open(); - const widget = mock.createdWindows[0].widgets[0] as DropdownWidget; + const widget = mock.createdWindows[0].widgets[0]; t.false(widget.isDisabled); }); @@ -292,7 +290,7 @@ test("Auto disable on never is never disabled", t => }); template.open(); - const widget = mock.createdWindows[0].widgets[0] as DropdownWidget; + const widget = mock.createdWindows[0].widgets[0]; t.falsy(widget.isDisabled); }); @@ -317,7 +315,7 @@ test("Invoke on change if item is at different index in new list", t => }); template.open(); - const widget = mock.createdWindows[0].widgets[0] as DropdownDesc; + const widget = mock.createdWindows[0].widgets[0]; proxy(widget, "selectedIndex", v => call(widget.onChange, v!)); // immitate the ingame bubbled callback t.deepEqual(widget.items, [ "a", "b", "c", "d" ]); @@ -360,7 +358,7 @@ test("Do not change selected index if item at same index in new list", t => }); template.open(); - const widget = mock.createdWindows[0].widgets[0] as DropdownDesc; + const widget = mock.createdWindows[0].widgets[0]; proxy(widget, "selectedIndex", v => call(widget.onChange, v!)); // immitate the ingame bubbled callback t.deepEqual(widget.items, [ "a", "b", "c", "d" ]); @@ -393,7 +391,7 @@ test("Reset selected index if item not present in new list", t => }); template.open(); - const widget = mock.createdWindows[0].widgets[0] as DropdownDesc; + const widget = mock.createdWindows[0].widgets[0]; proxy(widget, "selectedIndex", v => call(widget.onChange, v!)); // immitate the ingame bubbled callback t.deepEqual(widget.items, [ "a", "b", "c", "d" ]); @@ -425,7 +423,7 @@ test("Assigning bound selected index should silence on change", t => }); template.open(); - const widget = mock.createdWindows[0].widgets[0] as DropdownDesc; + const widget = mock.createdWindows[0].widgets[0]; proxy(widget, "selectedIndex", v => call(widget.onChange, v!)); // immitate the ingame bubbled callback t.is(widget.selectedIndex, 1); @@ -456,7 +454,7 @@ test("Assigning bound items should silence on change", t => }); template.open(); - const widget = mock.createdWindows[0].widgets[0] as DropdownDesc; + const widget = mock.createdWindows[0].widgets[0]; proxy(widget, "items", () => call(widget.onChange, 0)); // immitate the ingame bubbled callback t.deepEqual(widget.items, [ "a", "b", "c" ]); @@ -488,7 +486,7 @@ test("Items and selected index gets restored when disabled dropdown with message }); template.open(); - const widget = mock.createdWindows[0].widgets[0] as DropdownDesc; + const widget = mock.createdWindows[0].widgets[0]; proxy(widget, "items", () => widget.selectedIndex = 0); // immitate the ingame selected reset t.is(widget.selectedIndex, 2); @@ -525,7 +523,7 @@ test("Dropdown items changed but new selected index should stay the same", t => }); template.open(); - const widget = mock.createdWindows[0].widgets[0] as DropdownDesc; + const widget = mock.createdWindows[0].widgets[0]; proxy(widget, "items", () => call(widget.onChange, 0)); // immitate the ingame bubbled callback proxy(widget, "selectedIndex", i => call(widget.onChange, i!)); // immitate the ingame bubbled callback @@ -568,7 +566,7 @@ test("Two-way bindings update dropdown", t => }); template.open(); - const widget = mock.createdWindows[0].widgets[0] as DropdownDesc; + const widget = mock.createdWindows[0].widgets[0]; t.is(widget.selectedIndex, 1); t.is(selectedIndex.get(), 1); t.deepEqual(hits, []); @@ -592,4 +590,4 @@ test("Two-way bindings update dropdown", t => t.is(widget.selectedIndex, 0); t.is(selectedIndex.get(), 0); t.deepEqual(hits, [ 0, 2 ]); -}); \ No newline at end of file +}); diff --git a/tests/elements/controls/dropdownButton.tests.ts b/tests/elements/controls/dropdownButton.tests.ts index 67dc866..e47ccea 100644 --- a/tests/elements/controls/dropdownButton.tests.ts +++ b/tests/elements/controls/dropdownButton.tests.ts @@ -1,7 +1,7 @@ /// -import { window } from "@src/windows/window"; import { dropdownButton } from "@src/elements/controls/dropdownButton"; +import { window } from "@src/windows/window"; import test from "ava"; import Mock from "openrct2-mocks"; import { call } from "tests/helpers"; @@ -24,12 +24,12 @@ test("Standard properties are set", t => template.open(); const created = mock.createdWindows[0]; - const dropdown = created.widgets[0] as DropdownDesc; + const dropdown = created.widgets[0]; t.is(dropdown.type, "dropdown"); t.deepEqual(dropdown.items, [ "a", "b" ]); t.is(dropdown.tooltip, "hello!"); - const button = created.widgets[1] as ButtonDesc; + const button = created.widgets[1]; t.is(button.type, "button"); t.is(button.text, "a"); t.is(button.tooltip, "hello!"); @@ -52,8 +52,8 @@ test("Dropdown updates button", t => template.open(); const created = mock.createdWindows[0]; - const dropdown = created.widgets[0] as DropdownDesc; - const button = created.widgets[1] as ButtonDesc; + const dropdown = created.widgets[0]; + const button = created.widgets[1]; t.is(button.text, "a"); call(dropdown.onChange, 2); @@ -85,8 +85,8 @@ test("Button onClick's are called", t => template.open(); const created = mock.createdWindows[0]; - const dropdown = created.widgets[0] as DropdownDesc; - const button = created.widgets[1] as ButtonDesc; + const dropdown = created.widgets[0]; + const button = created.widgets[1]; call(button.onClick); t.deepEqual(hits, [ "a" ]); @@ -118,8 +118,8 @@ test("Dropdown allows empty list", t => template.open(); const created = mock.createdWindows[0]; - const dropdown = created.widgets[0] as DropdownDesc; - const button = created.widgets[1] as ButtonDesc; + const dropdown = created.widgets[0]; + const button = created.widgets[1]; t.is(button.text, ""); call(button.onClick); @@ -130,4 +130,4 @@ test("Dropdown allows empty list", t => call(dropdown.onChange, 1); t.is(button.text, ""); call(button.onClick); -}); \ No newline at end of file +}); diff --git a/tests/elements/controls/dropdownSpinner.tests.ts b/tests/elements/controls/dropdownSpinner.tests.ts index 770bc2a..1e7b7e3 100644 --- a/tests/elements/controls/dropdownSpinner.tests.ts +++ b/tests/elements/controls/dropdownSpinner.tests.ts @@ -23,12 +23,12 @@ test("Standard properties are set", t => template.open(); const created = mock.createdWindows[0]; - const spinner = created.widgets[0] as SpinnerDesc; + const spinner = created.widgets[0]; t.is(spinner.type, "spinner"); t.is(spinner.text, "0"); t.is(spinner.tooltip, "spin me"); - const dropdown = created.widgets[1] as DropdownDesc; + const dropdown = created.widgets[1]; t.is(dropdown.type, "dropdown"); t.deepEqual(dropdown.items, [ "a", "b", "c" ]); t.is(dropdown.selectedIndex, 0); @@ -50,8 +50,8 @@ test("Dropdown updates spinner", t => template.open(); const created = mock.createdWindows[0]; - const spinner = created.widgets[0] as SpinnerDesc; - const dropdown = created.widgets[1] as DropdownDesc; + const spinner = created.widgets[0]; + const dropdown = created.widgets[1]; t.is(spinner.text, "0"); call(dropdown.onChange, 2); @@ -76,8 +76,8 @@ test("Spinner updates dropdown", t => template.open(); const created = mock.createdWindows[0]; - const spinner = created.widgets[0] as SpinnerDesc; - const dropdown = created.widgets[1] as DropdownDesc; + const spinner = created.widgets[0]; + const dropdown = created.widgets[1]; t.is(dropdown.selectedIndex, 0); call(spinner.onIncrement); @@ -108,8 +108,8 @@ test("Spinner allows empty item list", t => template.open(); const created = mock.createdWindows[0]; - const spinner = created.widgets[0] as SpinnerDesc; - const dropdown = created.widgets[1] as DropdownDesc; + const spinner = created.widgets[0]; + const dropdown = created.widgets[1]; t.is(dropdown.selectedIndex, 0); call(spinner.onIncrement); @@ -141,8 +141,8 @@ test("Two-way bindings update dropdown spinner", t => template.open(); const created = mock.createdWindows[0]; - const spinner = created.widgets[0] as SpinnerDesc; - const dropdown = created.widgets[1] as DropdownDesc; + const spinner = created.widgets[0]; + const dropdown = created.widgets[1]; t.is(dropdown.selectedIndex, 1); t.is(selectedIndex.get(), 1); t.deepEqual(hits, []); @@ -166,4 +166,4 @@ test("Two-way bindings update dropdown spinner", t => t.is(dropdown.selectedIndex, 0); t.is(selectedIndex.get(), 0); t.deepEqual(hits, [ 1, 2 ]); -}); \ No newline at end of file +}); diff --git a/tests/elements/controls/groupbox.tests.ts b/tests/elements/controls/groupbox.tests.ts index 1800df4..c7a9321 100644 --- a/tests/elements/controls/groupbox.tests.ts +++ b/tests/elements/controls/groupbox.tests.ts @@ -35,14 +35,14 @@ test("Standard properties are set", t => }); template.open(); - const widget1 = mock.createdWindows[0].widgets[0] as GroupBoxWidget; + const widget1 = mock.createdWindows[0].widgets[0]; t.is(widget1.type, "groupbox"); t.is(widget1.x, 4 + 7); t.is(widget1.y, 4 + 7 + 15); t.is(widget1.width, 28); t.is(widget1.height, 18); - const widget2 = mock.createdWindows[0].widgets[1] as ButtonWidget; + const widget2 = mock.createdWindows[0].widgets[1]; t.is(widget2.type, "button"); t.is(widget2.text, "inside a box!"); t.is(widget2.x, 4 + 7 + 3); @@ -50,7 +50,7 @@ test("Standard properties are set", t => t.is(widget2.width, 8); t.is(widget2.height, 12); - const widget3 = mock.createdWindows[0].widgets[2] as ButtonWidget; + const widget3 = mock.createdWindows[0].widgets[2]; t.is(widget3.type, "button"); t.is(widget3.text, "also in the box!"); t.is(widget3.x, 4 + 7 + 3 + 8 + 6); // incl. 6px spacing @@ -87,14 +87,14 @@ test("Groupbox applies padding and default gap", t => }); template.open(); - const widget1 = mock.createdWindows[0].widgets[0] as GroupBoxWidget; + const widget1 = mock.createdWindows[0].widgets[0]; t.is(widget1.type, "groupbox"); t.is(widget1.x, 10 + 3); t.is(widget1.y, 10 + 3 + 15 - 4); // - default top pad t.is(widget1.width, 74); t.is(widget1.height, 54 + 4); // + default top pad - const widget2 = mock.createdWindows[0].widgets[1] as ButtonWidget; + const widget2 = mock.createdWindows[0].widgets[1]; t.is(widget2.type, "button"); t.is(widget2.text, "inside a box!"); t.is(widget2.x, 10 + 3 + 6 + 6); // inc. 6px default gap @@ -102,7 +102,7 @@ test("Groupbox applies padding and default gap", t => t.is(widget2.width, 50); t.is(widget2.height, 13); - const widget3 = mock.createdWindows[0].widgets[2] as ButtonWidget; + const widget3 = mock.createdWindows[0].widgets[2]; t.is(widget3.type, "button"); t.is(widget3.text, "labelled"); t.is(widget3.x, 10 + 3 + 6 + 1); // inc. 6px default gap @@ -138,14 +138,14 @@ test("Groupbox takes size of absolute child", t => }); template.open(); - const widget1 = mock.createdWindows[0].widgets[0] as GroupBoxWidget; + const widget1 = mock.createdWindows[0].widgets[0]; t.is(widget1.type, "groupbox"); t.is(widget1.x, 10); t.is(widget1.y, 10 + 15 - 4); // - default top pad t.is(widget1.width, 120 + 24 + 6); // inc. gap t.is(widget1.height, 70 + 24 + 6 + 30 + 10 + 4 + 4); // + default top pad - const widget2 = mock.createdWindows[0].widgets[1] as ButtonWidget; + const widget2 = mock.createdWindows[0].widgets[1]; t.is(widget2.type, "button"); t.is(widget2.text, "inside a box!"); t.is(widget2.x, 10 + 3 + 12); @@ -153,7 +153,7 @@ test("Groupbox takes size of absolute child", t => t.is(widget2.width, 120); t.is(widget2.height, 70); - const widget3 = mock.createdWindows[0].widgets[2] as ButtonWidget; + const widget3 = mock.createdWindows[0].widgets[2]; t.is(widget3.type, "button"); t.is(widget3.text, "inside a box too!"); t.is(widget3.x, 10 + 3 + 5); @@ -189,14 +189,14 @@ test("Groupbox uses default fallback padding for gap", t => }); template.open(); - const widget1 = mock.createdWindows[0].widgets[0] as GroupBoxWidget; + const widget1 = mock.createdWindows[0].widgets[0]; t.is(widget1.type, "groupbox"); t.is(widget1.x, 10); t.is(widget1.y, 10 + 15 - 4); // - default top pad t.is(widget1.width, 120 + 6 + 6); // inc. gap t.is(widget1.height, 415 - (15 + 10 + 6)); // + default top pad - const widget2 = mock.createdWindows[0].widgets[1] as ButtonWidget; + const widget2 = mock.createdWindows[0].widgets[1]; t.is(widget2.type, "button"); t.is(widget2.text, "inside a box!"); t.is(widget2.x, 10 + 6); // 6px default padding @@ -204,7 +204,7 @@ test("Groupbox uses default fallback padding for gap", t => t.is(widget2.width, 120); t.is(widget2.height, 70); - const widget3 = mock.createdWindows[0].widgets[2] as ButtonWidget; + const widget3 = mock.createdWindows[0].widgets[2]; t.is(widget3.type, "button"); t.is(widget3.text, "inside a box too!"); t.is(widget3.x, 10 + 6); // 6px default padding @@ -234,14 +234,14 @@ test("Groupbox has correct size with padding in flex layout", t => }); template.open(); - const widget1 = mock.createdWindows[0].widgets[0] as GroupBoxWidget; + const widget1 = mock.createdWindows[0].widgets[0]; t.is(widget1.type, "groupbox"); t.is(widget1.x, 5 + 15); t.is(widget1.y, (5 + 15 + 15) - 4); // - default top pad t.is(widget1.width, 150 - (10 + 30)); t.is(widget1.height, 20 + 12 + 4); // + default top pad - const widget2 = mock.createdWindows[0].widgets[1] as ButtonWidget; + const widget2 = mock.createdWindows[0].widgets[1]; t.is(widget2.type, "button"); t.is(widget2.text, "click"); t.is(widget2.x, 5 + 15 + 6); @@ -249,11 +249,11 @@ test("Groupbox has correct size with padding in flex layout", t => t.is(widget2.width, 150 - (10 + 30 + 12)); t.is(widget2.height, 20); - const widget3 = mock.createdWindows[0].widgets[2] as ButtonWidget; + const widget3 = mock.createdWindows[0].widgets[2]; t.is(widget3.type, "button"); t.is(widget3.text, "press"); t.is(widget3.x, 5); t.is(widget3.y, 5 + 30 + 12 + 20 + 2 + 15); t.is(widget3.width, 150 - 10); t.is(widget3.height, 200 - (10 + 2 + 30 + 12 + 20 + 15)); -}); \ No newline at end of file +}); diff --git a/tests/elements/controls/label.tests.ts b/tests/elements/controls/label.tests.ts index 6be7999..4cec1ac 100644 --- a/tests/elements/controls/label.tests.ts +++ b/tests/elements/controls/label.tests.ts @@ -25,7 +25,7 @@ test("Standard properties are set", t => template.open(); - const widget = mock.createdWindows[0].widgets[0] as LabelWidget; + const widget = mock.createdWindows[0].widgets[0]; t.is(widget.type, "label"); t.is(widget.text, "static"); t.is(widget.textAlign, "centred"); @@ -48,7 +48,7 @@ test("Text is bindable", t => const instance1 = template.open(); - const label1 = mock.createdWindows[0].widgets[0] as LabelWidget; + const label1 = mock.createdWindows[0].widgets[0]; t.is(label1.text, "Hello"); text.set("Bye"); @@ -58,7 +58,7 @@ test("Text is bindable", t => text.set("Still there"); template.open(); - const label2 = mock.createdWindows[0].widgets[0] as LabelWidget; + const label2 = mock.createdWindows[0].widgets[0]; t.is(label2.text, "Still there"); }); @@ -78,7 +78,7 @@ test("Alignment is bindable", t => const instance1 = template.open(); - const label1 = mock.createdWindows[0].widgets[0] as LabelWidget; + const label1 = mock.createdWindows[0].widgets[0]; t.is(label1.textAlign, "centred"); alignment.set("left"); @@ -88,6 +88,6 @@ test("Alignment is bindable", t => alignment.set("centred"); template.open(); - const label2 = mock.createdWindows[0].widgets[0] as LabelWidget; + const label2 = mock.createdWindows[0].widgets[0]; t.is(label2.textAlign, "centred"); }); diff --git a/tests/elements/controls/listview.tests.ts b/tests/elements/controls/listview.tests.ts index c63eb8a..80c595e 100644 --- a/tests/elements/controls/listview.tests.ts +++ b/tests/elements/controls/listview.tests.ts @@ -50,7 +50,7 @@ test("Standard properties are set", t => template.open(); - const widget = mock.createdWindows[0].widgets[0] as ListViewWidget; + const widget = mock.createdWindows[0].widgets[0]; t.is(widget.type, "listview"); t.is(widget.scrollbars, "both"); t.deepEqual(widget.selectedCell, { row: 2, column: 1 }); @@ -107,7 +107,7 @@ test("Simple column names get converted", t => template.open(); - const widget = mock.createdWindows[0].widgets[0] as ListViewWidget; + const widget = mock.createdWindows[0].widgets[0]; t.is(widget.type, "listview"); t.is(widget.scrollbars, "vertical"); t.true(widget.showColumnHeaders); @@ -161,7 +161,7 @@ test("Items is bindable", t => const instance1 = template.open(); - const listview1 = mock.createdWindows[0].widgets[0] as ListViewWidget; + const listview1 = mock.createdWindows[0].widgets[0]; t.deepEqual(listview1.items, [ "Hello", "world" ]); items.set([ "Bye", "friendly", "friend" ]); @@ -171,7 +171,7 @@ test("Items is bindable", t => items.set([ "Still", "there" ]); template.open(); - const listview2 = mock.createdWindows[0].widgets[0] as ListViewWidget; + const listview2 = mock.createdWindows[0].widgets[0]; t.deepEqual(listview2.items, [ "Still", "there" ]); }); @@ -191,7 +191,7 @@ test("Show column headers is false without columns", t => template.open(); - const listview1 = mock.createdWindows[0].widgets[0] as ListViewWidget; + const listview1 = mock.createdWindows[0].widgets[0]; t.false(listview1.showColumnHeaders); t.falsy(listview1.columns); }); @@ -213,7 +213,7 @@ test("Show column headers is true with empty column array", t => template.open(); - const listview1 = mock.createdWindows[0].widgets[0] as ListViewWidget; + const listview1 = mock.createdWindows[0].widgets[0]; t.true(listview1.showColumnHeaders); t.deepEqual(listview1.columns, []); }); @@ -239,7 +239,7 @@ test("Built-in ratio width colums map correctly", t => template.open(); - const listview1 = mock.createdWindows[0].widgets[0] as ListViewWidget; + const listview1 = mock.createdWindows[0].widgets[0]; t.true(listview1.showColumnHeaders); const columns = listview1.columns; @@ -270,7 +270,7 @@ test("Custom colum params with mixed widths map correctly", t => template.open(); - const listview1 = mock.createdWindows[0].widgets[0] as ListViewWidget; + const listview1 = mock.createdWindows[0].widgets[0]; t.true(listview1.showColumnHeaders); const columns = listview1.columns; @@ -319,7 +319,7 @@ test("Custom columns with unspecified width", t => template.open(); - const listview1 = mock.createdWindows[0].widgets[0] as ListViewWidget; + const listview1 = mock.createdWindows[0].widgets[0]; t.true(listview1.showColumnHeaders); const columns = listview1.columns; @@ -357,7 +357,7 @@ test("All pixel widths is built-in scaling", t => template.open(); - const listview1 = mock.createdWindows[0].widgets[0] as ListViewWidget; + const listview1 = mock.createdWindows[0].widgets[0]; const columns = listview1.columns; t.is(columns[0].width, 25); t.is(columns[1].width, 35); @@ -388,7 +388,7 @@ test("All weighted widths is built-in scaling", t => template.open(); - const listview1 = mock.createdWindows[0].widgets[0] as ListViewWidget; + const listview1 = mock.createdWindows[0].widgets[0]; const columns = listview1.columns; t.is(columns[0].ratioWidth, 1); t.is(columns[1].ratioWidth, 3); @@ -419,7 +419,7 @@ test("All percentage widths is custom scaling", t => template.open(); - const listview1 = mock.createdWindows[0].widgets[0] as ListViewWidget; + const listview1 = mock.createdWindows[0].widgets[0]; const columns = listview1.columns; t.is(columns[0].width, 50); t.is(columns[1].width, 70); @@ -447,7 +447,7 @@ test("On click callback is propagated and skips duplicate clicks", t => template.open(); - const listview1 = mock.createdWindows[0].widgets[0] as ListViewDesc; + const listview1 = mock.createdWindows[0].widgets[0]; listview1.onClick!(2, 1); listview1.onClick!(1, 0); listview1.onClick!(1, 1); @@ -477,7 +477,7 @@ test("Selected cell can be bound", t => template.open(); - const listview1 = mock.createdWindows[0].widgets[0] as ListViewWidget; + const listview1 = mock.createdWindows[0].widgets[0]; t.deepEqual(listview1.selectedCell, { row: 2, column: 0 }); t.deepEqual(updates, []); @@ -517,7 +517,7 @@ test("Selected cell can be bound with separate on click event", t => template.open(); - const listview1 = mock.createdWindows[0].widgets[0] as (ListViewWidget & ListViewDesc); + const listview1 = mock.createdWindows[0].widgets[0]; t.deepEqual(listview1.selectedCell, null); t.deepEqual(calls, []); @@ -561,7 +561,7 @@ test("Selected cell can be two-way bound", t => template.open(); - const listview1 = mock.createdWindows[0].widgets[0] as (ListViewWidget & ListViewDesc); + const listview1 = mock.createdWindows[0].widgets[0]; t.deepEqual(listview1.selectedCell, { row: 2, column: 0 }); t.deepEqual(updates, []); @@ -600,7 +600,7 @@ test("Selected cell can be two-way bound with extra on click event", t => template.open(); - const listview1 = mock.createdWindows[0].widgets[0] as (ListViewWidget & ListViewDesc); + const listview1 = mock.createdWindows[0].widgets[0]; t.deepEqual(listview1.selectedCell, { row: 2, column: 0 }); t.deepEqual(calls, []); diff --git a/tests/elements/controls/spinner.tests.ts b/tests/elements/controls/spinner.tests.ts index bfc73d6..a6c8727 100644 --- a/tests/elements/controls/spinner.tests.ts +++ b/tests/elements/controls/spinner.tests.ts @@ -1,4 +1,3 @@ -/* eslint-disable @typescript-eslint/no-non-null-assertion */ /// import { store } from "@src/bindings/stores/createStore"; @@ -24,7 +23,7 @@ test("Standard properties are set", t => template.open(); - const widget = mock.createdWindows[0].widgets[0] as SpinnerWidget; + const widget = mock.createdWindows[0].widgets[0]; t.is(widget.type, "spinner"); t.is(widget.text, "45", ); t.is(widget.tooltip, "spin me"); @@ -46,7 +45,7 @@ test("Value is bindable", t => template.open(); - const widget = mock.createdWindows[0].widgets[0] as SpinnerWidget; + const widget = mock.createdWindows[0].widgets[0]; t.is(widget.text, "33"); value.set(76); @@ -68,7 +67,7 @@ test("Value can be incremented/decremented", t => template.open(); - const widget = mock.createdWindows[0].widgets[0] as SpinnerDesc; + const widget = mock.createdWindows[0].widgets[0]; t.is(widget.text, "41"); call(widget.onIncrement); @@ -93,7 +92,7 @@ test("Incremented value gets clamped", t => template.open(); - const widget = mock.createdWindows[0].widgets[0] as SpinnerDesc; + const widget = mock.createdWindows[0].widgets[0]; t.is(widget.text, "15"); call(widget.onIncrement); @@ -118,7 +117,7 @@ test("Decremented value gets clamped", t => template.open(); - const widget = mock.createdWindows[0].widgets[0] as SpinnerDesc; + const widget = mock.createdWindows[0].widgets[0]; t.is(widget.text, "15"); call(widget.onDecrement); @@ -143,7 +142,7 @@ test("Incremented value gets wrapped", t => template.open(); - const widget = mock.createdWindows[0].widgets[0] as SpinnerDesc; + const widget = mock.createdWindows[0].widgets[0]; t.is(widget.text, "6"); call(widget.onIncrement); @@ -168,7 +167,7 @@ test("Decremented value gets wrapped", t => template.open(); - const widget = mock.createdWindows[0].widgets[0] as SpinnerDesc; + const widget = mock.createdWindows[0].widgets[0]; t.is(widget.text, "4"); call(widget.onDecrement); @@ -193,7 +192,7 @@ test("Incremented value gets clamped then wrapped", t => template.open(); - const widget = mock.createdWindows[0].widgets[0] as SpinnerDesc; + const widget = mock.createdWindows[0].widgets[0]; t.is(widget.text, "6"); call(widget.onIncrement); @@ -221,7 +220,7 @@ test("Decremented value gets clamped then wrapped", t => template.open(); - const widget = mock.createdWindows[0].widgets[0] as SpinnerDesc; + const widget = mock.createdWindows[0].widgets[0]; t.is(widget.text, "4"); call(widget.onDecrement); @@ -247,7 +246,7 @@ test("Change event gets called", t => template.open(); - const widget = mock.createdWindows[0].widgets[0] as SpinnerDesc; + const widget = mock.createdWindows[0].widgets[0]; call(widget.onIncrement); call(widget.onIncrement); call(widget.onIncrement); @@ -295,7 +294,7 @@ test("Minimum equal to maximum does nothing", t => }); template.open(); - const widget = mock.createdWindows[0].widgets[0] as SpinnerDesc; + const widget = mock.createdWindows[0].widgets[0]; call(widget.onIncrement); call(widget.onDecrement); t.pass(); @@ -316,7 +315,7 @@ test("Step is bindable", t => }); template.open(); - const widget = mock.createdWindows[0].widgets[0] as SpinnerDesc; + const widget = mock.createdWindows[0].widgets[0]; call(widget.onIncrement); t.is(widget.text, "1"); @@ -348,7 +347,7 @@ test("Minimum is bindable", t => }); template.open(); - const widget = mock.createdWindows[0].widgets[0] as SpinnerDesc; + const widget = mock.createdWindows[0].widgets[0]; call(widget.onDecrement); t.is(widget.text, "10"); @@ -376,7 +375,7 @@ test("Maximum is bindable", t => }); template.open(); - const widget = mock.createdWindows[0].widgets[0] as SpinnerDesc; + const widget = mock.createdWindows[0].widgets[0]; call(widget.onIncrement); t.is(widget.text, "1"); call(widget.onIncrement); @@ -412,7 +411,7 @@ test("Disabled message shows on disabled", t => }); template.open(); - const widget = mock.createdWindows[0].widgets[0] as SpinnerDesc; + const widget = mock.createdWindows[0].widgets[0]; call(widget.onIncrement); t.is(widget.text, "1"); @@ -446,7 +445,7 @@ test("Default minimum is clamped at smallest 32-bit signed integer", t => template.open(); - const widget = mock.createdWindows[0].widgets[0] as SpinnerDesc; + const widget = mock.createdWindows[0].widgets[0]; t.is(widget.type, "spinner"); call(widget.onDecrement); @@ -468,7 +467,7 @@ test("Default maximum is clamped at largest 32-bit signed integer", t => template.open(); - const widget = mock.createdWindows[0].widgets[0] as SpinnerDesc; + const widget = mock.createdWindows[0].widgets[0]; t.is(widget.type, "spinner"); call(widget.onIncrement); @@ -496,7 +495,7 @@ test("Update maximum clamps value", t => template.open(); - const widget = mock.createdWindows[0].widgets[0] as SpinnerDesc; + const widget = mock.createdWindows[0].widgets[0]; t.is(widget.type, "spinner"); t.is(widget.text, "65"); @@ -530,7 +529,7 @@ test("Update minimum clamps value", t => template.open(); - const widget = mock.createdWindows[0].widgets[0] as SpinnerDesc; + const widget = mock.createdWindows[0].widgets[0]; t.is(widget.type, "spinner"); t.is(widget.text, "65"); @@ -563,7 +562,7 @@ test("Two-way bindings update spinner", t => }); template.open(); - const widget = mock.createdWindows[0].widgets[0] as SpinnerDesc; + const widget = mock.createdWindows[0].widgets[0]; t.is(widget.text, "0"); t.is(value.get(), 0); t.deepEqual(hits, []); diff --git a/tests/elements/controls/toggle.tests.ts b/tests/elements/controls/toggle.tests.ts index 0bbcf74..7f75e3a 100644 --- a/tests/elements/controls/toggle.tests.ts +++ b/tests/elements/controls/toggle.tests.ts @@ -22,7 +22,7 @@ test("Standard properties are set", t => }); template.open(); - const widget = mock.createdWindows[0].widgets[0] as ButtonWidget; + const widget = mock.createdWindows[0].widgets[0]; t.is(widget.type, "button"); t.is(widget.text, "Toggle me!"); t.true(widget.isPressed); @@ -44,7 +44,7 @@ test("Is pressed is still bindable", t => }); template.open(); - const widget = mock.createdWindows[0].widgets[0] as ButtonWidget; + const widget = mock.createdWindows[0].widgets[0]; t.true(widget.isPressed); pressed.set(false); @@ -65,7 +65,7 @@ test("Is pressed updates on toggle", t => }); template.open(); - const widget = mock.createdWindows[0].widgets[0] as ButtonDesc; + const widget = mock.createdWindows[0].widgets[0]; t.falsy(widget.isPressed); call(widget.onClick); @@ -97,7 +97,7 @@ test("Is pressed store does not update store", t => }); template.open(); - const widget = mock.createdWindows[0].widgets[0] as ButtonDesc; + const widget = mock.createdWindows[0].widgets[0]; t.false(widget.isPressed); call(widget.onClick); @@ -141,7 +141,7 @@ test("Change event gets called", t => }); template.open(); - const widget = mock.createdWindows[0].widgets[0] as ButtonDesc; + const widget = mock.createdWindows[0].widgets[0]; t.deepEqual(hits, []); call(widget.onClick); @@ -173,7 +173,7 @@ test("Two-way bindings update toggle", t => }); template.open(); - const widget = mock.createdWindows[0].widgets[0] as ButtonDesc; + const widget = mock.createdWindows[0].widgets[0]; t.true(widget.isPressed); t.true(isPressed.get()); t.deepEqual(hits, []); @@ -197,4 +197,4 @@ test("Two-way bindings update toggle", t => t.true(widget.isPressed); t.true(isPressed.get()); t.deepEqual(hits, [ true, false ]); -}); \ No newline at end of file +}); diff --git a/tests/elements/controls/viewport.tests.ts b/tests/elements/controls/viewport.tests.ts index d8f0bb8..aa85533 100644 --- a/tests/elements/controls/viewport.tests.ts +++ b/tests/elements/controls/viewport.tests.ts @@ -1,9 +1,9 @@ /// import { store } from "@src/bindings/stores/createStore"; -import { window } from "@src/windows/window"; import { ViewportFlags } from "@src/elements/controls/enums/viewportFlags"; import { viewport } from "@src/elements/controls/viewport"; +import { window } from "@src/windows/window"; import test from "ava"; import Mock, { UiMock } from "openrct2-mocks"; import { call } from "tests/helpers"; @@ -27,7 +27,7 @@ test("Standard properties are set", t => }); template.open(); - const widget = mock.createdWindows[0].widgets[0] as ViewportWidget; + const widget = mock.createdWindows[0].widgets[0]; t.is(widget.type, "viewport"); t.is(widget.tooltip, "view this"); const vp = widget.viewport; @@ -52,10 +52,10 @@ test("Viewport updates on store update", t => }); template.open(); - const created = (globalThis.ui as UiMock).createdWindows[0]; + const created = (globalThis.ui).createdWindows[0]; call(created.onUpdate); - const widget = created.widgets[0] as ViewportWidget; + const widget = created.widgets[0]; const vp = widget.viewport; t.is(vp.left, 10 - 50); t.is(vp.bottom, 20 - 50); @@ -86,8 +86,8 @@ test("Viewport goes into disabled appearance", t => }); template.open(); - const created = (globalThis.ui as UiMock).createdWindows[0]; - const widget = created.widgets[0] as ViewportWidget; + const created = (globalThis.ui).createdWindows[0]; + const widget = created.widgets[0]; const vp = widget.viewport; t.is(vp.visibilityFlags, 1); t.is(widget.isDisabled, false); @@ -99,4 +99,4 @@ test("Viewport goes into disabled appearance", t => disabled.set(false); t.is(vp.visibilityFlags, 1); t.is(widget.isDisabled, false); -}); \ No newline at end of file +}); diff --git a/tests/elements/controls/widget.tests.ts b/tests/elements/controls/widget.tests.ts index 3817554..d516cf3 100644 --- a/tests/elements/controls/widget.tests.ts +++ b/tests/elements/controls/widget.tests.ts @@ -11,7 +11,7 @@ test("Standard properties are set", t => const mock = Mock.ui(); globalThis.ui = mock; - const callback = (): void => {}; + const callback = (): void => {/* empty */}; const template = window({ width: 100, height: 100, padding: 10, content: [ @@ -29,7 +29,7 @@ test("Standard properties are set", t => }); template.open(); - const result = mock.createdWindows[0].widgets[0] as ButtonDesc; + const result = mock.createdWindows[0].widgets[0]; t.is(result.type, "button"); t.is(result.text, "Click me!"); t.is(result.tooltip, "Best button in the world"); diff --git a/tests/elements/layouts/absolute.tests.ts b/tests/elements/layouts/absolute.tests.ts index 48b8d0d..dd2e368 100644 --- a/tests/elements/layouts/absolute.tests.ts +++ b/tests/elements/layouts/absolute.tests.ts @@ -1,9 +1,9 @@ /// -import { window } from "@src/windows/window"; import { button } from "@src/elements/controls/button"; import { label } from "@src/elements/controls/label"; import { absolute } from "@src/elements/layouts/absolute/absolute"; +import { window } from "@src/windows/window"; import test from "ava"; import Mock from "openrct2-mocks"; @@ -32,7 +32,7 @@ test("Simple layout with widgets", t => }); template.open(); - const widget1 = mock.createdWindows[0].widgets[0] as LabelWidget; + const widget1 = mock.createdWindows[0].widgets[0]; t.is(widget1.type, "label"); t.is(widget1.text, "Look at me!"); t.is(widget1.x, 21); @@ -40,7 +40,7 @@ test("Simple layout with widgets", t => t.is(widget1.width, 43); t.is(widget1.height, 19); - const widget2 = mock.createdWindows[0].widgets[1] as ButtonWidget; + const widget2 = mock.createdWindows[0].widgets[1]; t.is(widget2.type, "button"); t.is(widget2.text, "Click me!"); t.is(widget2.x, 42); @@ -72,7 +72,7 @@ test("Flat layout with widgets", t => }); template.open(); - const widget2 = mock.createdWindows[0].widgets[0] as ButtonWidget; + const widget2 = mock.createdWindows[0].widgets[0]; t.is(widget2.type, "button"); t.is(widget2.text, "Click me!"); t.is(widget2.x, 43); @@ -80,11 +80,11 @@ test("Flat layout with widgets", t => t.is(widget2.width, 33); t.is(widget2.height, 70); - const widget1 = mock.createdWindows[0].widgets[1] as LabelWidget; + const widget1 = mock.createdWindows[0].widgets[1]; t.is(widget1.type, "label"); t.is(widget1.text, "Look at me!"); t.is(widget1.x, 22); t.is(widget1.y, 35 + 2 + 15); t.is(widget1.width, 44); t.is(widget1.height, 20); -}); \ No newline at end of file +}); diff --git a/tests/elements/layouts/flexible.tests.ts b/tests/elements/layouts/flexible.tests.ts index 9a0e100..5a651d8 100644 --- a/tests/elements/layouts/flexible.tests.ts +++ b/tests/elements/layouts/flexible.tests.ts @@ -31,17 +31,17 @@ const parentMock: ParentControl = parse: parseFlexiblePosition, recalculate(): void { /* empty */ } }; -// eslint-disable-next-line @typescript-eslint/explicit-function-return-type + function createBuildOutput() { return { widgets: Array(), binder: new WidgetBinder(), context: { redraw: noop }, - open: >[], - redraw: >[], - update: >[], - close: >[], + open: [], + redraw: [], + update: [], + close: [], add(widget: WidgetBaseDesc): void { this.widgets.push(widget); @@ -77,7 +77,7 @@ test("Simple layouts with widgets", t => invoke(output.redraw); control.layout(widgetMap, rect); - const label1 = output.widgets[0] as LabelWidget; + const label1 = output.widgets[0]; t.is(label1.type, "label"); t.is(label1.text, "hello world"); t.is(label1.x, 0); @@ -85,7 +85,7 @@ test("Simple layouts with widgets", t => t.is(label1.width, 200); t.is(label1.height, 50); - const button1 = output.widgets[1] as ButtonWidget; + const button1 = output.widgets[1]; t.is(button1.type, "button"); t.is(button1.text, "left button"); t.is(button1.x, 0); @@ -93,7 +93,7 @@ test("Simple layouts with widgets", t => t.is(button1.width, 100); t.is(button1.height, 50); - const button2 = output.widgets[2] as ButtonWidget; + const button2 = output.widgets[2]; t.is(button2.type, "button"); t.is(button2.text, "right button"); t.is(button2.x, 100); @@ -101,7 +101,7 @@ test("Simple layouts with widgets", t => t.is(button2.width, 100); t.is(button2.height, 50); - const label2 = output.widgets[3] as LabelWidget; + const label2 = output.widgets[3]; t.is(label2.type, "label"); t.is(label2.text, "big area"); t.is(label2.textAlign, "centred"); @@ -136,19 +136,19 @@ test("Pixel sizes ignore leftover space", t => invoke(output.redraw); control.layout(widgetMap, rect); - const label1 = output.widgets[0] as LabelWidget; + const label1 = output.widgets[0]; t.is(label1.x, 0); t.is(label1.y, 0 + 2); t.is(label1.width, 40); t.is(label1.height, 25); - const label2 = output.widgets[1] as LabelWidget; + const label2 = output.widgets[1]; t.is(label2.x, 0); t.is(label2.y, 25 + 2); t.is(label2.width, 30); t.is(label2.height, 10); - const label3 = output.widgets[2] as LabelWidget; + const label3 = output.widgets[2]; t.is(label3.x, 0); t.is(label3.y, 35 + 2); t.is(label3.width, 70); @@ -180,19 +180,19 @@ test("Percentage sizes", t => invoke(output.redraw); control.layout(widgetMap, rect); - const label1 = output.widgets[0] as LabelWidget; + const label1 = output.widgets[0]; t.is(label1.x, 0); t.is(label1.y, 0 + 2); t.is(label1.width, 30); t.is(label1.height, 12); - const label2 = output.widgets[1] as LabelWidget; + const label2 = output.widgets[1]; t.is(label2.x, 0); t.is(label2.y, 12 + 2); t.is(label2.width, 6); t.is(label2.height, 27); - const label3 = output.widgets[2] as LabelWidget; + const label3 = output.widgets[2]; t.is(label3.x, 0); t.is(label3.y, 39 + 2); t.is(label3.width, 45); @@ -224,19 +224,19 @@ test("Weighted sizes", t => invoke(output.redraw); control.layout(widgetMap, rect); - const label1 = output.widgets[0] as LabelWidget; + const label1 = output.widgets[0]; t.is(label1.x, 0); t.is(label1.y, 0 + 2); t.is(label1.width, 60); t.is(label1.height, 18); - const label2 = output.widgets[1] as LabelWidget; + const label2 = output.widgets[1]; t.is(label2.x, 0); t.is(label2.y, 18 + 2); t.is(label2.width, 60); t.is(label2.height, 7); - const label3 = output.widgets[2] as LabelWidget; + const label3 = output.widgets[2]; t.is(label3.x, 0); t.is(label3.y, 25 + 2); t.is(label3.width, 60); @@ -265,11 +265,11 @@ test("Relative percentage fills leftover space", t => invoke(output.redraw); control.layout(widgetMap, rect); - const label1 = output.widgets[0] as LabelWidget; + const label1 = output.widgets[0]; t.is(label1.y, 0 + 2); t.is(label1.height, 15); - const label2 = output.widgets[1] as LabelWidget; + const label2 = output.widgets[1]; t.is(label2.y, 15 + 2); t.is(label2.height, 65); }); @@ -296,11 +296,11 @@ test("Relative weight fills leftover space", t => invoke(output.redraw); control.layout(widgetMap, rect); - const label1 = output.widgets[0] as LabelWidget; + const label1 = output.widgets[0]; t.is(label1.y, 0 + 2); t.is(label1.height, 43); - const label2 = output.widgets[1] as LabelWidget; + const label2 = output.widgets[1]; t.is(label2.y, 43 + 2); t.is(label2.height, 17); }); @@ -327,11 +327,11 @@ test("Relative weight takes leftover after relative percentage", t => invoke(output.redraw); control.layout(widgetMap, rect); - const label1 = output.widgets[0] as LabelWidget; + const label1 = output.widgets[0]; t.is(label1.y, 0 + 2); t.is(label1.height, 20); - const label2 = output.widgets[1] as LabelWidget; + const label2 = output.widgets[1]; t.is(label2.y, 20 + 2); t.is(label2.height, 60); }); @@ -454,14 +454,14 @@ test("Padding: tuple with 2 values", t => invoke(output.redraw); control.layout(widgetMap, rect); - const label1 = output.widgets[0] as LabelWidget; + const label1 = output.widgets[0]; t.is(label1.text, "a"); t.is(label1.x, 7); t.is(label1.y, 3 + 2); t.is(label1.width, 46); t.is(label1.height, 12); - const label2 = output.widgets[1] as LabelWidget; + const label2 = output.widgets[1]; t.is(label2.text, "b"); t.is(label2.x, 6); t.is(label2.y, 12 + 2 + 6 + 6); @@ -511,14 +511,14 @@ test("Padding: multiple weighted values mixed with absolute sizes", t => invoke(output.redraw); control.layout(widgetMap, rect); - const widget1 = output.widgets[0] as ButtonWidget; + const widget1 = output.widgets[0]; t.is(widget1.text, "a"); t.is(widget1.x, 5); t.is(widget1.y, 5); t.is(widget1.width, 60); t.is(widget1.height, 34); - const widget2 = output.widgets[1] as ButtonWidget; + const widget2 = output.widgets[1]; t.is(widget2.text, "b"); t.is(widget2.x, 5 + 25); t.is(widget2.y, 5 + 34 + 16 + 8); @@ -544,14 +544,14 @@ test("Padding: included in cursor tracking", t => invoke(output.redraw); control.layout(widgetMap, rect); - const widget1 = output.widgets[0] as ButtonWidget; + const widget1 = output.widgets[0]; t.is(widget1.text, "a"); t.is(widget1.x, 5 + 12); t.is(widget1.y, 5 + 12); t.is(widget1.width, 60 - 24); t.is(widget1.height, 30); - const widget2 = output.widgets[1] as ButtonWidget; + const widget2 = output.widgets[1]; t.is(widget2.text, "b"); t.is(widget2.x, 5); t.is(widget2.y, 5 + 24 + 30 + 3); @@ -578,21 +578,21 @@ test("Padding: used as spacing for single element", t => invoke(output.redraw); control.layout(widgetMap, rect); - const widget1 = output.widgets[0] as ButtonWidget; + const widget1 = output.widgets[0]; t.is(widget1.text, "a"); t.is(widget1.x, 5); t.is(widget1.y, 5); t.is(widget1.width, 16); t.is(widget1.height, 30); - const widget2 = output.widgets[1] as ButtonWidget; + const widget2 = output.widgets[1]; t.is(widget2.text, "b"); t.is(widget2.x, 5 + 16 + 3); t.is(widget2.y, 5); t.is(widget2.width, 17); t.is(widget2.height, 30); - const widget3 = output.widgets[2] as ButtonWidget; + const widget3 = output.widgets[2]; t.is(widget3.text, "c"); t.is(widget3.x, 5 + (100 - 18)); t.is(widget3.y, 5); @@ -666,13 +666,13 @@ test("Spacing: default space between two elements", t => invoke(output.redraw); control.layout(widgetMap, rect); - const label1 = output.widgets[0] as LabelWidget; + const label1 = output.widgets[0]; t.is(label1.x, 7); t.is(label1.y, 20 + 2); t.is(label1.width, 78); t.is(label1.height, 14); - const label2 = output.widgets[1] as LabelWidget; + const label2 = output.widgets[1]; t.is(label2.x, 7); t.is(label2.y, 38 + 2); t.is(label2.width, 78); @@ -697,13 +697,13 @@ test("Spacing: percentile space between two elements", t => invoke(output.redraw); control.layout(widgetMap, rect); - const label1 = output.widgets[0] as LabelWidget; + const label1 = output.widgets[0]; t.is(label1.x, 5); t.is(label1.y, 10 + 2); t.is(label1.width, 20); t.is(label1.height, 14); - const label2 = output.widgets[1] as LabelWidget; + const label2 = output.widgets[1]; t.is(label2.x, 35); t.is(label2.y, 10 + 2); t.is(label2.width, 20); @@ -728,13 +728,13 @@ test("Spacing: weighted space between two elements", t => invoke(output.redraw); control.layout(widgetMap, rect); - const label1 = output.widgets[0] as LabelWidget; + const label1 = output.widgets[0]; t.is(label1.x, 5); t.is(label1.y, 0 + 2); t.is(label1.width, 10); t.is(label1.height, 14); - const label2 = output.widgets[1] as LabelWidget; + const label2 = output.widgets[1]; t.is(label2.x, 25); t.is(label2.y, 0 + 2); t.is(label2.width, 10); @@ -919,56 +919,56 @@ test("Nested layouts with boxed labels using percentage padding", t => invoke(output.redraw); control.layout(widgetMap, rect); - const box1 = output.widgets[0] as LabelWidget; + const box1 = output.widgets[0]; t.is(box1.text, "b-a"); t.is(box1.x, 0 + 32); t.is(box1.y, 0 + 15); t.is(box1.width, 120); t.is(box1.height, 90); - const label1 = output.widgets[1] as LabelWidget; + const label1 = output.widgets[1]; t.is(label1.text, "l-a"); t.is(label1.x, 0 + 32); t.is(label1.y, 45 + 2 + 15 - 7); t.is(label1.width, 120); t.is(label1.height, 14); - const box2 = output.widgets[2] as LabelWidget; + const box2 = output.widgets[2]; t.is(box2.text, "b-b"); t.is(box2.x, 120 + 32); t.is(box2.y, 0 + 15); t.is(box2.width, 120); t.is(box2.height, 90); - const label2 = output.widgets[3] as LabelWidget; + const label2 = output.widgets[3]; t.is(label2.text, "l-b"); t.is(label2.x, 120 + 32); t.is(label2.y, 45 + 2 + 15 - 7); t.is(label2.width, 120); t.is(label2.height, 14); - const box3 = output.widgets[4] as LabelWidget; + const box3 = output.widgets[4]; t.is(box3.text, "b-c"); t.is(box3.x, 0 + 32); t.is(box3.y, 90 + 15); t.is(box3.width, 240); t.is(box3.height, 45); - const label3 = output.widgets[5] as LabelWidget; + const label3 = output.widgets[5]; t.is(label3.text, "l-c"); t.is(label3.x, 0 + 32); t.is(label3.y, 90 + 2 + 23 + 15 - 7); t.is(label3.width, 240); t.is(label3.height, 14); - const box4 = output.widgets[6] as LabelWidget; + const box4 = output.widgets[6]; t.is(box4.text, "b-d"); t.is(box4.x, 0 + 32); t.is(box4.y, 135 + 15); t.is(box4.width, 240); t.is(box4.height, 45); - const label4 = output.widgets[7] as LabelWidget; + const label4 = output.widgets[7]; t.is(label4.text, "l-d"); t.is(label4.x, 0 + 32); t.is(label4.y, 135 + 2 + 23 + 15 - 7); @@ -999,21 +999,21 @@ test("Child with visibility 'none' is not updated", t => const widgets = output.widgets; t.is(widgets.length, 3); - const widget1 = output.widgets[0] as LabelWidget; + const widget1 = output.widgets[0]; t.is(widget1.text, "abc"); t.is(widget1.x, 28); t.is(widget1.y, 20 + 2); t.is(widget1.width, 43); t.is(widget1.height, 25); - const widget2 = output.widgets[1] as LabelWidget; + const widget2 = output.widgets[1]; t.is(widget2.text, "nada"); t.is(widget2.x, 0); t.is(widget2.y, 0); t.is(widget2.width, 0); t.is(widget2.height, 0); - const widget3 = output.widgets[2] as LabelWidget; + const widget3 = output.widgets[2]; t.is(widget3.text, "def"); t.is(widget3.x, 28); t.is(widget3.y, 20 + 2 + 25 + 10); @@ -1043,21 +1043,21 @@ test("None update if all children have visibility set to 'none'", t => const widgets = output.widgets; t.is(widgets.length, 3); - const widget1 = output.widgets[0] as LabelWidget; + const widget1 = output.widgets[0]; t.is(widget1.text, "abc"); t.is(widget1.x, 0); t.is(widget1.y, 0); t.is(widget1.width, 0); t.is(widget1.height, 0); - const widget2 = output.widgets[1] as LabelWidget; + const widget2 = output.widgets[1]; t.is(widget2.text, "def"); t.is(widget2.x, 0); t.is(widget2.y, 0); t.is(widget2.width, 0); t.is(widget2.height, 0); - const widget3 = output.widgets[2] as LabelWidget; + const widget3 = output.widgets[2]; t.is(widget3.text, "ghi"); t.is(widget3.x, 0); t.is(widget3.y, 0); @@ -1089,9 +1089,9 @@ test("Child visibility is updated by store", t => const widgets = output.widgets; t.is(widgets.length, 3); - const widget1 = output.widgets[0] as LabelWidget; - const widget2 = output.widgets[1] as LabelWidget; - const widget3 = output.widgets[2] as LabelWidget; + const widget1 = output.widgets[0]; + const widget2 = output.widgets[1]; + const widget3 = output.widgets[2]; t.is(widget1.y, 3 + 2); t.is(widget2.y, 3 + 2 + 10 + 20); t.is(widget3.y, 3 + 2 + 10 + 20 + 10 + 20); @@ -1143,8 +1143,8 @@ test("Invisible childs should still count for size inheritance", t => const widgets = output.widgets; t.is(widgets.length, 2); - const widget1 = output.widgets[0] as LabelWidget; - const widget2 = output.widgets[1] as LabelWidget; + const widget1 = output.widgets[0]; + const widget2 = output.widgets[1]; t.is(widget1.y, 3 + 2); t.is(widget2.y, 3 + 2 + 10 + 15); t.is(widget1.height, 15); @@ -1192,15 +1192,15 @@ test("Rounding: uneven sizes get rounded inwards", t => invoke(output.redraw); control.layout(widgetMap, rect); - const label1 = output.widgets[0] as LabelWidget; + const label1 = output.widgets[0]; t.is(label1.x, 3); t.is(label1.y, 5); t.is(label1.width, 37); t.is(label1.height, 11); // 11 instead of 11.5 - const label2 = output.widgets[1] as LabelWidget; + const label2 = output.widgets[1]; t.is(label2.x, 3); t.is(label2.y, 5 + 12); // 12 instead of 11.5 t.is(label2.width, 37); t.is(label2.height, 11); // 11 instead of 11.5 -}); \ No newline at end of file +}); diff --git a/tests/helpers.ts b/tests/helpers.ts index a1d9b57..ea1bab6 100644 --- a/tests/helpers.ts +++ b/tests/helpers.ts @@ -3,6 +3,5 @@ */ export function call(method: ((...args: T) => void) | undefined, ...args: T): void { - // eslint-disable-next-line @typescript-eslint/no-non-null-assertion method!.call(undefined, ...args); } diff --git a/tests/package/_integration-tests.ts b/tests/package/_integration-tests.ts index 1938e1e..9802ec6 100644 --- a/tests/package/_integration-tests.ts +++ b/tests/package/_integration-tests.ts @@ -2,7 +2,7 @@ import { TestFn } from 'ava'; import { getFile } from "./_integration-helpers"; -export function integrations(test: TestFn, name: string): void +export function integrations(test: TestFn, name: string): void { test("Output contains no arrow functions", async t => { diff --git a/tests/utilities/array.tests.ts b/tests/utilities/array.tests.ts index 8a14c15..4aa90ea 100644 --- a/tests/utilities/array.tests.ts +++ b/tests/utilities/array.tests.ts @@ -1,7 +1,5 @@ -/* eslint-disable @typescript-eslint/no-non-null-assertion */ - -import test from "ava"; import * as ArrayHelper from "@src/utilities/array"; +import test from "ava"; test("find()", t => diff --git a/tests/.trackable/trackable.tests.ts b/tests/utilities/trackable.tests.ts similarity index 100% rename from tests/.trackable/trackable.tests.ts rename to tests/utilities/trackable.tests.ts diff --git a/tests/.trackable/trackable.ts b/tests/utilities/trackable.ts similarity index 70% rename from tests/.trackable/trackable.ts rename to tests/utilities/trackable.ts index 4c79d17..b63ab5b 100644 --- a/tests/.trackable/trackable.ts +++ b/tests/utilities/trackable.ts @@ -58,7 +58,7 @@ function createTotalCounter(root: Trackable, children: Trackable[], key get: function() { return children - .map(t => selector(t)[key as keyof T] as number) + .map(t => selector(t)[key]) .reduce((sum, cur) => sum + cur); }, enumerable: true, @@ -70,9 +70,9 @@ function createTotalCounter(root: Trackable, children: Trackable[], key /** * Allows any reads and writes to the object of T to be tracked. */ -export default function track(source: T[]): Trackable[]>; -export default function track(source: T): Trackable; -export default function track(source: T | T[]): Trackable | Trackable[]> +export default function track(source: T[]): Trackable[]>; +export default function track(source: T): Trackable; +export default function track(source: T | T[]): Trackable | Trackable[]> { if (Array.isArray(source)) { @@ -86,46 +86,44 @@ export default function track(source: T | T[]): Trackable | Trackable(source: T[]): Trackable[]> +function trackArray(source: T[]): Trackable[]> { - // eslint-disable-next-line @typescript-eslint/no-explicit-any - const tracker = source as Trackable; + const tracker = []>>source; Object.defineProperty(tracker ,"_gets", { value: {} }); Object.defineProperty(tracker ,"_sets", { value: {} }); - const subtrackers: Trackable[] = new Array(source.length); + const subtrackers = new Array>(source.length); for (const item of source) { for (const key of Object.keys(source[0])) { - createTotalCounter(tracker, subtrackers, key, t => t._gets); - createTotalCounter(tracker, subtrackers, key, t => t._sets); + createTotalCounter(tracker, subtrackers, key, t => t._gets); + createTotalCounter(tracker, subtrackers, key, t => t._sets); } subtrackers.push(track(item)); } - return tracker as Trackable[]>; + return tracker; } /** * Tracks all geter and setter accessings on source. */ -function trackObject(source: T): Trackable +function trackObject(source: T): Trackable { - // eslint-disable-next-line @typescript-eslint/no-explicit-any - const trackable = source as Trackable; - const internal: Record = {}; + const trackable = >source; + const internal = >{}; - const keys = Object.keys(source); + const keys = <(keyof T)[]>Object.keys(source); Object.defineProperty(trackable ,"_gets", { value: { total: calculateTotal } }); Object.defineProperty(trackable ,"_sets", { value: { total: calculateTotal } }); for (const key of keys) { internal[key] = trackable[key]; - trackable._gets[key] = 0; - trackable._sets[key] = 0; + trackable._gets[key] = 0; + trackable._sets[key] = 0; Object.defineProperty(source, key, { @@ -134,12 +132,12 @@ function trackObject(source: T): Trackable trackable._gets[key]++; return internal[key]; }, - set: function(value) + set: function(value: unknown) { trackable._sets[key]++; internal[key] = value; }, }); } - return trackable as Trackable; -} \ No newline at end of file + return trackable; +} diff --git a/tests/utilities/type.tests.ts b/tests/utilities/type.tests.ts index efc8cca..1eb8395 100644 --- a/tests/utilities/type.tests.ts +++ b/tests/utilities/type.tests.ts @@ -1,5 +1,5 @@ -import test from "ava"; import * as Type from "@src/utilities/type"; +import test from "ava"; test("isUndefined() returns true", t => @@ -9,7 +9,7 @@ test("isUndefined() returns true", t => // eslint-disable-next-line @typescript-eslint/no-explicit-any let a: any; t.true(Type.isUndefined(a)); - // eslint-disable-next-line @typescript-eslint/no-explicit-any + // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-member-access t.true(Type.isUndefined(({}).b)); }); @@ -121,7 +121,7 @@ test("isNumber() returns false", t => class Test { - value: number = 5; + value = 5; } @@ -160,4 +160,4 @@ test("isString() returns false", t => t.false(Type.isString((): [] => [])); t.false(Type.isString(null)); t.false(Type.isString(undefined)); -}); \ No newline at end of file +}); diff --git a/tests/windows/tab.tests.ts b/tests/windows/tab.tests.ts index 971c2c1..d93da8a 100644 --- a/tests/windows/tab.tests.ts +++ b/tests/windows/tab.tests.ts @@ -1,4 +1,3 @@ -/* eslint-disable @typescript-eslint/no-non-null-assertion */ /// import { store } from "@src/bindings/stores/createStore"; @@ -19,15 +18,15 @@ test("Tab gets created", t => label({ text: "waddup" }), ] }); - const description = {} as WindowTabDesc; - tabCreator({} as ParentWindow, description); + const description = {}; + tabCreator({}, description); t.is(description.image, 104); t.truthy(description.widgets); - const buttonWidget = description.widgets![0] as ButtonWidget; + const buttonWidget = description.widgets![0]; t.is(buttonWidget.type, "button"); t.is(buttonWidget.text, "hey"); - const labelWidget = description.widgets![1] as LabelWidget; + const labelWidget = description.widgets![1]; t.is(labelWidget.type, "label"); t.is(labelWidget.text, "waddup"); }); @@ -41,8 +40,8 @@ test("Tab open() triggers event", t => content: [], onOpen: () => hits.push("opened") }); - const description = {} as WindowTabDesc; - const layoutable = tabCreator({} as ParentWindow, description); + const description = {}; + const layoutable = tabCreator({}, description); layoutable.open({}, {}); t.deepEqual(hits, [ "opened" ]); @@ -61,8 +60,8 @@ test("Tab update() triggers event", t => content: [], onUpdate: () => hits.push("updated") }); - const description = {} as WindowTabDesc; - const layoutable = tabCreator({} as ParentWindow, description); + const description = {}; + const layoutable = tabCreator({}, description); layoutable.update(); t.deepEqual(hits, [ "updated" ]); @@ -81,8 +80,8 @@ test("Tab close() triggers event", t => content: [], onClose: () => hits.push("closed") }); - const description = {} as WindowTabDesc; - const layoutable = tabCreator({} as ParentWindow, description); + const description = {}; + const layoutable = tabCreator({}, description); layoutable.open({}, {}); layoutable.close(); @@ -104,8 +103,8 @@ test("Tab all events are bound", t => onUpdate: () => hits.push("updated"), onClose: () => hits.push("closed") }); - const description = {} as WindowTabDesc; - const layoutable = tabCreator({} as ParentWindow, description); + const description = {}; + const layoutable = tabCreator({}, description); layoutable.open({}, {}); layoutable.close(); @@ -131,12 +130,12 @@ test("Tab open() refreshes widget properties bound to stores", t => label({ text: labelStore }), ] }); - const description = {} as WindowTabDesc; - const layoutable = tabCreator({} as ParentWindow, description); + const description = {}; + const layoutable = tabCreator({}, description); const widgets = description.widgets!; - const createdButton = {} as ButtonWidget; - const createdLabel = {} as LabelWidget; + const createdButton = {}; + const createdLabel = {}; const widgetMap: WidgetMap = { [widgets[0].name!]: createdButton, [widgets[1].name!]: createdLabel, @@ -153,4 +152,4 @@ test("Tab open() refreshes widget properties bound to stores", t => labelStore.set("something else"); t.is(createdButton.text, "changed me"); t.is(createdLabel.text, "something else"); -}); \ No newline at end of file +}); diff --git a/tests/windows/tabwindow.tests.ts b/tests/windows/tabwindow.tests.ts index c9e8448..03a4930 100644 --- a/tests/windows/tabwindow.tests.ts +++ b/tests/windows/tabwindow.tests.ts @@ -34,14 +34,14 @@ test("Window with one tab and one absolute widget", t => }); template.open(); - const created = (globalThis.ui as UiMock).createdWindows[0]; + const created = (globalThis.ui).createdWindows[0]; t.truthy(created); t.is(created.width, 120); t.is(created.height, 70); t.is(created.widgets.length, 1); t.is(created.tabIndex, 0); - const button1 = created.widgets[0] as ButtonWidget; + const button1 = created.widgets[0]; t.is(button1.type, "button"); t.is(button1.text, "hello world"); t.is(button1.x, 10); @@ -82,7 +82,7 @@ test("Window with viewmodel", t => const model = new Model(); template.open(model); - const created = (globalThis.ui as UiMock).createdWindows[0]; + const created = (globalThis.ui).createdWindows[0]; t.truthy(created); t.is(created.width, 120); t.is(created.height, 70); @@ -90,7 +90,7 @@ test("Window with viewmodel", t => t.is(created.tabIndex, 0); t.is(created.title, "better window"); - const button1 = created.widgets[0] as ButtonWidget; + const button1 = created.widgets[0]; t.is(button1.type, "button"); t.is(button1.text, "hello world"); t.is(button1.x, 10); @@ -123,14 +123,14 @@ test("Window with one tab and one 100% widget", t => }); template.open(); - const created = (globalThis.ui as UiMock).createdWindows[0]; + const created = (globalThis.ui).createdWindows[0]; t.truthy(created); t.is(created.width, 120); t.is(created.height, 150); t.is(created.widgets.length, 1); t.is(created.tabIndex, 0); - const button1 = created.widgets[0] as ButtonWidget; + const button1 = created.widgets[0]; t.is(button1.type, "button"); t.is(button1.text, "hello world"); t.is(button1.x, 10); @@ -157,14 +157,14 @@ test("Window with no tabs and one static absolute widget", t => }); template.open(); - const created = (globalThis.ui as UiMock).createdWindows[0]; + const created = (globalThis.ui).createdWindows[0]; t.truthy(created); t.is(created.width, 200); t.is(created.height, 150); t.is(created.widgets.length, 1); t.is(created.tabIndex, 0); - const button1 = created.widgets[0] as ButtonWidget; + const button1 = created.widgets[0]; t.is(button1.type, "button"); t.is(button1.text, "hello world"); t.is(button1.x, 10); @@ -187,14 +187,14 @@ test("Window with no tabs and one static 100% widget", t => }); template.open(); - const created = (globalThis.ui as UiMock).createdWindows[0]; + const created = (globalThis.ui).createdWindows[0]; t.truthy(created); t.is(created.width, 200); t.is(created.height, 150); t.is(created.widgets.length, 1); t.is(created.tabIndex, 0); - const button1 = created.widgets[0] as ButtonWidget; + const button1 = created.widgets[0]; t.is(button1.type, "button"); t.is(button1.text, "hello world"); t.is(button1.x, 10); @@ -224,7 +224,7 @@ test("Window with tabs errors with weighted widget in auto-sized tab", t => { template.open(); }); - t.is(error?.message, "Window body width must resolve to absolute size for \"auto\" window size."); + t.is(error.message, "Window body width must resolve to absolute size for \"auto\" window size."); }); @@ -248,7 +248,7 @@ test("Window with tabs errors with weighted padding in auto-sized tab", t => { template.open(); }); - t.is(error?.message, "Window padding must be absolute for \"auto\" window size."); + t.is(error.message, "Window padding must be absolute for \"auto\" window size."); }); @@ -272,20 +272,20 @@ test("Window with tabs allows weighted widget for static widget in auto-sized ta }); template.open(); - const created = (globalThis.ui as UiMock).createdWindows[0]; + const created = (globalThis.ui).createdWindows[0]; const expectedWindowWidth = (35 + 16); const expectedWindowHeight = (20 + 16 + 44); t.is(created.width, expectedWindowWidth); t.is(created.height, expectedWindowHeight); - const button1 = created.widgets[0] as ButtonWidget; + const button1 = created.widgets[0]; t.is(button1.text, "static button"); t.is(button1.x, 8); t.is(button1.y, 8 + 15); t.is(button1.width, 35); // should be same width and height + topbar difference t.is(button1.height, 20 + (44 - 15)); - const button2 = created.widgets[1] as ButtonWidget; + const button2 = created.widgets[1]; t.is(button2.text, "tab 1 button"); t.is(button2.x, 8); t.is(button2.y, 8 + 44); @@ -324,14 +324,14 @@ test("Window with tabs allows weighted widget and padding for static widget in a t.is(window.width, expectedWindowWidth); t.is(window.height, expectedWindowHeight); - const button1 = window.widgets[0] as ButtonWidget; + const button1 = window.widgets[0]; t.is(button1.text, "static button"); t.is(button1.x, 8 + 4); // 10% = 4.1 of (35 + 6) t.is(button1.y, 8 + 6 + 15); // 10% = 5.5 of (20 + 6 + (44 - 15)) t.is(button1.width, expectedWindowWidth - (16 + 8)); t.is(button1.height, expectedWindowHeight - (16 + 11 + 15)); - const button2 = window.widgets[1] as ButtonWidget; + const button2 = window.widgets[1]; t.is(button2.text, "tab 1 button"); t.is(button2.x, 8 + 3); t.is(button2.y, 8 + 3 + 44); @@ -339,7 +339,7 @@ test("Window with tabs allows weighted widget and padding for static widget in a t.is(button2.height, 20); } - const created = (globalThis.ui as UiMock).createdWindows[0]; + const created = (globalThis.ui).createdWindows[0]; verify(created); call(created.onUpdate); @@ -378,7 +378,7 @@ test("Window with multiple tabs, widgets, title and colours", t => }); template.open(); - const created = (globalThis.ui as UiMock).createdWindows[0]; + const created = (globalThis.ui).createdWindows[0]; t.truthy(created); t.is(created.title, "test tab window"); t.is(created.width, 200); @@ -387,7 +387,7 @@ test("Window with multiple tabs, widgets, title and colours", t => t.is(created.tabIndex, 1); t.deepEqual(created.colours, [ Colour.Aquamarine, Colour.BrightGreen, Colour.SalmonPink ]); - const label1 = created.widgets[0] as LabelWidget; + const label1 = created.widgets[0]; t.is(label1.type, "label"); t.is(label1.text, "hello world"); t.is(label1.x, 10); @@ -395,7 +395,7 @@ test("Window with multiple tabs, widgets, title and colours", t => t.is(label1.width, 200 - 20); t.is(label1.height, 14); - const label2 = created.widgets[1] as LabelWidget; + const label2 = created.widgets[1]; t.is(label2.type, "label"); t.is(label2.text, "tab 2"); t.is(label2.x, 10); @@ -428,18 +428,18 @@ test("Window with tabs and static includes all paddings", t => }); template.open(); - const created = (globalThis.ui as UiMock).createdWindows[0]; + const created = (globalThis.ui).createdWindows[0]; t.is(created.width, 150); t.is(created.height, 275); - const button1 = created.widgets[0] as ButtonWidget; + const button1 = created.widgets[0]; t.is(button1.text, "static button"); t.is(button1.x, 10 + 7); t.is(button1.y, 10 + 7 + 15); t.is(button1.width, 150 - (20 + 14)); t.is(button1.height, 275 - (20 + 14 + 15)); - const button2 = created.widgets[1] as ButtonWidget; + const button2 = created.widgets[1]; t.is(button2.text, "tab 1 button"); t.is(button2.x, 10 + 4); t.is(button2.y, 10 + 4 + 44); @@ -483,7 +483,7 @@ test("Window and tab events execute", t => t.deepEqual(hits, ["window open", "tab 2 open"]); - const created = (globalThis.ui as UiMock).createdWindows[0]; + const created = (globalThis.ui).createdWindows[0]; call(created.onUpdate); t.deepEqual(hits, ["window open", "tab 2 open", "window update", "tab 2 update"]); @@ -559,7 +559,7 @@ test("Window and tab events with static content execute", t => t.deepEqual(hits, ["window open", "tab 3 open"]); - const created = (globalThis.ui as UiMock).createdWindows[0]; + const created = (globalThis.ui).createdWindows[0]; call(created.onUpdate); t.deepEqual(hits, ["window open", "tab 3 open", "window update", "tab 3 update"]); @@ -607,7 +607,7 @@ test("Window layouts with tabs and static with padding", t => }); template.open(); - const created = (globalThis.ui as UiMock).createdWindows[0]; + const created = (globalThis.ui).createdWindows[0]; const secondTab = created.widgets; t.is(secondTab[0].text, "label 2"); t.is(secondTab[0].x, 30 + 2); @@ -684,7 +684,7 @@ test("Window layouts with tabs and static", t => }); template.open(); - const created = (globalThis.ui as UiMock).createdWindows[0]; + const created = (globalThis.ui).createdWindows[0]; function assertStaticWidgets(widgets: LabelWidget[]): void { t.is(widgets[0].text, "static label"); @@ -768,7 +768,7 @@ test("Window and tab rebind to stores on each tab change", t => }); template.open(); - const created = (globalThis.ui as UiMock).createdWindows[0]; + const created = (globalThis.ui).createdWindows[0]; const firstTab = created.widgets; t.is(firstTab[0].text, "static"); t.is(firstTab[0].tooltip, "hello"); @@ -854,11 +854,11 @@ test("Window is sized to tab size", t => }); template.open(); - const created = (globalThis.ui as UiMock).createdWindows[0]; + const created = (globalThis.ui).createdWindows[0]; t.is(created.width, 450); t.is(created.height, 300); - const button1 = created.widgets[0] as ButtonWidget; + const button1 = created.widgets[0]; t.is(button1.text, "tab button"); t.is(button1.x, 25 + 10); t.is(button1.y, 25 + 10 + 44); @@ -889,7 +889,7 @@ test("Window with tabs adjusts to resize", t => }); template.open(); - const created = (globalThis.ui as UiMock).createdWindows[0]; + const created = (globalThis.ui).createdWindows[0]; t.is(created.width, 200); t.is(created.height, 180); t.is(created.minWidth, 100); @@ -901,14 +901,14 @@ test("Window with tabs adjusts to resize", t => created.height = 300; call(created.onUpdate); - const button1 = created.widgets[0] as ButtonWidget; + const button1 = created.widgets[0]; t.is(button1.text, "static button"); t.is(button1.x, 10); t.is(button1.y, 10 + 15); t.is(button1.width, 400 - 20); t.is(button1.height, 300 - (20 + 15)); - const button2 = created.widgets[1] as ButtonWidget; + const button2 = created.widgets[1]; t.is(button2.text, "tab button"); t.is(button2.x, 10); t.is(button2.y, 10 + 44); @@ -939,17 +939,17 @@ test("Window with tabs does not resize if size has not changed", t => }); template.open(); - const created = (globalThis.ui as UiMock).createdWindows[0]; + const created = (globalThis.ui).createdWindows[0]; call(created.onUpdate); - const button1 = created.widgets[0] as ButtonWidget; + const button1 = created.widgets[0]; t.is(button1.text, "static button"); t.is(button1.x, 10); t.is(button1.y, 10 + 15); t.is(button1.width, 200 - 20); t.is(button1.height, 180 - (20 + 15)); - const button2 = created.widgets[1] as ButtonWidget; + const button2 = created.widgets[1]; t.is(button2.text, "tab button"); t.is(button2.x, 10); t.is(button2.y, 10 + 44); @@ -978,7 +978,7 @@ test("Window with tabs does auto resizes to tab content", t => }); template.open(); - const created = (globalThis.ui as UiMock).createdWindows[0]; + const created = (globalThis.ui).createdWindows[0]; t.is(created.width, 175 + 20); t.is(created.height, 60 + 20 + 44); t.is(created.minWidth, created.width); @@ -986,14 +986,14 @@ test("Window with tabs does auto resizes to tab content", t => t.is(created.maxWidth, created.width); t.is(created.maxHeight, created.height); - const button1 = created.widgets[0] as ButtonWidget; + const button1 = created.widgets[0]; t.is(button1.text, "static button"); t.is(button1.x, 10); t.is(button1.y, 10 + 15); t.is(button1.width, 500); t.is(button1.height, 800); - const button2 = created.widgets[1] as ButtonWidget; + const button2 = created.widgets[1]; t.is(button2.text, "tab button"); t.is(button2.x, 10); t.is(button2.y, 10 + 44); @@ -1026,7 +1026,7 @@ test("Window with tabs does auto resizes when tabs switch", t => }); template.open(); - const created = (globalThis.ui as UiMock).createdWindows[0]; + const created = (globalThis.ui).createdWindows[0]; t.is(created.width, 20 + 20); t.is(created.height, 70 + 20 + 44); t.is(created.minWidth, created.width); @@ -1034,7 +1034,7 @@ test("Window with tabs does auto resizes when tabs switch", t => t.is(created.maxWidth, created.width); t.is(created.maxHeight, created.height); - const button1 = created.widgets[0] as ButtonWidget; + const button1 = created.widgets[0]; t.is(button1.text, "tab 2 button"); t.is(button1.x, 10); t.is(button1.y, 10 + 44); @@ -1051,7 +1051,7 @@ test("Window with tabs does auto resizes when tabs switch", t => t.is(created.maxWidth, created.width); t.is(created.maxHeight, created.height); - const button2 = created.widgets[0] as ButtonWidget; + const button2 = created.widgets[0]; t.is(button2.text, "tab 1 button"); t.is(button2.x, 10); t.is(button2.y, 10 + 44); @@ -1090,7 +1090,7 @@ test("Window with tabs does single redraw after tabs switch", t => }); template.open(); - const created = (globalThis.ui as UiMock).createdWindows[0]; + const created = (globalThis.ui).createdWindows[0]; call(created.onUpdate); t.deepEqual(hits, []); @@ -1126,8 +1126,8 @@ test("Window with tabs can do layouts when tabs switch", t => }); template.open(); - const created = (globalThis.ui as UiMock).createdWindows[0]; - const button1 = created.widgets[0] as ButtonWidget; + const created = (globalThis.ui).createdWindows[0]; + const button1 = created.widgets[0]; t.is(button1.text, "tab 1 button"); t.is(button1.x, 10); t.is(button1.y, 10 + 44); @@ -1138,7 +1138,7 @@ test("Window with tabs can do layouts when tabs switch", t => call(created.onTabChange); call(created.onUpdate); - const button2 = created.widgets[0] as ButtonWidget; + const button2 = created.widgets[0]; t.is(button2.text, "tab 2 button"); t.is(button2.x, 10); t.is(button2.y, 10 + 44); @@ -1149,7 +1149,7 @@ test("Window with tabs can do layouts when tabs switch", t => call(created.onTabChange); call(created.onUpdate); - const button3 = created.widgets[0] as ButtonWidget; + const button3 = created.widgets[0]; t.is(button3.text, "tab 1 button"); t.is(button3.x, 10); t.is(button3.y, 10 + 44); @@ -1178,18 +1178,18 @@ test("Window with tabs has auto static widgets with pixel tab size", t => }); template.open(); - const created = (globalThis.ui as UiMock).createdWindows[0]; + const created = (globalThis.ui).createdWindows[0]; t.is(created.width, 400); t.is(created.height, 350); - const button1 = created.widgets[0] as ButtonWidget; + const button1 = created.widgets[0]; t.is(button1.text, "static button"); t.is(button1.x, 10); t.is(button1.y, 10 + 15); t.is(button1.width, 400 - 20); t.is(button1.height, 350 - (20 + 15)); - const button2 = created.widgets[1] as ButtonWidget; + const button2 = created.widgets[1]; t.is(button2.text, "tab 1 button"); t.is(button2.x, 10); t.is(button2.y, 10 + 44); @@ -1218,18 +1218,18 @@ test("Window with tabs has pixel static widgets in auto container with pixel tab }); template.open(); - const created = (globalThis.ui as UiMock).createdWindows[0]; + const created = (globalThis.ui).createdWindows[0]; t.is(created.width, 400); t.is(created.height, 350); - const button1 = created.widgets[0] as ButtonWidget; + const button1 = created.widgets[0]; t.is(button1.text, "static button"); t.is(button1.x, 10); t.is(button1.y, 10 + 15); t.is(button1.width, 120); t.is(button1.height, 85); - const button2 = created.widgets[1] as ButtonWidget; + const button2 = created.widgets[1]; t.is(button2.text, "tab 1 button"); t.is(button2.x, 10); t.is(button2.y, 10 + 44); @@ -1261,20 +1261,20 @@ test("Window with tabs has weighted static widgets with auto tab size", t => }); template.open(); - const created = (globalThis.ui as UiMock).createdWindows[0]; + const created = (globalThis.ui).createdWindows[0]; const expectedWindowWidth = (230 + 24 + 6); const expectedWindowHeight = (135 + 24 + 6 + 44); t.is(created.width, expectedWindowWidth); t.is(created.height, expectedWindowHeight); - const button1 = created.widgets[0] as ButtonWidget; + const button1 = created.widgets[0]; t.is(button1.text, "static button"); t.is(button1.x, 12 + 7); t.is(button1.y, 12 + 7 + 15); t.is(button1.width, expectedWindowWidth - (24 + 14)); t.is(button1.height, expectedWindowHeight - (24 + 14 + 15)); - const button2 = created.widgets[1] as ButtonWidget; + const button2 = created.widgets[1]; t.is(button2.text, "tab 1 button"); t.is(button2.x, 12 + 3); t.is(button2.y, 12 + 3 + 44); @@ -1324,7 +1324,7 @@ test("Window with tabs has mixed static widgets in auto container with multiple t.is(window.width, expectedWidth); t.is(window.height, expectedHeight); - const tab = created.widgets as ButtonWidget[]; + const tab = created.widgets; t.is(tab[0].text, "static pixel button"); t.is(tab[0].x, 10); t.is(tab[0].y, 10 + 15); @@ -1342,7 +1342,7 @@ test("Window with tabs has mixed static widgets in auto container with multiple t.is(tab[2].height, expectedHeight - (20 + 44)); } - const created = (globalThis.ui as UiMock).createdWindows[0]; + const created = (globalThis.ui).createdWindows[0]; verifyWindow(created, 170, 220, "tab 2"); created.tabIndex = 0; @@ -1415,7 +1415,7 @@ test("Window with tabs has mixed static widgets in pixel container with multiple t.is(window.width, expectedWidth); t.is(window.height, expectedHeight); - const tab = created.widgets as ButtonWidget[]; + const tab = created.widgets; t.is(tab[0].text, "static pixel button"); t.is(tab[0].x, 12); t.is(tab[0].y, 12 + 15); @@ -1433,7 +1433,7 @@ test("Window with tabs has mixed static widgets in pixel container with multiple t.is(tab[2].height, expectedHeight - (24 + 44)); } - const created = (globalThis.ui as UiMock).createdWindows[0]; + const created = (globalThis.ui).createdWindows[0]; verifyWindow(created, 250, 350, "tab 3"); call(created.onUpdate); @@ -1502,11 +1502,11 @@ test("Window with tabs relayouts static on tab switch if window size changed", t }); template.open(); - const created = (globalThis.ui as UiMock).createdWindows[0]; + const created = (globalThis.ui).createdWindows[0]; t.is(created.width, 150); t.is(created.height, 280); - const firstTab = created.widgets as ButtonWidget[]; + const firstTab = created.widgets; t.is(firstTab[0].text, "static button"); t.is(firstTab[0].x, 10 + 7); t.is(firstTab[0].y, 10 + 7 + 15); @@ -1524,7 +1524,7 @@ test("Window with tabs relayouts static on tab switch if window size changed", t t.is(created.width, 265); t.is(created.height, 120); - const secondTab = created.widgets as ButtonWidget[]; + const secondTab = created.widgets; t.is(secondTab[0].text, "static button"); t.is(secondTab[0].x, 10 + 7); t.is(secondTab[0].y, 10 + 7 + 15); @@ -1557,17 +1557,17 @@ test("Window with tabs does auto resizes to body size changes", t => }); template.open(); - const created = (globalThis.ui as UiMock).createdWindows[0]; + const created = (globalThis.ui).createdWindows[0]; t.is(created.width, 100 + 12); t.is(created.height, 30 + 12 + 8 + 30 + 44); - const button1 = created.widgets[0] as ButtonWidget; + const button1 = created.widgets[0]; t.is(button1.x, 6); t.is(button1.y, 44 + 6); t.is(button1.width, 100); t.is(button1.height, 30); - const button2 = created.widgets[1] as ButtonWidget; + const button2 = created.widgets[1]; t.is(button2.x, 6); t.is(button2.y, 44 + 6 + 30 + 8); t.is(button2.width, 100); @@ -1602,7 +1602,7 @@ test("Window with tabs and bindings resets properly to first tab after close", t }); template.open(); - const created1 = (globalThis.ui as UiMock).createdWindows[0]; + const created1 = (globalThis.ui).createdWindows[0]; t.is(created1.width, 200); t.is(created1.height, 100); t.deepEqual(created1.widgets, []); @@ -1613,7 +1613,7 @@ test("Window with tabs and bindings resets properly to first tab after close", t const tab1widgets = created1.widgets; t.is(tab1widgets.length, 1); - const button1 = created1.widgets[0] as ButtonWidget; + const button1 = created1.widgets[0]; t.is(button1.x, 5); t.is(button1.y, 44 + 5); t.is(button1.width, 200 - 10); @@ -1623,7 +1623,7 @@ test("Window with tabs and bindings resets properly to first tab after close", t created1.onClose!(); template.open(); - const created2 = (globalThis.ui as UiMock).createdWindows[0]; + const created2 = (globalThis.ui).createdWindows[0]; t.is(created2.tabIndex, 0); t.deepEqual(created2.widgets, []); }); diff --git a/tests/windows/widgetBinder.tests.ts b/tests/windows/widgetBinder.tests.ts index 1b19a39..b851eb9 100644 --- a/tests/windows/widgetBinder.tests.ts +++ b/tests/windows/widgetBinder.tests.ts @@ -6,6 +6,7 @@ import { mutable } from "@src/utilities/mutable"; import { noop } from "@src/utilities/noop"; import { WidgetBinder } from "@src/windows/binders/widgetBinder"; import { FrameBuilder } from "@src/windows/frames/frameBuilder"; +import { ParentWindow } from "@src/windows/parentWindow"; import { addToWidgetMap } from "@src/windows/widgets/widgetMap"; import test from "ava"; import Mock from "openrct2-mocks"; @@ -58,7 +59,7 @@ test("read() sets store in window frame", t => type: "label", x: 0, y: 0, height: 10, width: 100, }; - const output = new FrameBuilder({ redraw: noop }, {}, [], undefined); + const output = new FrameBuilder({ redraw: noop }, {}, []); output.add(label); const storeNumber = store(25); @@ -86,7 +87,7 @@ test("read() sets store through converter", t => type: "label", x: 0, y: 0, height: 10, width: 100, isVisible: false }; - const output = new FrameBuilder({ redraw: noop }, {}, [], undefined); + const output = new FrameBuilder({ redraw: noop }, {}, []); output.add(label); const storeNumber = store("visible"); diff --git a/tests/windows/window.tests.ts b/tests/windows/window.tests.ts index e081719..a5d92f2 100644 --- a/tests/windows/window.tests.ts +++ b/tests/windows/window.tests.ts @@ -37,14 +37,14 @@ test("Simple window with widgets", t => }); template.open(); - const created = (globalThis.ui as UiMock).createdWindows[0]; + const created = (globalThis.ui).createdWindows[0]; t.truthy(created); t.is(created.title, "test window"); t.is(created.width, 200); t.is(created.height, 150 + 15); t.is(created.widgets.length, 4); - const label1 = created.widgets[0] as LabelWidget; + const label1 = created.widgets[0]; t.is(label1.type, "label"); t.is(label1.text, "hello world"); t.is(label1.x, 0); @@ -52,7 +52,7 @@ test("Simple window with widgets", t => t.is(label1.width, 200); t.is(label1.height, 50); - const button1 = created.widgets[1] as ButtonWidget; + const button1 = created.widgets[1]; t.is(button1.type, "button"); t.is(button1.text, "left button"); t.is(button1.x, 0); @@ -60,7 +60,7 @@ test("Simple window with widgets", t => t.is(button1.width, 100); t.is(button1.height, 50); - const button2 = created.widgets[2] as ButtonWidget; + const button2 = created.widgets[2]; t.is(button2.type, "button"); t.is(button2.text, "right button"); t.is(button2.x, 100); @@ -68,7 +68,7 @@ test("Simple window with widgets", t => t.is(button2.width, 100); t.is(button2.height, 50); - const label2 = created.widgets[3] as LabelWidget; + const label2 = created.widgets[3]; t.is(label2.type, "label"); t.is(label2.text, "big area"); t.is(label2.textAlign, "centred"); @@ -92,14 +92,14 @@ test("Simple window with single widget", t => }); template.open(); - const created = (globalThis.ui as UiMock).createdWindows[0]; + const created = (globalThis.ui).createdWindows[0]; t.truthy(created); t.is(created.title, "test window"); t.is(created.width, 200); t.is(created.height, 150 + 15); t.is(created.widgets.length, 1); - const button1 = created.widgets[0] as ButtonWidget; + const button1 = created.widgets[0]; t.is(button1.type, "button"); t.is(button1.text, "hello world"); t.is(button1.x, 0); @@ -129,14 +129,14 @@ test("Simple window with viewmodel", t => })); template.open(model); - const created = (globalThis.ui as UiMock).createdWindows[0]; + const created = (globalThis.ui).createdWindows[0]; t.truthy(created); t.is(created.title, "better window"); t.is(created.width, 200); t.is(created.height, 150 + 15); t.is(created.widgets.length, 1); - const button1 = created.widgets[0] as ButtonWidget; + const button1 = created.widgets[0]; t.is(button1.type, "button"); t.is(button1.text, "hello world"); t.is(button1.x, 0); @@ -165,14 +165,14 @@ test("Simple window with single 100% widget", t => }); template.open(); - const created = (globalThis.ui as UiMock).createdWindows[0]; + const created = (globalThis.ui).createdWindows[0]; t.truthy(created); t.is(created.title, "test window"); t.is(created.width, 200); t.is(created.height, 150 + 15); t.is(created.widgets.length, 1); - const button1 = created.widgets[0] as ButtonWidget; + const button1 = created.widgets[0]; t.is(button1.type, "button"); t.is(button1.text, "hello world"); t.is(button1.x, 8); @@ -196,14 +196,14 @@ test("Simple window with default padding and spacing", t => }); template.open(); - const created = (globalThis.ui as UiMock).createdWindows[0]; + const created = (globalThis.ui).createdWindows[0]; t.truthy(created); t.is(created.title, "test window"); t.is(created.width, 200); t.is(created.height, 75 + 15); t.is(created.widgets.length, 2); - const button1 = created.widgets[0] as ButtonWidget; + const button1 = created.widgets[0]; t.is(button1.type, "button"); t.is(button1.text, "hello one"); t.is(button1.x, 5); @@ -211,7 +211,7 @@ test("Simple window with default padding and spacing", t => t.is(button1.width, 200 - 10); t.is(button1.height, 30); // rounded down from 30.5 - const button2 = created.widgets[1] as ButtonWidget; + const button2 = created.widgets[1]; t.is(button2.type, "button"); t.is(button2.text, "hello two"); t.is(button2.x, 5); @@ -245,7 +245,7 @@ test("Window adjusts to resize", t => }); template.open(); - const created = (globalThis.ui as UiMock).createdWindows[0]; + const created = (globalThis.ui).createdWindows[0]; t.is(created.width, 200); t.is(created.height, 150 + 15); t.is(created.minWidth, 100); @@ -257,25 +257,25 @@ test("Window adjusts to resize", t => created.height = 300 + 15; call(created.onUpdate); - const label1 = created.widgets[0] as LabelWidget; + const label1 = created.widgets[0]; t.is(label1.x, 0); t.is(label1.y, 15 + 2); t.is(label1.width, 400); t.is(label1.height, 100); - const button1 = created.widgets[1] as ButtonWidget; + const button1 = created.widgets[1]; t.is(button1.x, 0); t.is(button1.y, 100 + 15); t.is(button1.width, 200); t.is(button1.height, 100); - const button2 = created.widgets[2] as ButtonWidget; + const button2 = created.widgets[2]; t.is(button2.x, 200); t.is(button2.y, 100 + 15); t.is(button2.width, 200); t.is(button2.height, 100); - const label2 = created.widgets[3] as LabelWidget; + const label2 = created.widgets[3]; t.is(label2.x, 0); t.is(label2.y, 200 + 2 + 15); t.is(label2.width, 400); @@ -307,28 +307,28 @@ test("Window does not resize if size hasn't changed", t => }); template.open(); - const created = (globalThis.ui as UiMock).createdWindows[0]; + const created = (globalThis.ui).createdWindows[0]; call(created.onUpdate); - const label1 = created.widgets[0] as LabelWidget; + const label1 = created.widgets[0]; t.is(label1.x, 0); t.is(label1.y, 15 + 2); t.is(label1.width, 200); t.is(label1.height, 50); - const button1 = created.widgets[1] as ButtonWidget; + const button1 = created.widgets[1]; t.is(button1.x, 0); t.is(button1.y, 50 + 15); t.is(button1.width, 100); t.is(button1.height, 50); - const button2 = created.widgets[2] as ButtonWidget; + const button2 = created.widgets[2]; t.is(button2.x, 100); t.is(button2.y, 50 + 15); t.is(button2.width, 100); t.is(button2.height, 50); - const label2 = created.widgets[3] as LabelWidget; + const label2 = created.widgets[3]; t.is(label2.x, 0); t.is(label2.y, 100 + 2 + 15); t.is(label2.width, 200); @@ -349,7 +349,7 @@ test("Window does auto resizes to content", t => }); template.open(); - const created = (globalThis.ui as UiMock).createdWindows[0]; + const created = (globalThis.ui).createdWindows[0]; t.is(created.width, 100 + 10); t.is(created.height, 30 + 10 + 15); t.is(created.minWidth, created.width); @@ -357,7 +357,7 @@ test("Window does auto resizes to content", t => t.is(created.maxWidth, created.width); t.is(created.maxHeight, created.height); - const button1 = created.widgets[0] as ButtonWidget; + const button1 = created.widgets[0]; t.is(button1.x, 5); t.is(button1.y, 15 + 5); t.is(button1.width, 100); @@ -380,16 +380,16 @@ test("Window does auto resizes to nested content", t => }); template.open(); - const created = (globalThis.ui as UiMock).createdWindows[0]; + const created = (globalThis.ui).createdWindows[0]; t.is(created.width, 100 + 12 + 10); t.is(created.height, 30 + 12 + 10 + 15); - const box1 = created.widgets[0] as GroupBoxWidget; + const box1 = created.widgets[0]; t.is(box1.x, 5); t.is(box1.y, 15 + 5 - 4); t.is(box1.width, 100 + 12); t.is(box1.height, 30 + 12 + 4); - const button1 = created.widgets[1] as ButtonWidget; + const button1 = created.widgets[1]; t.is(button1.x, 5 + 6); t.is(button1.y, 15 + 6 + 5); t.is(button1.width, 100); @@ -412,17 +412,17 @@ test("Window does auto resizes to body size changes", t => }); template.open(); - const created = (globalThis.ui as UiMock).createdWindows[0]; + const created = (globalThis.ui).createdWindows[0]; t.is(created.width, 100 + 10); t.is(created.height, 30 + 10 + 8 + 30 + 15); - const button1 = created.widgets[0] as ButtonWidget; + const button1 = created.widgets[0]; t.is(button1.x, 5); t.is(button1.y, 15 + 5); t.is(button1.width, 100); t.is(button1.height, 30); - const button2 = created.widgets[1] as ButtonWidget; + const button2 = created.widgets[1]; t.is(button2.x, 5); t.is(button2.y, 15 + 5 + 30 + 8); t.is(button2.width, 100); @@ -459,7 +459,7 @@ test("Window with auto resize errors with relative child width", t => { template.open(); }); - t.is(error?.message, "Window body width must resolve to absolute size for \"auto\" window size."); + t.is(error.message, "Window body width must resolve to absolute size for \"auto\" window size."); }); @@ -479,7 +479,7 @@ test("Window with auto resize errors with relative child height", t => { template.open(); }); - t.is(error?.message, "Window body height must resolve to absolute size for \"auto\" window size."); + t.is(error.message, "Window body height must resolve to absolute size for \"auto\" window size."); }); @@ -499,7 +499,7 @@ test("Window with auto resize errors with relative window padding", t => { template.open(); }); - t.is(error?.message, "Window padding must be absolute for \"auto\" window size."); + t.is(error.message, "Window padding must be absolute for \"auto\" window size."); }); @@ -529,12 +529,12 @@ test("Window updates to bindings", t => }); template.open(); - const created = (globalThis.ui as UiMock).createdWindows[0]; + const created = (globalThis.ui).createdWindows[0]; - const label1 = created.widgets[0] as LabelWidget; + const label1 = created.widgets[0]; t.is(label1.text, "test"); t.is(label1.textAlign, "centred"); - const button1 = created.widgets[1] as ButtonWidget; + const button1 = created.widgets[1]; t.is(button1.text, "click me"); t.true(button1.isPressed); @@ -566,7 +566,7 @@ test("Window title is bindable", t => }); const instance1 = template.open(); - const created1 = (globalThis.ui as UiMock).createdWindows[0]; + const created1 = (globalThis.ui).createdWindows[0]; t.is(created1.title, "test"); viewmodel.title.set("blub"); @@ -577,7 +577,7 @@ test("Window title is bindable", t => t.is(created1.title, "blub"); // dont update on close template.open(); - const created2 = (globalThis.ui as UiMock).createdWindows[0]; + const created2 = (globalThis.ui).createdWindows[0]; t.is(created1.title, "blub"); t.is(created2.title, "bobby"); }); @@ -596,9 +596,9 @@ test("Window applies padding", t => }); template.open(); - const created = (globalThis.ui as UiMock).createdWindows[0]; + const created = (globalThis.ui).createdWindows[0]; - const button1 = created.widgets[0] as ButtonWidget; + const button1 = created.widgets[0]; t.is(button1.x, 15); t.is(button1.y, 15 + 15); t.is(button1.width, 120); @@ -621,12 +621,12 @@ test("Window applies padding to resizes", t => }); template.open(); - const created = (globalThis.ui as UiMock).createdWindows[0]; + const created = (globalThis.ui).createdWindows[0]; created.width = 250; created.height = 300; call(created.onUpdate); - const button1 = created.widgets[0] as ButtonWidget; + const button1 = created.widgets[0]; t.is(button1.x, 20); t.is(button1.y, 20 + 15); t.is(button1.width, 210); @@ -641,9 +641,9 @@ test("Window events are triggered", t => const template = window({ width: 150, height: 100, - onOpen: ((c: FrameContext) => hits.push(["open", c])) as unknown as (() => void), - onUpdate: ((c: FrameContext) => hits.push(["update", c])) as unknown as (() => void), - onClose: ((c: FrameContext) => hits.push(["close", c])) as unknown as (() => void), + onOpen: <() => void>((c: FrameContext) => hits.push(["open", c])), + onUpdate: <() => void>((c: FrameContext) => hits.push(["update", c])), + onClose: <() => void>((c: FrameContext) => hits.push(["close", c])), content: [ button({ image: 342 }), label({ text: "hello"}) @@ -651,7 +651,7 @@ test("Window events are triggered", t => }); template.open(); - const created = (globalThis.ui as UiMock).createdWindows[0]; + const created = (globalThis.ui).createdWindows[0]; t.is(hits.length, 1); t.is(hits[0][0], "open"); t.truthy(hits[0][1]); @@ -697,7 +697,7 @@ test("Window focuses on double open", t => }); template.open(); - const created = (globalThis.ui as UiMock).createdWindows; + const created = (globalThis.ui).createdWindows; t.is(created.length, 1); t.is(created[0].title, "test window"); t.true(created[0].isOpen); @@ -721,7 +721,7 @@ test("Window can be reopened after closing", t => }); template.open(); - const created = (globalThis.ui as UiMock).createdWindows; + const created = (globalThis.ui).createdWindows; t.is(created.length, 1); t.is(created[0].title, "test window"); @@ -744,7 +744,7 @@ test("Window opens at unspecified default position", t => }); template.open(); - const created = (globalThis.ui as UiMock).createdWindows; + const created = (globalThis.ui).createdWindows; t.is(created.length, 1); t.is(created[0].title, "test window"); t.is(created[0].x, undefined); @@ -763,7 +763,7 @@ test("Window opens at specified default position", t => }); template.open(); - const created = (globalThis.ui as UiMock).createdWindows; + const created = (globalThis.ui).createdWindows; t.is(created.length, 1); t.is(created[0].title, "test window"); t.is(created[0].x, undefined); @@ -782,7 +782,7 @@ test("Window opens at center position", t => }); template.open(); - const created = (globalThis.ui as UiMock).createdWindows; + const created = (globalThis.ui).createdWindows; t.is(created.length, 1); t.is(created[0].title, "test window"); t.is(created[0].x, (1920 / 2) - (150 / 2)); @@ -801,7 +801,7 @@ test("Window opens at specified position", t => }); template.open(); - const created = (globalThis.ui as UiMock).createdWindows; + const created = (globalThis.ui).createdWindows; t.is(created.length, 1); t.is(created[0].title, "test window"); t.is(created[0].x, 100); @@ -826,7 +826,7 @@ test("Window opens at center position after game window resize", t => uiMock.height = 720; template.open(); - const created = (globalThis.ui as UiMock).createdWindows; + const created = (globalThis.ui).createdWindows; t.is(created.length, 2); t.is(created[0].title, "test window"); t.is(created[0].x, (1280 / 2) - (150 / 2)); diff --git a/tsconfig.json b/tsconfig.json index ef69470..0a1c42e 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -22,7 +22,8 @@ }, "include": [ "./lib/**/*.ts", - "./src/**/*.ts" + "./src/**/*.ts", + "./tests/**/*.ts" ], "exclude": [ "./dist/**/*"