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

fix: duplicate hidden input fields on auth-code-section #150

Merged
merged 1 commit into from
Sep 28, 2023
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
6 changes: 5 additions & 1 deletion src/react-components/ory/sections/auth-code-section.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@ export const AuthCodeSection = ({
<FilterFlowNodes
filter={{
nodes: nodes,
groups: "code",
groups: ["code"],
// we don't want to map the default group twice
// the form already maps hidden fields under the default group
// we are only interested in hidden fields that are under the code group
withoutDefaultGroup: true,
withoutDefaultAttributes: true,
attributes: ["hidden"],
}}
Expand Down
33 changes: 32 additions & 1 deletion src/react-components/ory/user-auth-card.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
recoveryFixture,
registrationFixture,
registrationCodeFixture,
registrationCodeStepTwoFixture,
verificationFixture,
loginCodeFixture,
} from "../../test"
Expand Down Expand Up @@ -100,7 +101,7 @@ test("ory auth card registration code flow", async ({ mount }) => {
title="Sign up"
flowType="registration"
additionalProps={{
loginURL: "/registration",
loginURL: "/login",
}}
flow={registrationCodeFixture}
/>,
Expand All @@ -121,6 +122,36 @@ test("ory auth card registration code flow", async ({ mount }) => {
)
})

test("ory auth card registration step 2 of code flow", async ({ mount }) => {
const component = await mount(
<UserAuthCard
title="Sign up"
flowType="registration"
additionalProps={{
loginURL: "/login",
}}
flow={registrationCodeStepTwoFixture}
/>,
)

const registrationComponent = new AuthPage(
registrationCodeStepTwoFixture.ui.nodes,
component,
)
await registrationComponent.expectTraitFields()

await expect(component).toContainText("Sign up", { ignoreCase: true })
await expect(component).toContainText("Already have an account?", {
ignoreCase: true,
})
await expect(
component.locator('button[type="submit"][name="method"]'),
).toHaveText("Submit")
await expect(
component.locator('button[type="submit"][name="resend"]'),
).toHaveText("Resend code")
})

test("ory auth card verification flow", async ({ mount }) => {
const component = await mount(
<UserAuthCard
Expand Down
162 changes: 160 additions & 2 deletions src/test/fixtures/registration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -539,7 +539,7 @@ export const registrationCodeFixture: RegistrationFlow = {
},
{
type: "input",
group: "code",
group: "default",
attributes: {
name: "traits.email",
type: "email",
Expand All @@ -558,7 +558,7 @@ export const registrationCodeFixture: RegistrationFlow = {
},
{
type: "input",
group: "code",
group: "default",
attributes: {
name: "traits.firstName",
type: "text",
Expand Down Expand Up @@ -596,4 +596,162 @@ export const registrationCodeFixture: RegistrationFlow = {
},
],
},
state: "choose_method",
}

export const registrationCodeStepTwoFixture: RegistrationFlow = {
id: "28554fd0-cbf5-4ff3-a1f7-c033e5ad459c",
type: "browser",
expires_at: "2023-09-28T06:38:36.109217Z",
issued_at: "2023-09-28T06:08:36.109217Z",
request_url:
"https://auth.terblanche.eu/self-service/registration/browser?return_to=",
active: "code",
ui: {
action:
"https://auth.terblanche.eu/self-service/registration?flow=28554fd0-cbf5-4ff3-a1f7-c033e5ad459c",
method: "POST",
nodes: [
{
type: "input",
group: "default",
attributes: {
name: "traits.email",
type: "hidden",
value: "[email protected]",
required: true,
autocomplete: "email",
disabled: false,
node_type: "input",
},
messages: [],
meta: {
label: {
id: 1070002,
text: "E-Mail",
type: "info",
context: {
title: "E-Mail",
},
},
},
},
{
type: "input",
group: "default",
attributes: {
name: "traits.tos",
type: "hidden",
value: true,
required: true,
disabled: false,
node_type: "input",
},
messages: [],
meta: {
label: {
id: 1070002,
text: "Accept Tos",
type: "info",
context: {
title: "Accept Tos",
},
},
},
},
{
type: "input",
group: "default",
attributes: {
name: "csrf_token",
type: "hidden",
value:
"RWrc7sJjlrv2xAdtlvlFmRg/vExgYOiXjdReeIYQ8uyptoPfF5vCqPdBmKW76qq6ZE6YjINL5yRPNO4ycAAHFQ==",
required: true,
disabled: false,
node_type: "input",
},
messages: [],
meta: {},
},
{
type: "input",
group: "code",
attributes: {
name: "method",
type: "hidden",
value: "code",
disabled: false,
node_type: "input",
},
messages: [],
meta: {},
},
{
type: "input",
group: "code",
attributes: {
name: "code",
type: "text",
required: true,
disabled: false,
node_type: "input",
},
messages: [],
meta: {
label: {
id: 1070012,
text: "Registration code",
type: "info",
},
},
},
{
type: "input",
group: "code",
attributes: {
name: "method",
type: "submit",
value: "code",
disabled: false,
node_type: "input",
},
messages: [],
meta: {
label: {
id: 1070005,
text: "Submit",
type: "info",
},
},
},
{
type: "input",
group: "code",
attributes: {
name: "resend",
type: "submit",
value: "code",
disabled: false,
node_type: "input",
},
messages: [],
meta: {
label: {
id: 1070008,
text: "Resend code",
type: "info",
},
},
},
],
messages: [
{
id: 1040005,
text: "An email containing a code has been sent to the email address you provided. If you have not received an email, check the spelling of the address and retry the registration.",
type: "info",
},
],
},
state: "sent_email",
}
6 changes: 4 additions & 2 deletions src/test/models/AuthPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,12 @@
const t = traits || this.traits
for (const key in t) {
if (t[key].type === "hidden") {
await expect(this.locator.locator(`*[name="${key}"]`)).toBeHidden()
await expect(this.locator.locator(`*[name="${key}"]`)).toBeAttached()
} else {
await expect(
this.locator.locator(`*[name="${t[key].name || key}"]`),
this.locator.locator(
`*[name="${t[key].name || key}"][type="${t[key].type}"]`,
),
).toBeVisible()
}
}
Expand All @@ -55,7 +57,7 @@
async submitForm(buttonLocator?: string) {
for (const key in this.traits) {
if (this.traits[key].type === "input") {
await this.formFields[key].fill(this.traits[key].value)

Check failure on line 60 in src/test/models/AuthPage.ts

View workflow job for this annotation

GitHub Actions / test

[firefox] › registration.spec.ts:19:3 › Registration Page › registration duplicate account

1) [firefox] › registration.spec.ts:19:3 › Registration Page › registration duplicate account › mock the submit registration response Error: locator.fill: Error: strict mode violation: getByTestId('registration-auth-card').locator('input[name="traits.email"]') resolved to 2 elements: 1) <input id=":r3:" required="" type="email" placeholder="…/> aka getByTestId('registration-flow').getByTestId('node/input/traits.email').getByPlaceholder(' ') 2) <input id=":rj:" required="" type="email" placeholder="…/> aka getByTestId('passwordless-flow').getByTestId('node/input/traits.email').getByPlaceholder(' ') =========================== logs =========================== waiting for getByTestId('registration-auth-card').locator('input[name="traits.email"]') ============================================================ at ../../../src/test/models/AuthPage.ts:60 58 | for (const key in this.traits) { 59 | if (this.traits[key].type === "input") { > 60 | await this.formFields[key].fill(this.traits[key].value) | ^ 61 | } else if (this.traits[key].type === "checkbox") { 62 | await this.formFields[key].click() 63 | } at ag.submitForm (/home/runner/work/elements/elements/src/test/models/AuthPage.ts:60:36) at /home/runner/work/elements/elements/src/test/mock/registration.ts:101:30 at Object.RegistrationDuplicateAccountTest (/home/runner/work/elements/elements/src/test/mock/registration.ts:90:11) at /home/runner/work/elements/elements/examples/react-spa/e2e/registration.spec.ts:28:5
} else if (this.traits[key].type === "checkbox") {
await this.formFields[key].click()
}
Expand Down
Loading