Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: Migrate LiteElements #2145

Merged
merged 7 commits into from
Nov 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion frontend/src/components/screencast.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ type CloseMessage = Message & {
@localized()
export class Screencast extends BtrixElement {
static baseUrl = `${window.location.protocol === "https:" ? "wss" : "ws"}:${
process.env.WEBSOCKET_HOST || window.location.host
// Defined in webpack:
window.process.env.WEBSOCKET_HOST || window.location.host
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated to work with test runner

}/watch`;
static maxRetries = 10;

Expand Down
1 change: 0 additions & 1 deletion frontend/src/components/ui/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import("./copy-field");
import("./details");
import("./file-list");
import("./inline-input");
import("./input");
import("./language-select");
import("./locale-picker");
import("./markdown-editor");
Expand Down
1 change: 0 additions & 1 deletion frontend/src/components/ui/input/index.ts

This file was deleted.

55 changes: 0 additions & 55 deletions frontend/src/components/ui/input/input.css

This file was deleted.

120 changes: 0 additions & 120 deletions frontend/src/components/ui/input/input.ts

This file was deleted.

19 changes: 11 additions & 8 deletions frontend/src/features/accounts/sign-up-form.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { localized, msg, str } from "@lit/localize";
import type { SlInput } from "@shoelace-style/shoelace";
import type { ZxcvbnResult } from "@zxcvbn-ts/core";
import { customElement, property, state } from "lit/decorators.js";
import { when } from "lit/directives/when.js";
import debounce from "lodash/fp/debounce";

import type { Input as BtrixInput } from "@/components/ui/input";
import type { UserOrgInviteInfo, UserRegisterResponseData } from "@/types/user";
import type { UnderlyingFunction } from "@/types/utils";
import AuthService from "@/utils/AuthService";
Expand Down Expand Up @@ -97,33 +97,35 @@ export class SignUpForm extends LiteElement {
/>
`
: html`
<btrix-input
<sl-input
id="email"
name="email"
type="email"
label=${msg("Enter your email")}
placeholder=${msg("you@email.com")}
autocomplete="email"
class="hide-required-content"
required
>
</btrix-input>
</sl-input>
`}
</div>
<div class="mb-5">
<btrix-input
<sl-input
id="password"
name="password"
type="password"
label="${msg("Password")}"
minlength=${PASSWORD_MINLENGTH}
autocomplete="new-password"
passwordToggle
class="hide-required-content"
required
@input=${this.onPasswordInput as UnderlyingFunction<
typeof this.onPasswordInput
>}
>
</btrix-input>
</sl-input>
<p class="mt-2 text-xs text-neutral-500">
${msg(
str`Choose a strong password between ${PASSWORD_MINLENGTH}–${PASSWORD_MAXLENGTH} characters.`,
Expand All @@ -132,15 +134,16 @@ export class SignUpForm extends LiteElement {
${when(this.pwStrengthResults, this.renderPasswordStrength)}
</div>
<div class="mb-5">
<btrix-input
<sl-input
id="name"
name="name"
label=${msg("Your name")}
autocomplete="nickname"
minlength="2"
class="hide-required-content"
required
>
</btrix-input>
</sl-input>
<p class="mt-2 text-xs text-neutral-500">
${msg(
"Your full name, nickname, or another name that org collaborators can see.",
Expand Down Expand Up @@ -172,7 +175,7 @@ export class SignUpForm extends LiteElement {
`;

private readonly onPasswordInput = debounce(150)(async (e: InputEvent) => {
const { value } = e.target as BtrixInput;
const { value } = e.target as SlInput;
if (!value || value.length < 4) {
this.pwStrengthResults = null;
return;
Expand Down
11 changes: 9 additions & 2 deletions frontend/src/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { expect, fixture } from "@open-wc/testing";
import { html } from "lit";
import { restore, stub } from "sinon";

import AuthService from "./utils/AuthService";
Expand Down Expand Up @@ -50,8 +51,14 @@ describe("browsertrix-app", () => {
username: "test-auth@example.com",
}),
);
const el = await fixture("<browsertrix-app></browsertrix-app>");
expect(el).lightDom.descendants("btrix-home");
const el = await fixture<App>(html` <browsertrix-app></browsertrix-app>`);
expect(el.shadowRoot?.querySelector("btrix-home")).to.exist;
});

it("renders home when not authenticated", async () => {
stub(AuthService, "initSessionStorage").returns(Promise.resolve(null));
const el = await fixture<App>(html` <browsertrix-app></browsertrix-app>`);
expect(el.shadowRoot?.querySelector("btrix-home")).to.exist;
});

// TODO move tests to AuthService
Expand Down
Loading