-
-
Notifications
You must be signed in to change notification settings - Fork 909
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
# What - Remove the "JSON or YAML" language from the AdminSettings page for describing FooterLinks inputs. - Add unit tests for ArrayInput and AdminSettingsFooterLinks. - Provide a property for accessing a component's value # Why Providing a property by which the JSONified version of the value can be accessed enhances the ability of tests to independently check that the value is in a state we desire, since properties can easily be accessed across the wire protocol used by browser-based testing environments.
- Loading branch information
1 parent
afcf0e7
commit 5d874cb
Showing
5 changed files
with
133 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
web/src/admin/admin-settings/stories/AdminSettingsFooterLinks.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import { render } from "@goauthentik/elements/tests/utils.js"; | ||
import { $, expect } from "@wdio/globals"; | ||
|
||
import { html } from "lit"; | ||
|
||
import "../AdminSettingsFooterLinks.js"; | ||
|
||
describe("ak-admin-settings-footer-link", () => { | ||
afterEach(async () => { | ||
await browser.execute(async () => { | ||
await document.body.querySelector("ak-admin-settings-footer-link")?.remove(); | ||
if (document.body["_$litPart$"]) { | ||
// @ts-expect-error expression of type '"_$litPart$"' is added by Lit | ||
await delete document.body["_$litPart$"]; | ||
} | ||
}); | ||
}); | ||
|
||
it("should render an empty control", async () => { | ||
render(html`<ak-admin-settings-footer-link name="link"></ak-admin-settings-footer-link>`); | ||
const link = await $("ak-admin-settings-footer-link"); | ||
await expect(await link.getProperty("isValid")).toStrictEqual(false); | ||
await expect(await link.getProperty("toJson")).toEqual({ name: "", href: "" }); | ||
}); | ||
|
||
it("should not be valid if just a name is filled in", async () => { | ||
render(html`<ak-admin-settings-footer-link name="link"></ak-admin-settings-footer-link>`); | ||
const link = await $("ak-admin-settings-footer-link"); | ||
await link.$('input[name="name"]').setValue("foo"); | ||
await expect(await link.getProperty("isValid")).toStrictEqual(false); | ||
await expect(await link.getProperty("toJson")).toEqual({ name: "foo", href: "" }); | ||
}); | ||
|
||
it("should be valid if just a URL is filled in", async () => { | ||
render(html`<ak-admin-settings-footer-link name="link"></ak-admin-settings-footer-link>`); | ||
const link = await $("ak-admin-settings-footer-link"); | ||
await link.$('input[name="href"]').setValue("https://foo.com"); | ||
await expect(await link.getProperty("isValid")).toStrictEqual(true); | ||
await expect(await link.getProperty("toJson")).toEqual({ | ||
name: "", | ||
href: "https://foo.com", | ||
}); | ||
}); | ||
|
||
it("should be valid if both are filled in", async () => { | ||
render(html`<ak-admin-settings-footer-link name="link"></ak-admin-settings-footer-link>`); | ||
const link = await $("ak-admin-settings-footer-link"); | ||
await link.$('input[name="name"]').setValue("foo"); | ||
await link.$('input[name="href"]').setValue("https://foo.com"); | ||
await expect(await link.getProperty("isValid")).toStrictEqual(true); | ||
await expect(await link.getProperty("toJson")).toEqual({ | ||
name: "foo", | ||
href: "https://foo.com", | ||
}); | ||
}); | ||
|
||
it("should not be valid if the URL is not valid", async () => { | ||
render(html`<ak-admin-settings-footer-link name="link"></ak-admin-settings-footer-link>`); | ||
const link = await $("ak-admin-settings-footer-link"); | ||
await link.$('input[name="name"]').setValue("foo"); | ||
await link.$('input[name="href"]').setValue("never://foo.com"); | ||
await expect(await link.getProperty("toJson")).toEqual({ | ||
name: "foo", | ||
href: "never://foo.com", | ||
}); | ||
await expect(await link.getProperty("isValid")).toStrictEqual(false); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import "@goauthentik/admin/admin-settings/AdminSettingsFooterLinks.js"; | ||
import { render } from "@goauthentik/elements/tests/utils.js"; | ||
import { $, expect } from "@wdio/globals"; | ||
|
||
import { html } from "lit"; | ||
|
||
import { FooterLink } from "@goauthentik/api"; | ||
|
||
import "../ak-array-input.js"; | ||
|
||
const sampleItems: FooterLink[] = [ | ||
{ name: "authentik", href: "https://goauthentik.io" }, | ||
{ name: "authentik docs", href: "https://docs.goauthentik.io/docs/" }, | ||
]; | ||
|
||
describe("ak-array-input", () => { | ||
afterEach(async () => { | ||
await browser.execute(async () => { | ||
await document.body.querySelector("ak-array-input")?.remove(); | ||
if (document.body["_$litPart$"]) { | ||
// @ts-expect-error expression of type '"_$litPart$"' is added by Lit | ||
await delete document.body["_$litPart$"]; | ||
} | ||
}); | ||
}); | ||
|
||
const component = (items: FooterLink[] = []) => | ||
render( | ||
html` <ak-array-input | ||
id="ak-array-input" | ||
.items=${items} | ||
.newItem=${() => ({ name: "", href: "" })} | ||
.row=${(f?: FooterLink) => | ||
html`<ak-admin-settings-footer-link name="footerLink" .footerLink=${f}> | ||
</ak-admin-settings-footer-link>`} | ||
validate | ||
></ak-array-input>`, | ||
); | ||
|
||
it("should render an empty control", async () => { | ||
await component(); | ||
const link = await $("ak-array-input"); | ||
await browser.pause(500); | ||
await expect(await link.getProperty("isValid")).toStrictEqual(true); | ||
await expect(await link.getProperty("toJson")).toEqual([]); | ||
}); | ||
|
||
it("should render a populated component", async () => { | ||
await component(sampleItems); | ||
const link = await $("ak-array-input"); | ||
await browser.pause(500); | ||
await expect(await link.getProperty("isValid")).toStrictEqual(true); | ||
await expect(await link.getProperty("toJson")).toEqual(sampleItems); | ||
}); | ||
}); |