-
-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: add tests for currentIdentifierButton logic
- Loading branch information
1 parent
d16071f
commit e633103
Showing
2 changed files
with
122 additions
and
22 deletions.
There are no files selected for viewing
93 changes: 93 additions & 0 deletions
93
packages/elements-react/src/theme/default/components/card/current-identifier-button.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,93 @@ | ||
// Copyright © 2024 Ory Corp | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
import { FlowType, UiNode } from "@ory/client-fetch" | ||
import { getBackButtonNode } from "./current-identifier-button" | ||
|
||
test("getBackButtonNode should return the correct node for FlowType.Login", () => { | ||
const nodes = [ | ||
{ | ||
attributes: { name: "identifier" }, | ||
group: "identifier_first", | ||
}, | ||
{ | ||
attributes: { name: "email" }, | ||
group: "default", | ||
}, | ||
] as UiNode[] | ||
|
||
const result = getBackButtonNode(FlowType.Login, nodes) | ||
expect(result).toEqual({ | ||
attributes: { name: "identifier" }, | ||
group: "identifier_first", | ||
}) | ||
}) | ||
|
||
test("getBackButtonNode should return the correct node for FlowType.Registration", () => { | ||
const nodes: UiNode[] = [ | ||
{ | ||
attributes: { name: "traits.email" }, | ||
group: "default", | ||
}, | ||
{ | ||
attributes: { name: "traits.username" }, | ||
group: "default", | ||
}, | ||
] as UiNode[] | ||
|
||
const result = getBackButtonNode(FlowType.Registration, nodes) | ||
expect(result).toEqual({ | ||
attributes: { name: "traits.email" }, | ||
group: "default", | ||
}) | ||
}) | ||
|
||
test("getBackButtonNode should return the correct node for FlowType.Recovery", () => { | ||
const nodes: UiNode[] = [ | ||
{ | ||
attributes: { name: "email" }, | ||
group: "default", | ||
}, | ||
{ | ||
attributes: { name: "other" }, | ||
group: "default", | ||
}, | ||
] as UiNode[] | ||
|
||
const result = getBackButtonNode(FlowType.Recovery, nodes) | ||
expect(result).toEqual({ | ||
attributes: { name: "email" }, | ||
group: "default", | ||
}) | ||
}) | ||
|
||
test("getBackButtonNode should return the correct node for FlowType.Verification", () => { | ||
const nodes: UiNode[] = [ | ||
{ | ||
attributes: { name: "email" }, | ||
group: "default", | ||
}, | ||
{ | ||
attributes: { name: "traits.username" }, | ||
group: "default", | ||
}, | ||
] as UiNode[] | ||
|
||
const result = getBackButtonNode(FlowType.Verification, nodes) | ||
expect(result).toEqual({ | ||
attributes: { name: "email" }, | ||
group: "default", | ||
}) | ||
}) | ||
|
||
test("getBackButtonNode should return undefined if no matching node is found", () => { | ||
const nodes: UiNode[] = [ | ||
{ | ||
attributes: { name: "non-matching" }, | ||
group: "non-matching-group", | ||
}, | ||
] as unknown[] as UiNode[] | ||
|
||
const result = getBackButtonNode(FlowType.Login, nodes) | ||
expect(result).toBeUndefined() | ||
}) |
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