Skip to content

Commit

Permalink
Migrate interactors material-ui to deno
Browse files Browse the repository at this point in the history
Signed-off-by: Dmitriy Lazarev <w@kich.dev>
  • Loading branch information
wKich committed Aug 8, 2024
1 parent d6355ce commit 4586c05
Show file tree
Hide file tree
Showing 88 changed files with 451 additions and 3,627 deletions.
3 changes: 2 additions & 1 deletion deno.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
"./packages/core",
"./packages/globals",
"./packages/html",
"./packages/keyboard"
"./packages/keyboard",
"./packages/material-ui"
],
"compilerOptions": {
"lib": [
Expand Down
288 changes: 288 additions & 0 deletions deno.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion packages/core/test/extend.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { dom } from './helpers.ts';
import { Header, Link, Thing, HTML } from './fixtures.ts';

// eslint-disable-next-line @typescript-eslint/ban-ts-comment
//@ts-ignore
//@ts-ignore Create HTML Instance without a name
const HTMLWithNoLabel = HTML.extend()

describe('Interactor.extend', () => {
Expand Down
8 changes: 4 additions & 4 deletions packages/globals/test/globals.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ describe("@interactors/globals", () => {
beforeEach(() => {
globals.reset();
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
// @ts-ignore Reset jsdom state
delete globalThis.document;
});

Expand Down Expand Up @@ -61,9 +61,9 @@ describe("@interactors/globals", () => {
).toBe(action);
});

it("applies defined interaction wrapper", async () => {
let action = async () => "foo";
let removeWrapper = addInteractionWrapper(() => async () => "bar");
it("applies defined interaction wrapper", () => {
let action = async () => await Promise.resolve("foo");
let removeWrapper = addInteractionWrapper(() => async () => await Promise.resolve("bar"));
globals.wrapInteraction(
action,
{
Expand Down
1 change: 1 addition & 0 deletions packages/html/deno.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
},
"exports": "./mod.ts",
"imports": {
"@frontside/tsconfig": "npm:@frontside/tsconfig@^1.2.0",
"jsdom": "npm:jsdom@^24.0.0",
"parcel": "npm:parcel@^2.10.2",
"typedoc": "npm:typedoc@^0.25.13"
Expand Down
6 changes: 0 additions & 6 deletions packages/material-ui/.storybook/main.js

This file was deleted.

10 changes: 0 additions & 10 deletions packages/material-ui/bigtest.json

This file was deleted.

36 changes: 36 additions & 0 deletions packages/material-ui/deno.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
"name": "@interactors/material-ui",
"version": "5.0.0",
"tasks": {
"build:npm": "deno run -A tasks/build-npm.ts",
"docs": "rm -rf docs && typedoc --options typedoc.json --tsconfig tsconfig.docs.json",
"preview": "deno task docs && parcel docs/api/v4/index.html"
},
"exports": "./mod.ts",
"imports": {
"parcel": "npm:parcel@^2.10.2",
"typedoc": "npm:typedoc@^0.25.13"
},
"lint": {
"rules": {
"exclude": ["prefer-const", "require-yield", "no-slow-types"]
},
"exclude": [
"build",
"docs"
]
},
"fmt": {
"exclude": [
"build",
"docs",
"README.md"
]
},
"test": {
"exclude": [
"build",
"docs"
]
}
}
1 change: 1 addition & 0 deletions packages/material-ui/mod.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './src/index.ts'
70 changes: 0 additions & 70 deletions packages/material-ui/package.json

This file was deleted.

2 changes: 1 addition & 1 deletion packages/material-ui/src/accordion.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { HTML, innerText } from "@interactors/html";
import { isDisabled, isHTMLElement } from "./helpers";
import { isDisabled, isHTMLElement } from "./helpers.ts";

const getSummary = (element: HTMLElement) => element.querySelector('[class*="MuiAccordionSummary-root"]');
const isExpanded = (element: HTMLElement) => getSummary(element)?.getAttribute("aria-expanded") == "true";
Expand Down
2 changes: 1 addition & 1 deletion packages/material-ui/src/bottom-navigation.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { click, createInteractor, innerText } from "@interactors/html";
import { isHTMLElement } from "./helpers";
import { isHTMLElement } from "./helpers.ts";

const BottomNavigationAction = createInteractor<HTMLButtonElement>("MUIBottomNavigationAction")
.selector('button[class*="MuiBottomNavigationAction-root"]')
Expand Down
2 changes: 1 addition & 1 deletion packages/material-ui/src/button.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { HTML, innerText } from "@interactors/html";
import { isDisabled } from "./helpers";
import { isDisabled } from "./helpers.ts";

const ButtonInteractor = HTML.extend<HTMLButtonElement | HTMLLinkElement>("MUIButton")
.selector(
Expand Down
7 changes: 4 additions & 3 deletions packages/material-ui/src/calendar.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { click, HTML, createInteractor, including, Interaction, Interactor, not, innerText } from "@interactors/html";
import { delay, isHTMLElement } from "./helpers";
import { DatePickerUtils } from "./types";
import { click, HTML, createInteractor, including, not, innerText } from "@interactors/html";
import type { Interaction, Interactor } from '@interactors/html';
import { delay, isHTMLElement } from "./helpers.ts";
import type { DatePickerUtils } from "./types.ts";

function getHeaderElement(element: HTMLElement) {
let header = element.parentElement?.querySelector('[class*="MuiPickersCalendarHeader-switchHeader"]');
Expand Down
2 changes: 1 addition & 1 deletion packages/material-ui/src/date-field.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { TextField } from "@interactors/html";
import { dispatchChange, setValue } from "./helpers";
import { dispatchChange, setValue } from "./helpers.ts";

const DateFieldInteractor = TextField.extend<HTMLInputElement>("DateField")
.selector('input[type="date"]')
Expand Down
2 changes: 1 addition & 1 deletion packages/material-ui/src/datetime-field.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { TextField } from "@interactors/html";
import { dispatchChange, setValue } from "./helpers";
import { dispatchChange, setValue } from "./helpers.ts";

const DateTimeFieldInteractor = TextField.extend<HTMLInputElement>("DateTimeField")
.selector('input[type="datetime-local"]')
Expand Down
2 changes: 1 addition & 1 deletion packages/material-ui/src/dialog.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { click, HTML, innerText } from "@interactors/html";
import { isHTMLElement } from "./helpers";
import { isHTMLElement } from "./helpers.ts";

const DialogInteractor = HTML.extend("MUIDialog")
.selector('[class*="MuiDialog-root"][role="presentation"]:not([aria-hidden="true"])')
Expand Down
2 changes: 1 addition & 1 deletion packages/material-ui/src/form-control.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { HTML, innerText } from "@interactors/html";
import { isHTMLElement } from "./helpers";
import { isHTMLElement } from "./helpers.ts";

function getLabelElement(root: HTMLElement) {
let label = root.querySelector('label[class*="MuiFormLabel-root"]');
Expand Down
2 changes: 1 addition & 1 deletion packages/material-ui/src/form-field-filters.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { innerText } from "@interactors/html";
import { getInputLabel, isHTMLElement } from "./helpers";
import { getInputLabel, isHTMLElement } from "./helpers.ts";

export const createFormFieldFilters = <E extends HTMLInputElement | HTMLSelectElement | HTMLTextAreaElement>(): {
valid: (element: E) => boolean;
Expand Down
4 changes: 2 additions & 2 deletions packages/material-ui/src/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,12 @@ export function setValue(element: HTMLInputElement, value: string): void {
}

export function dispatchChange(element: HTMLElement): boolean {
let Event = element.ownerDocument.defaultView?.Event || window.Event;
let Event = element.ownerDocument.defaultView?.Event || globalThis.Event;
return element.dispatchEvent(new Event("change", { bubbles: true, cancelable: false }));
}

export function dispatchMouseDown(element: HTMLElement, options: MouseEventInit = {}): boolean {
let MouseEvent = element.ownerDocument.defaultView?.MouseEvent || window.MouseEvent;
let MouseEvent = element.ownerDocument.defaultView?.MouseEvent || globalThis.MouseEvent;
return element.dispatchEvent(
new MouseEvent("mousedown", Object.assign({ bubbles: true, cancelable: true }, options))
);
Expand Down
50 changes: 25 additions & 25 deletions packages/material-ui/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,30 +13,30 @@ export {
TextField as HTMLTextField,
} from "@interactors/html";

export * from "./types";
export * from "./types.ts";

export * from "./date-field";
export * from "./time-field";
export * from "./datetime-field";
export * from "./date-field.ts";
export * from "./time-field.ts";
export * from "./datetime-field.ts";

export * from "./checkbox";
export * from "./calendar";
export * from "./accordion";
export * from "./menu";
export * from "./switch";
export * from "./bottom-navigation";
export * from "./link";
export * from "./list";
export * from "./menu";
export * from "./tabs";
export * from "./select";
export * from "./native-select";
export * from "./popover";
export * from "./text-field";
export * from "./button";
export * from "./snackbar";
export * from "./form-control";
export * from "./dialog";
export * from "./fab";
export * from "./slider";
export * from "./radio";
export * from "./checkbox.ts";
export * from "./calendar.ts";
export * from "./accordion.ts";
export * from "./menu.ts";
export * from "./switch.ts";
export * from "./bottom-navigation.ts";
export * from "./link.ts";
export * from "./list.ts";
export * from "./menu.ts";
export * from "./tabs.ts";
export * from "./select.ts";
export * from "./native-select.ts";
export * from "./popover.ts";
export * from "./text-field.ts";
export * from "./button.ts";
export * from "./snackbar.ts";
export * from "./form-control.ts";
export * from "./dialog.ts";
export * from "./fab.ts";
export * from "./slider.ts";
export * from "./radio.ts";
6 changes: 3 additions & 3 deletions packages/material-ui/src/menu.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { click, HTML, createInteractor } from "@interactors/html";
import { Button } from "./button";
import { isDisabled } from "./helpers";
import { Button } from "./button.ts";
import { isDisabled } from "./helpers.ts";

const MenuItemInteractor = HTML.extend<HTMLElement>("MUIMenuItem")
.selector('[class*="MuiMenuItem-root"][role="menuitem"]')
Expand All @@ -22,7 +22,7 @@ const MenuInteractor = Button.extend("MUIMenu")
.selector(`${Button().options.specification.selector as string}[aria-haspopup="true"]`)
.filters({ menuId: (element) => element.getAttribute("aria-controls") ?? "" })
.actions({
open: async ({ perform }) => perform((element) => click(element)),
open: async ({ perform }) => await perform((element) => click(element)),
click: async (interactor, value: string) => {
await interactor.perform((element) => click(element));

Expand Down
4 changes: 2 additions & 2 deletions packages/material-ui/src/native-select.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Select, MultiSelect } from "@interactors/html";
import { createFormFieldFilters } from "./form-field-filters";
import { GetElementType } from "./types";
import { createFormFieldFilters } from "./form-field-filters.ts";
import type { GetElementType } from "./types.ts";

const NativeSelectInteractor = Select.extend("MUINativeSelect").filters(
createFormFieldFilters<GetElementType<typeof Select>>()
Expand Down
2 changes: 1 addition & 1 deletion packages/material-ui/src/popover.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { HTML } from "@interactors/html";
import { isHTMLElement } from "./helpers";
import { isHTMLElement } from "./helpers.ts";

const PopoverInteractor = HTML.extend("MUIPopover")
.selector('[class*="MuiPopover-root"][role="presentation"]')
Expand Down
2 changes: 1 addition & 1 deletion packages/material-ui/src/radio.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { RadioButton, isVisible } from "@interactors/html";
import { isHTMLElement } from "./helpers";
import { isHTMLElement } from "./helpers.ts";

const RadioInteractor = RadioButton.extend("Radio")
.selector('[class*="MuiRadio-root"] input[type=radio]')
Expand Down
6 changes: 3 additions & 3 deletions packages/material-ui/src/select.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { click, HTML, createInteractor, Interactor, innerText } from "@interactors/html";
import { createFormFieldFilters } from "./form-field-filters";
import { isDefined, isHTMLElement, delay, dispatchMouseDown, getInputLabel, isDisabled } from "./helpers";
import { click, HTML, createInteractor, type Interactor, innerText } from "@interactors/html";
import { createFormFieldFilters } from "./form-field-filters.ts";
import { isDefined, isHTMLElement, delay, dispatchMouseDown, getInputLabel, isDisabled } from "./helpers.ts";

export const SelectOption = HTML.extend<HTMLLIElement>("MUISelectOption")
.selector('li[role="option"]')
Expand Down
2 changes: 1 addition & 1 deletion packages/material-ui/src/slider.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { HTML, innerText } from "@interactors/html";
import { isDefined } from "./helpers";
import { isDefined } from "./helpers.ts";

function isDisabled(element: Element) {
return element.className.includes("Mui-disabled");
Expand Down
2 changes: 1 addition & 1 deletion packages/material-ui/src/snackbar.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { HTML, innerText } from "@interactors/html";
import { isHTMLElement } from "./helpers";
import { isHTMLElement } from "./helpers.ts";

const SnackbarInteractor = HTML.extend("MUISnackbar")
.selector('[class*="MuiSnackbar-root"]')
Expand Down
2 changes: 1 addition & 1 deletion packages/material-ui/src/switch.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Checkbox } from "./checkbox";
import { Checkbox } from "./checkbox.ts";

const SwitchInteractor = Checkbox.extend("MUISwitch").selector('[class*="MuiSwitch-input"]');

Expand Down
2 changes: 1 addition & 1 deletion packages/material-ui/src/tabs.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { HTML, innerText } from "@interactors/html";
import { isDisabled, isHTMLElement } from "./helpers";
import { isDisabled, isHTMLElement } from "./helpers.ts";

const TabInteractor = HTML.extend<HTMLElement>("MUITab")
.selector('[class*="MuiTab-root"][role="tab"]')
Expand Down
Loading

0 comments on commit 4586c05

Please sign in to comment.