@@ -2,53 +2,90 @@ import { describe, expect, it } from 'vitest';
22
33import { signInMessages } from '../sign-in.messages' ;
44import type { SignInStep } from '../sign-in.types' ;
5+ import type { SignInStepKey } from '../sign-in.utils' ;
56import {
67 codeCopy ,
78 codeIdentity ,
89 codeNotice ,
910 codeSecondaryAction ,
11+ emailLinkStatusCopy ,
1012 httpsUrl ,
1113 identifierFieldCopy ,
1214 splitLastUsedProvider ,
1315 startPrompt ,
16+ stepIds ,
1417 stepKey ,
1518} from '../sign-in.utils' ;
1619
20+ const provider = { id : 'whatsapp' , name : 'WhatsApp' , iconUrl : 'https://img.clerk.com/static/whatsapp.svg' } ;
21+
22+ const stepsByKey : Record < SignInStepKey , SignInStep > = {
23+ identifier : { kind : 'identifier' , field : 'email' } ,
24+ 'identifier:channel' : { kind : 'identifier' , field : 'phone' , channel : provider } ,
25+ 'credential:password' : { kind : 'credential' , credential : 'password' , identifier : 'jane@acme.com' } ,
26+ 'credential:backup-code' : { kind : 'credential' , credential : 'backup-code' , identifier : 'jane@acme.com' } ,
27+ 'credential:passkey' : { kind : 'credential' , credential : 'passkey' , identifier : 'jane@acme.com' } ,
28+ 'code:first-factor' : { kind : 'code' , purpose : 'first-factor' , channel : 'email' , identifier : 'jane@acme.com' } ,
29+ 'code:second-factor' : { kind : 'code' , purpose : 'second-factor' , channel : 'totp' } ,
30+ 'code:client-trust' : { kind : 'code' , purpose : 'client-trust' , channel : 'email' } ,
31+ 'code:sso-bypass' : { kind : 'code' , purpose : 'sso-bypass' , channel : 'email' } ,
32+ 'code:reset-password' : { kind : 'code' , purpose : 'reset-password' , channel : 'email' , identifier : 'jane@acme.com' } ,
33+ 'code:verify-email' : { kind : 'code' , purpose : 'verify-email' , channel : 'email' , identifier : 'new@acme.com' } ,
34+ 'code:verify-phone' : { kind : 'code' , purpose : 'verify-phone' , channel : 'phone' } ,
35+ 'choice:methods' : { kind : 'choice' , purpose : 'methods' , options : [ ] } ,
36+ 'choice:reset-methods' : { kind : 'choice' , purpose : 'reset-methods' , options : [ ] } ,
37+ 'choice:enterprise-connections' : { kind : 'choice' , purpose : 'enterprise-connections' , options : [ ] } ,
38+ 'choice:accounts' : { kind : 'choice' , purpose : 'accounts' , options : [ ] } ,
39+ 'choice:wallets' : { kind : 'choice' , purpose : 'wallets' , options : [ ] } ,
40+ 'notice:help' : { kind : 'notice' , purpose : 'help' } ,
41+ 'notice:forgot-password' : { kind : 'notice' , purpose : 'forgot-password' , identifier : 'jane@acme.com' } ,
42+ 'notice:no-methods' : { kind : 'notice' , purpose : 'no-methods' } ,
43+ 'notice:action-blocked' : { kind : 'notice' , purpose : 'action-blocked' } ,
44+ 'notice:password-compromised' : { kind : 'notice' , purpose : 'password-compromised' } ,
45+ 'notice:enterprise-sso' : { kind : 'notice' , purpose : 'enterprise-sso' } ,
46+ 'notice:email-link' : { kind : 'notice' , purpose : 'email-link' , identifier : 'jane@acme.com' } ,
47+ 'notice:email-link-status' : { kind : 'notice' , purpose : 'email-link-status' , status : 'expired' } ,
48+ 'new-password:forgot' : { kind : 'new-password' , reason : 'forgot' } ,
49+ 'sign-up' : { kind : 'sign-up' } ,
50+ } ;
51+
1752describe ( 'stepKey' , ( ) => {
1853 it ( 'keys each step by its kind and the variant that changes its copy' , ( ) => {
19- const steps : [ SignInStep , string ] [ ] = [
20- [ { kind : 'identifier' , field : 'email' } , 'identifier' ] ,
21- [
22- {
23- kind : 'identifier' ,
24- field : 'phone' ,
25- channel : { id : 'whatsapp' , name : 'WhatsApp' , iconUrl : 'https://img.clerk.com/static/whatsapp.svg' } ,
26- } ,
27- 'identifier:channel' ,
28- ] ,
29- [ { kind : 'credential' , credential : 'password' , identifier : 'jane@acme.com' } , 'credential:password' ] ,
30- [ { kind : 'credential' , credential : 'backup-code' , identifier : 'jane@acme.com' } , 'credential:backup-code' ] ,
31- [ { kind : 'credential' , credential : 'passkey' , identifier : 'jane@acme.com' } , 'credential:passkey' ] ,
32- [ { kind : 'code' , purpose : 'first-factor' , channel : 'email' , identifier : 'jane@acme.com' } , 'code:first-factor' ] ,
33- [ { kind : 'code' , purpose : 'second-factor' , channel : 'totp' } , 'code:second-factor' ] ,
34- [ { kind : 'code' , purpose : 'verify-email' , channel : 'email' , identifier : 'new@acme.com' } , 'code:verify-email' ] ,
35- [ { kind : 'choice' , purpose : 'methods' , options : [ ] } , 'choice:methods' ] ,
36- [ { kind : 'choice' , purpose : 'reset-methods' , options : [ ] } , 'choice:reset-methods' ] ,
37- [ { kind : 'choice' , purpose : 'accounts' , options : [ ] } , 'choice:accounts' ] ,
38- [ { kind : 'choice' , purpose : 'wallets' , options : [ ] } , 'choice:wallets' ] ,
39- [ { kind : 'notice' , purpose : 'help' } , 'notice:help' ] ,
40- [
41- { kind : 'code' , purpose : 'reset-password' , channel : 'email' , identifier : 'jane@acme.com' } ,
42- 'code:reset-password' ,
43- ] ,
44- [ { kind : 'notice' , purpose : 'forgot-password' , identifier : 'jane@acme.com' } , 'notice:forgot-password' ] ,
45- [ { kind : 'notice' , purpose : 'action-blocked' } , 'notice:action-blocked' ] ,
46- [ { kind : 'notice' , purpose : 'email-link' , identifier : 'jane@acme.com' } , 'notice:email-link' ] ,
47- [ { kind : 'new-password' , reason : 'forgot' } , 'new-password:forgot' ] ,
48- [ { kind : 'sign-up' } , 'sign-up' ] ,
49- ] ;
50-
51- expect ( steps . map ( ( [ step ] ) => stepKey ( step ) ) ) . toEqual ( steps . map ( ( [ , key ] ) => key ) ) ;
54+ const steps = Object . entries ( stepsByKey ) ;
55+
56+ expect ( steps . map ( ( [ , step ] ) => stepKey ( step ) ) ) . toEqual ( steps . map ( ( [ key ] ) => key ) ) ;
57+ } ) ;
58+
59+ it ( 'gives every step a key the view lists in a flow step, and lists no key a step cannot produce' , ( ) => {
60+ const listed = Object . values ( stepIds ) . flat ( ) ;
61+ const produced = Object . values ( stepsByKey ) . map ( step => stepKey ( step ) ) ;
62+
63+ expect ( [ ...listed ] . sort ( ) ) . toEqual ( [ ...produced ] . sort ( ) ) ;
64+ } ) ;
65+ } ) ;
66+
67+ describe ( 'emailLinkStatusCopy' , ( ) => {
68+ const m = signInMessages ;
69+
70+ it ( 'tells the tab the link opened in to go back to the original tab' , ( ) => {
71+ expect ( emailLinkStatusCopy ( 'signed-in' , m ) ) . toEqual ( {
72+ title : 'Successfully signed in' ,
73+ description : 'Return to original tab to continue' ,
74+ } ) ;
75+ expect ( emailLinkStatusCopy ( 'transferable' , m ) . title ) . toBe ( 'Email verified' ) ;
76+ } ) ;
77+
78+ it ( 'tells the original tab to go to the newly opened one' , ( ) => {
79+ expect ( emailLinkStatusCopy ( 'signed-in-other-tab' , m ) ) . toEqual ( {
80+ title : 'Signed in on other tab' ,
81+ description : 'Return to the newly opened tab to continue' ,
82+ } ) ;
83+ } ) ;
84+
85+ it ( 'names what went wrong with the link' , ( ) => {
86+ expect ( emailLinkStatusCopy ( 'expired' , m ) . title ) . toBe ( 'This verification link has expired' ) ;
87+ expect ( emailLinkStatusCopy ( 'failed' , m ) . title ) . toBe ( 'This verification link is invalid' ) ;
88+ expect ( emailLinkStatusCopy ( 'client-mismatch' , m ) . title ) . toBe ( 'Verification link is invalid for this device' ) ;
5289 } ) ;
5390} ) ;
5491
0 commit comments