We have working tests!!!!!!
This commit is contained in:
		| @ -7,6 +7,7 @@ import { CustomListenerElement } from "@goauthentik/elements/utils/eventEmitter" | |||||||
|  |  | ||||||
| import { html } from "lit"; | import { html } from "lit"; | ||||||
| import { property, query } from "lit/decorators.js"; | import { property, query } from "lit/decorators.js"; | ||||||
|  | import { ifDefined } from "lit/directives/if-defined.js"; | ||||||
|  |  | ||||||
| import { FlowsApi, FlowsInstancesListDesignationEnum } from "@goauthentik/api"; | import { FlowsApi, FlowsInstancesListDesignationEnum } from "@goauthentik/api"; | ||||||
| import type { Flow, FlowsInstancesListRequest } from "@goauthentik/api"; | import type { Flow, FlowsInstancesListRequest } from "@goauthentik/api"; | ||||||
| @ -122,7 +123,7 @@ export class FlowSearch<T extends Flow> extends CustomListenerElement(AKElement) | |||||||
|                 .renderElement=${renderElement} |                 .renderElement=${renderElement} | ||||||
|                 .renderDescription=${renderDescription} |                 .renderDescription=${renderDescription} | ||||||
|                 .value=${getFlowValue} |                 .value=${getFlowValue} | ||||||
|                 .name=${this.name} |                 name=${ifDefined(this.name)} | ||||||
|                 @ak-change=${this.handleSearchUpdate} |                 @ak-change=${this.handleSearchUpdate} | ||||||
|                 ?blankable=${!this.required} |                 ?blankable=${!this.required} | ||||||
|             > |             > | ||||||
|  | |||||||
| @ -1,6 +1,6 @@ | |||||||
| import { browser } from "@wdio/globals"; | import { browser } from "@wdio/globals"; | ||||||
| import { match } from "ts-pattern"; | import { match } from "ts-pattern"; | ||||||
| import { ChainablePromiseArray, Key } from "webdriverio"; | import { Key } from "webdriverio"; | ||||||
|  |  | ||||||
| export async function setSearchSelect(name: string, value: string) { | export async function setSearchSelect(name: string, value: string) { | ||||||
|     const control = await (async () => { |     const control = await (async () => { | ||||||
| @ -21,23 +21,22 @@ export async function setSearchSelect(name: string, value: string) { | |||||||
|     await input.scrollIntoView(); |     await input.scrollIntoView(); | ||||||
|     await input.click(); |     await input.click(); | ||||||
|  |  | ||||||
|     // Weirdly necessary because it's portals! |  | ||||||
|     const searchBlock = await ( |  | ||||||
|         await $(`div[data-managed-for*="${name}"]`).$("ak-list-select") |  | ||||||
|     ).shadow$$("button"); |  | ||||||
|  |  | ||||||
|     // @ts-expect-error "Types break on shadow$$" |     // @ts-expect-error "Types break on shadow$$" | ||||||
|     for (const button of searchBlock) { |     const button = await (async () => { | ||||||
|         if ((await button.getText()).includes(value)) { |         for await (const button of $(`div[data-managed-for*="${name}"]`) | ||||||
|             target = button; |             .$("ak-list-select") | ||||||
|             break; |             .$$("button")) { | ||||||
|  |             if ((await button.getText()).includes(value)) { | ||||||
|  |                 return button; | ||||||
|  |             } | ||||||
|         } |         } | ||||||
|     } |     })(); | ||||||
|  |  | ||||||
|     // @ts-expect-error "TSC cannot tell if the `for` loop actually performs the assignment." |     // @ts-expect-error "TSC cannot tell if the `for` loop actually performs the assignment." | ||||||
|     if (!target) { |     if (!button.isExisting()) { | ||||||
|         throw new Error(`Expected to find an entry matching the spec ${value}`); |         throw new Error(`Expected to find an entry matching the spec ${value}`); | ||||||
|     } |     } | ||||||
|     await (await target).click(); |     await (await button).click(); | ||||||
|     await browser.keys(Key.Tab); |     await browser.keys(Key.Tab); | ||||||
| } | } | ||||||
|  |  | ||||||
| @ -55,35 +54,44 @@ export async function setRadio(name: string, value: string) { | |||||||
|     await item.click(); |     await item.click(); | ||||||
| } | } | ||||||
|  |  | ||||||
| browser.addCommand( | export async function setTypeCreate(name: string, value: string | RegExp) { | ||||||
|     "findInside$", |  | ||||||
|     async function (these: WebdriverIO.ElementArray, selector: string) { |  | ||||||
|         // prettier-ignore |  | ||||||
|         console.log("HERE!!!!!!!!!"); |  | ||||||
|         for await (const item of these) { |  | ||||||
|             const wanted = item.$(selector); |  | ||||||
|             if (wanted.isExisting()) { |  | ||||||
|                 return wanted; |  | ||||||
|             } |  | ||||||
|         } |  | ||||||
|         return undefined; |  | ||||||
|     }, |  | ||||||
|     true, |  | ||||||
| ); |  | ||||||
|  |  | ||||||
| export async function setTypeCreate(name: string, value: string) { |  | ||||||
|     const control = await $(`ak-wizard-page-type-create[name="${name}"]`); |     const control = await $(`ak-wizard-page-type-create[name="${name}"]`); | ||||||
|     await control.scrollIntoView(); |     await control.scrollIntoView(); | ||||||
|     const selection = await $$("ak-type-create-grid-card").findInside$(`div*=${value}`); |  | ||||||
|     await selection.scrollIntoView(); |     const comparator = | ||||||
|     await selection.click(); |         typeof value === "string" ? (sample) => sample === value : (sample) => value.test(sample); | ||||||
|  |  | ||||||
|  |     const card = await (async () => { | ||||||
|  |         for await (const card of $("ak-wizard-page-type-create").$$( | ||||||
|  |             '[data-ouid-component-type="ak-type-create-grid-card"]', | ||||||
|  |         )) { | ||||||
|  |             if (comparator(await card.$(".pf-c-card__title").getText())) { | ||||||
|  |                 return card; | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  |     })(); | ||||||
|  |  | ||||||
|  |     await card.scrollIntoView(); | ||||||
|  |     await card.click(); | ||||||
| } | } | ||||||
|  |  | ||||||
| export async function setFormGroup(name: string, setting: "open" | "closed") { | export async function setFormGroup(name: string | RegExp, setting: "open" | "closed") { | ||||||
|     const formGroup = await $(`.//span[contains(., "${name}")]`); |     const comparator = | ||||||
|  |         typeof name === "string" ? (sample) => sample === name : (sample) => name.test(sample); | ||||||
|  |  | ||||||
|  |     const formGroup = await (async () => { | ||||||
|  |         for await (const group of $$("ak-form-group")) { | ||||||
|  |             if ( | ||||||
|  |                 comparator(await group.$("div.pf-c-form__field-group-header-title-text").getText()) | ||||||
|  |             ) { | ||||||
|  |                 return group; | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  |     })(); | ||||||
|  |  | ||||||
|     await formGroup.scrollIntoView(); |     await formGroup.scrollIntoView(); | ||||||
|     const toggle = await formGroup.$("div.pf-c-form__field-group-toggle-button button"); |     const toggle = await formGroup.$("div.pf-c-form__field-group-toggle-button button"); | ||||||
|     await match([toggle.getAttribute("expanded"), setting]) |     await match([await toggle.getAttribute("aria-expanded"), setting]) | ||||||
|         .with(["false", "open"], async () => await toggle.click()) |         .with(["false", "open"], async () => await toggle.click()) | ||||||
|         .with(["true", "closed"], async () => await toggle.click()) |         .with(["true", "closed"], async () => await toggle.click()) | ||||||
|         .otherwise(async () => {}); |         .otherwise(async () => {}); | ||||||
|  | |||||||
| @ -32,19 +32,19 @@ async function fillOutFields(fields: FieldDesc[]) { | |||||||
| } | } | ||||||
|  |  | ||||||
| describe("Configure Oauth2 Providers", () => { | describe("Configure Oauth2 Providers", () => { | ||||||
|     it("Should configure a simple LDAP Application", async () => { |     it("Should configure a simple OAuth2 Provider", async () => { | ||||||
|         const newProviderName = `New OAuth2 Provider - ${randomId()}`; |         const newProviderName = `New OAuth2 Provider - ${randomId()}`; | ||||||
|  |  | ||||||
|         await reachTheProvider(); |         await reachTheProvider(); | ||||||
|  |  | ||||||
|         await $("ak-wizard-page-type-create").waitForDisplayed(); |         await $("ak-wizard-page-type-create").waitForDisplayed(); | ||||||
|         await setTypeCreate("selectProviderType", "OAuth2/OpenID Provider"); |  | ||||||
|         await clickButton("Next"); |  | ||||||
|  |  | ||||||
|         // prettier-ignore |         // prettier-ignore | ||||||
|         await fillOutFields([ |         await fillOutFields([ | ||||||
|  |             [setTypeCreate, "selectProviderType", "OAuth2/OpenID Provider"], | ||||||
|  |             [clickButton, "Next"], | ||||||
|             [setTextInput, "name", newProviderName], |             [setTextInput, "name", newProviderName], | ||||||
|             [setFormGroup, "Flow settings", "open"], |             [setFormGroup, /Flow settings/, "open"], | ||||||
|             [setSearchSelect, "authenticationFlow", "default-authentication-flow"], |             [setSearchSelect, "authenticationFlow", "default-authentication-flow"], | ||||||
|             [setSearchSelect, "authorizationFlow", "default-provider-authorization-explicit-consent"], |             [setSearchSelect, "authorizationFlow", "default-provider-authorization-explicit-consent"], | ||||||
|             [setSearchSelect, "invalidationFlow", "default-invalidation-flow"], |             [setSearchSelect, "invalidationFlow", "default-invalidation-flow"], | ||||||
| @ -54,3 +54,26 @@ describe("Configure Oauth2 Providers", () => { | |||||||
|         await ProviderWizardView.nextButton.click(); |         await ProviderWizardView.nextButton.click(); | ||||||
|     }); |     }); | ||||||
| }); | }); | ||||||
|  |  | ||||||
|  | describe("Configure LDAP Providers", () => { | ||||||
|  |     it("Should configure a simple LDAP Provider", async () => { | ||||||
|  |         const newProviderName = `New LDAP Provider - ${randomId()}`; | ||||||
|  |  | ||||||
|  |         await reachTheProvider(); | ||||||
|  |         await $("ak-wizard-page-type-create").waitForDisplayed(); | ||||||
|  |  | ||||||
|  |         // prettier-ignore | ||||||
|  |         await fillOutFields([ | ||||||
|  |             [setTypeCreate, "selectProviderType", "LDAP Provider"], | ||||||
|  |             [clickButton, "Next"], | ||||||
|  |             [setTextInput, "name", newProviderName], | ||||||
|  |             [setFormGroup, /Flow settings/, "open"], | ||||||
|  |             // This will never not weird me out. | ||||||
|  |             [setSearchSelect, "authorizationFlow", "default-authentication-flow"], | ||||||
|  |             [setSearchSelect, "invalidationFlow", "default-invalidation-flow"], | ||||||
|  |         ]); | ||||||
|  |  | ||||||
|  |         await ProviderWizardView.pause(); | ||||||
|  |         await ProviderWizardView.nextButton.click(); | ||||||
|  |     }); | ||||||
|  | }); | ||||||
|  | |||||||
		Reference in New Issue
	
	Block a user
	 Ken Sternberg
					Ken Sternberg