Skip to content

Commit

Permalink
test: error message formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
Benehiko committed Sep 27, 2023
1 parent 4a9b14a commit 8518954
Show file tree
Hide file tree
Showing 3 changed files with 308 additions and 42 deletions.
50 changes: 50 additions & 0 deletions src/react-components/ory/helpers/error-flow-nodes.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -98,3 +98,53 @@ test("can render multiple messages", async ({ mount }) => {
component.locator("[data-testid='ui/message/1080002']"),
).toBeVisible()
})

test("message unix expired_at timestamp with formatted date", async ({
mount,
}) => {
const component = await mount(
<NodeMessages
severity="info"
uiMessages={[
{
id: 4010001,
text: "The login flow expired",
type: "error",
context: {
expired_at_unix: Math.floor(
new Date(Date.now() - 1000 * 60 * 10).getTime() / 1000,
),
},
},
]}
/>,
)

await expect(component).toContainText(
/The login flow expired 10\.[0-9]{2} minutes ago, please try again\./,
)
})

test("message unix until minutes with formatted date", async ({ mount }) => {
const component = await mount(
<NodeMessages
severity="info"
uiMessages={[
{
id: 1060001,
text: "You successfully recovered your account",
type: "info",
context: {
privileged_session_expires_at_unix: Math.floor(
new Date(Date.now() + 1000 * 60 * 10).getTime() / 1000,
),
},
},
]}
/>,
)

await expect(component).toContainText(
/You successfully recovered your account\. Please change your password or set up an alternative login method \(e\.g\. social sign in\) within the next 10\.[0-9]{2} minutes\./,
)
})
134 changes: 134 additions & 0 deletions src/react-components/ory/helpers/node.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,137 @@ test("hidden input field shouldn't show label", async ({ mount }) => {

await expect(component).toBeHidden()
})

test("uiTextToFormattedMessage on a list", async ({ mount }) => {
const component = await mount(
<Node
node={{
type: "text",
group: "lookup_secret",
attributes: {
text: {
id: 1050015,
text: "3r9noma8, tv14n5tu",
type: "info",
context: {
secrets: [
{
context: {
secret: "3r9noma8",
},
id: 1050009,
text: "3r9noma8",
type: "info",
},
{
context: {
secret: "tv14n5tu",
},
id: 1050009,
text: "tv14n5tu",
type: "info",
},
{
context: {
secret: "te45pbc0",
},
id: 1050009,
text: "te45pbc0",
type: "info",
},
{
context: {
secret: "juuri7u3",
},
id: 1050009,
text: "juuri7u3",
type: "info",
},
{
context: {
secret: "zp8df6fe",
},
id: 1050009,
text: "zp8df6fe",
type: "info",
},
{
context: {
secret: "dhxbkfmv",
},
id: 1050009,
text: "dhxbkfmv",
type: "info",
},
{
context: {
secret: "rwu6svpj",
},
id: 1050009,
text: "rwu6svpj",
type: "info",
},
{
context: {
secret: "evv9pedj",
},
id: 1050009,
text: "evv9pedj",
type: "info",
},
{
context: {
secret: "v37k7nxv",
},
id: 1050009,
text: "v37k7nxv",
type: "info",
},
{
context: {
secret: "pqhtefs4",
},
id: 1050009,
text: "pqhtefs4",
type: "info",
},
{
context: {
secret: "mrwstrmp",
},
id: 1050009,
text: "mrwstrmp",
type: "info",
},
{
context: {
secret: "q3vvtd4i",
},
id: 1050009,
text: "q3vvtd4i",
type: "info",
},
],
},
},
id: "lookup_secret_codes",
node_type: "text",
},
messages: [],
meta: {
label: {
id: 1050010,
text: "These are your back up recovery codes. Please keep them in a safe place!",
type: "info",
},
},
}}
/>,
)

await expect(component).toContainText(
"These are your back up recovery codes. Please keep them in a safe place!",
)
await expect(component).toContainText("te45pbc0")
await expect(component).toContainText("q3vvtd4i")
})
Loading

0 comments on commit 8518954

Please sign in to comment.