11import { describe , expect , it } from 'vitest' ;
22
33import { resolveUserButtonLayout } from '../user-button.layout' ;
4- import type { UserButtonData , UserButtonMode , UserButtonModePriority } from '../user-button.types' ;
4+ import type { UserButtonData , UserButtonMode } from '../user-button.types' ;
55
66const alice = { sessionId : 'sess_1' , name : 'Alice Smith' , identifier : 'alice@example.com' } ;
77const bob = { sessionId : 'sess_2' , name : 'Bob Jones' , identifier : 'bob@example.com' } ;
88const foundry = { kind : 'membership' , organizationId : 'org_1' , name : 'Foundry' } as const ;
99
10- function resolve (
11- mode : UserButtonMode ,
12- data : Partial < UserButtonData > = { } ,
13- modePriority : UserButtonModePriority = 'organization' ,
14- ) {
15- return resolveUserButtonLayout ( mode , modePriority , {
10+ function resolve ( mode : UserButtonMode , data : Partial < UserButtonData > = { } ) {
11+ return resolveUserButtonLayout ( mode , {
1612 activeSession : alice ,
1713 activeOrganization : foundry ,
1814 hasOrganizations : true ,
@@ -25,30 +21,27 @@ function resolve(
2521}
2622
2723describe ( 'resolveUserButtonLayout, where each action lands' , ( ) => {
28- it ( 'spreads them across all four slots in combined mode' , ( ) => {
24+ it ( 'spreads them across all three slots in combined mode' , ( ) => {
2925 expect ( resolve ( 'combined' ) . actions ) . toEqual ( {
3026 header : [ 'inviteMembers' , 'manageLead' ] ,
31- organizationsHeading : [ 'manageAccount' , 'signOut' ] ,
3227 organizationsFooter : [ 'createOrganization' ] ,
33- footer : [ 'switchAccount' , 'signOutAll ' ] ,
28+ footer : [ 'switchAccount' , 'signOut ' ] ,
3429 } ) ;
3530 } ) ;
3631
3732 it ( 'carries no account actions at all in organization mode' , ( ) => {
3833 expect ( resolve ( 'organization' ) . actions ) . toEqual ( {
3934 header : [ 'inviteMembers' , 'manageLead' ] ,
40- organizationsHeading : [ ] ,
4135 organizationsFooter : [ 'createOrganization' ] ,
4236 footer : [ ] ,
4337 } ) ;
4438 } ) ;
4539
4640 it ( 'takes the account actions into the header and the foot in user mode' , ( ) => {
4741 expect ( resolve ( 'user' ) . actions ) . toEqual ( {
48- header : [ 'signOut' , 'manageLead' ] ,
49- organizationsHeading : [ ] ,
42+ header : [ 'manageLead' ] ,
5043 organizationsFooter : [ ] ,
51- footer : [ 'switchAccount' , 'signOutAll ' ] ,
44+ footer : [ 'switchAccount' , 'signOut ' ] ,
5245 } ) ;
5346 } ) ;
5447} ) ;
@@ -58,7 +51,7 @@ describe('resolveUserButtonLayout, what the data settles', () => {
5851 const layout = resolve ( 'combined' , { activeOrganization : null } ) ;
5952
6053 expect ( layout . lead ) . toBe ( 'user' ) ;
61- expect ( layout . actions . header ) . toEqual ( [ 'signOut' , ' manageLead'] ) ;
54+ expect ( layout . actions . header ) . toEqual ( [ 'manageLead' ] ) ;
6255 } ) ;
6356
6457 it ( 'leads with no selection where no organization is active and personal is hidden' , ( ) => {
@@ -69,60 +62,43 @@ describe('resolveUserButtonLayout, what the data settles', () => {
6962 } ) ;
7063
7164 // With no second account the flyout would open onto one row, so the foot offers that row instead.
72- // "All accounts" is that one account too, so the foot signs out of just it, in the singular.
73- it ( 'collapses the foot to "Add account" and "Sign out" in combined mode where there is one account' , ( ) => {
74- expect ( resolve ( 'combined' , { additionalSessions : [ ] } ) . actions . footer ) . toEqual ( [ 'addAccount' , 'signOut' ] ) ;
75- } ) ;
76-
77- it ( 'signs a lone account out from the header in user mode, leaving the foot to add one' , ( ) => {
78- const layout = resolve ( 'user' , { additionalSessions : [ ] } ) ;
79-
80- expect ( layout . actions . header ) . toEqual ( [ 'signOut' , 'manageLead' ] ) ;
81- expect ( layout . actions . footer ) . toEqual ( [ 'addAccount' ] ) ;
82- } ) ;
65+ it . each ( [ 'combined' , 'user' ] as const ) (
66+ 'collapses the foot to "Add account" in %s mode where there is one account' ,
67+ mode => {
68+ expect ( resolve ( mode , { additionalSessions : [ ] } ) . actions . footer ) . toEqual ( [ 'addAccount' , 'signOut' ] ) ;
69+ } ,
70+ ) ;
8371} ) ;
8472
85- describe ( 'resolveUserButtonLayout, a combined surface led by the account ' , ( ) => {
73+ describe ( 'resolveUserButtonLayout, a combined surface' , ( ) => {
8674 it ( 'leads with the account inside its active organization, inviting to that organization' , ( ) => {
87- const layout = resolve ( 'combined' , { } , 'user' ) ;
75+ const layout = resolve ( 'combined' ) ;
8876
8977 expect ( layout . lead ) . toBe ( 'member' ) ;
9078 expect ( layout . actions . header ) . toEqual ( [ 'inviteMembers' , 'manageLead' ] ) ;
9179 } ) ;
9280
93- it ( 'leads with the account alone where no organization is active' , ( ) => {
94- const layout = resolve ( 'combined' , { activeOrganization : null , hidePersonal : true } , 'user' ) ;
81+ it ( 'leads with the account alone where no organization is active, even with personal hidden ' , ( ) => {
82+ const layout = resolve ( 'combined' , { activeOrganization : null , hidePersonal : true } ) ;
9583
9684 expect ( layout . lead ) . toBe ( 'user' ) ;
97- expect ( layout . actions . header ) . toEqual ( [ 'signOut' , 'manageLead' ] ) ;
98- } ) ;
99-
100- it ( 'is ignored by the single-purpose modes' , ( ) => {
101- expect ( resolve ( 'organization' , { } , 'user' ) . lead ) . toBe ( 'organization' ) ;
102- expect ( resolve ( 'user' , { } , 'user' ) . lead ) . toBe ( 'user' ) ;
85+ expect ( layout . actions . header ) . toEqual ( [ 'manageLead' ] ) ;
10386 } ) ;
10487} ) ;
10588
10689describe ( 'resolveUserButtonLayout, how the header carries its actions' , ( ) => {
10790 it ( 'stacks them wherever a labelled action joins the gear' , ( ) => {
10891 expect ( resolve ( 'combined' ) . headerLayout ) . toBe ( 'stacked' ) ;
10992 expect ( resolve ( 'organization' ) . headerLayout ) . toBe ( 'stacked' ) ;
110- expect ( resolve ( 'user' ) . headerLayout ) . toBe ( 'stacked' ) ;
11193 } ) ;
11294
11395 it ( 'runs the gear inline where it is the only action' , ( ) => {
114- expect ( resolve ( 'combined' , { activeOrganization : null , hidePersonal : true } ) . headerLayout ) . toBe ( 'inline' ) ;
96+ expect ( resolve ( 'user' ) . headerLayout ) . toBe ( 'inline' ) ;
97+ expect ( resolve ( 'organization' , { activeOrganization : null , hidePersonal : true } ) . headerLayout ) . toBe ( 'inline' ) ;
11598 } ) ;
11699} ) ;
117100
118101describe ( 'resolveUserButtonLayout, which sections render' , ( ) => {
119- it ( 'heads the organizations with the account even where it belongs to none' , ( ) => {
120- const layout = resolve ( 'combined' , { hasOrganizations : false , memberships : [ ] , activeOrganization : null } ) ;
121-
122- expect ( layout . showOrganizationsHeading ) . toBe ( true ) ;
123- expect ( layout . showOrganizations ) . toBe ( false ) ;
124- } ) ;
125-
126102 it ( 'counts an invitation or a suggestion as something to list' , ( ) => {
127103 const invitation = {
128104 kind : 'invitation' ,
@@ -138,6 +114,6 @@ describe('resolveUserButtonLayout, which sections render', () => {
138114 } ) ;
139115
140116 it ( 'carries no organizations in user mode' , ( ) => {
141- expect ( resolve ( 'user' ) ) . toMatchObject ( { showOrganizations : false , showOrganizationsHeading : false } ) ;
117+ expect ( resolve ( 'user' ) . showOrganizations ) . toBe ( false ) ;
142118 } ) ;
143119} ) ;
0 commit comments