-
-
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.
feat: add two-step login card (#211)
Co-authored-by: Miłosz Szekiel <[email protected]>
- Loading branch information
1 parent
0fdccbe
commit 81571a0
Showing
59 changed files
with
1,148 additions
and
423 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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,3 @@ | ||
# Review comments generated by i18n-ally. Please commit this file. | ||
|
||
{} |
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,4 @@ | ||
{ | ||
"i18n-ally.localesPaths": ["src/locales", "src/util/i18n"], | ||
"i18n-ally.keystyle": "flat" | ||
} |
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
130 changes: 130 additions & 0 deletions
130
packages/elements-react/src/components/card/__tests__/card-two-step.spec.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,130 @@ | ||
// Copyright © 2024 Ory Corp | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
import { | ||
filterZeroStepGroups, | ||
getFinalNodes, | ||
isChoosingMethod, | ||
} from "../card-two-step.utils" | ||
import { UiNode, UiNodeAttributes, UiNodeGroupEnum } from "@ory/client-fetch" | ||
|
||
describe("CardTwoStep/utils", () => { | ||
describe("filterZeroStepGroups", () => { | ||
test("should filter out nodes with group Oidc", () => { | ||
const nodes: UiNode[] = [ | ||
{ group: UiNodeGroupEnum.Oidc } as UiNode, | ||
{ group: UiNodeGroupEnum.Default } as UiNode, | ||
] | ||
const result = filterZeroStepGroups(nodes) | ||
expect(result).toHaveLength(1) | ||
expect(result[0].group).toBe(UiNodeGroupEnum.Default) | ||
}) | ||
}) | ||
|
||
describe("isChoosingMethod", () => { | ||
test("should return true if a node has value 'profile:back'", () => { | ||
const uiNodes: UiNode[] = [ | ||
{ | ||
attributes: { value: "profile:back" } as UiNodeAttributes, | ||
group: UiNodeGroupEnum.Default, | ||
} as UiNode, | ||
] | ||
expect(isChoosingMethod(uiNodes)).toBe(true) | ||
}) | ||
|
||
test("should return true if a node is identifier first and hidden", () => { | ||
const uiNodes: UiNode[] = [ | ||
{ | ||
attributes: { | ||
name: "identifier", | ||
type: "hidden", | ||
} as UiNodeAttributes, | ||
group: UiNodeGroupEnum.IdentifierFirst, | ||
} as UiNode, | ||
] | ||
expect(isChoosingMethod(uiNodes)).toBe(true) | ||
}) | ||
|
||
test("should return false if no conditions are met", () => { | ||
const uiNodes: UiNode[] = [ | ||
{ | ||
attributes: { name: "other", type: "text" } as UiNodeAttributes, | ||
group: UiNodeGroupEnum.Default, | ||
} as UiNode, | ||
] | ||
expect(isChoosingMethod(uiNodes)).toBe(false) | ||
}) | ||
}) | ||
|
||
describe("getFinalNodes", () => { | ||
test("should return hidden nodes from identifier_first and default groups, concatenated with selected nodes", () => { | ||
const uniqueGroups = { | ||
identifier_first: [ | ||
{ | ||
attributes: { type: "hidden" } as UiNodeAttributes, | ||
} as UiNode, | ||
], | ||
default: [ | ||
{ | ||
attributes: { type: "hidden" } as UiNodeAttributes, | ||
} as UiNode, | ||
], | ||
} | ||
const selectedGroup = UiNodeGroupEnum.Default | ||
const result = getFinalNodes(uniqueGroups, selectedGroup) | ||
expect(result).toHaveLength(3) | ||
}) | ||
|
||
test("should return only hidden nodes if no group is selected", () => { | ||
const uniqueGroups = { | ||
identifier_first: [ | ||
{ | ||
attributes: { type: "hidden" } as UiNodeAttributes, | ||
} as UiNode, | ||
], | ||
default: [ | ||
{ | ||
attributes: { type: "hidden" } as UiNodeAttributes, | ||
} as UiNode, | ||
], | ||
} | ||
const result = getFinalNodes(uniqueGroups, undefined) | ||
expect(result).toHaveLength(2) | ||
}) | ||
|
||
test("should return an empty array if no hidden nodes are found and no group is selected", () => { | ||
const uniqueGroups = { | ||
identifier_first: [ | ||
{ | ||
attributes: { type: "text" } as UiNodeAttributes, | ||
} as UiNode, | ||
], | ||
default: [ | ||
{ | ||
attributes: { type: "text" } as UiNodeAttributes, | ||
} as UiNode, | ||
], | ||
} | ||
const result = getFinalNodes(uniqueGroups, undefined) | ||
expect(result).toHaveLength(0) | ||
}) | ||
|
||
test("should return selected nodes if no hidden nodes are found", () => { | ||
const uniqueGroups = { | ||
identifier_first: [ | ||
{ | ||
attributes: { type: "text" } as UiNodeAttributes, | ||
} as UiNode, | ||
], | ||
default: [ | ||
{ | ||
attributes: { type: "text" } as UiNodeAttributes, | ||
} as UiNode, | ||
], | ||
} | ||
const selectedGroup = UiNodeGroupEnum.Default | ||
const result = getFinalNodes(uniqueGroups, selectedGroup) | ||
expect(result).toHaveLength(1) | ||
}) | ||
}) | ||
}) |
Oops, something went wrong.