@@ -63,4 +63,131 @@ describe('mgt-person - tests', () => {
6363
6464 expect ( screen . queryByTestId ( 'flyout-slot' ) ) . toBeDefined ( ) ;
6565 } ) ;
66+
67+ it ( 'should render with initials when given name and surname are supplied' , async ( ) => {
68+ Providers . globalProvider = new MockProvider ( true ) ;
69+ person = await fixture (
70+ `<mgt-person person-details='${ JSON . stringify ( {
71+ displayName : 'Frank Herbert' ,
72+ 73+ givenName : 'Brian' ,
74+ surname : 'Herbert' ,
75+ personType : { }
76+ } ) } ' view="twoLines"></mgt-person>`
77+ ) ;
78+ expect ( person ) . not . toBeUndefined ( ) ;
79+ const initials = await screen . findByText ( 'BH' ) ;
80+ expect ( initials ) . toBeDefined ( ) ;
81+ } ) ;
82+
83+ it ( 'should render with initials when given name and surname are null' , async ( ) => {
84+ Providers . globalProvider = new MockProvider ( true ) ;
85+ person = await fixture (
86+ `<mgt-person person-details='${ JSON . stringify ( {
87+ displayName : 'Frank Herbert' ,
88+ 89+ givenName : null ,
90+ surname : null ,
91+ personType : { }
92+ } ) } ' view="twoLines"></mgt-person>`
93+ ) ;
94+ expect ( person ) . not . toBeUndefined ( ) ;
95+ const initials = await screen . findByText ( 'FH' ) ;
96+ expect ( initials ) . toBeDefined ( ) ;
97+ } ) ;
98+
99+ it ( 'should render with first initial when only given name is supplied' , async ( ) => {
100+ Providers . globalProvider = new MockProvider ( true ) ;
101+ person = await fixture (
102+ `<mgt-person person-details='${ JSON . stringify ( {
103+ displayName : 'Frank Herbert' ,
104+ 105+ givenName : 'Frank' ,
106+ surname : null ,
107+ personType : { }
108+ } ) } ' view="twoLines"></mgt-person>`
109+ ) ;
110+ expect ( person ) . not . toBeUndefined ( ) ;
111+ const initials = await screen . findByText ( 'F' ) ;
112+ expect ( initials ) . toBeDefined ( ) ;
113+ } ) ;
114+
115+ it ( 'should render with first initial when only given name is populated and surname is an empty string' , async ( ) => {
116+ Providers . globalProvider = new MockProvider ( true ) ;
117+ person = await fixture (
118+ `<mgt-person person-details='${ JSON . stringify ( {
119+ displayName : 'Frank Herbert' ,
120+ 121+ givenName : 'Frank' ,
122+ surname : '' ,
123+ personType : { }
124+ } ) } ' view="twoLines"></mgt-person>`
125+ ) ;
126+ expect ( person ) . not . toBeUndefined ( ) ;
127+ const initials = await screen . findByText ( 'F' ) ;
128+ expect ( initials ) . toBeDefined ( ) ;
129+ } ) ;
130+
131+ it ( 'should render with last initial when only surname is supplied' , async ( ) => {
132+ Providers . globalProvider = new MockProvider ( true ) ;
133+ person = await fixture (
134+ `<mgt-person person-details='${ JSON . stringify ( {
135+ displayName : 'Frank Herbert' ,
136+ 137+ givenName : null ,
138+ surname : 'Herbert' ,
139+ personType : { }
140+ } ) } ' view="twoLines"></mgt-person>`
141+ ) ;
142+ expect ( person ) . not . toBeUndefined ( ) ;
143+ const initials = await screen . findByText ( 'H' ) ;
144+ expect ( initials ) . toBeDefined ( ) ;
145+ } ) ;
146+ it ( 'should render with last initial when only surname is populated and given name is an empty string' , async ( ) => {
147+ Providers . globalProvider = new MockProvider ( true ) ;
148+ person = await fixture (
149+ `<mgt-person person-details='${ JSON . stringify ( {
150+ displayName : 'Frank Herbert' ,
151+ 152+ givenName : '' ,
153+ surname : 'Herbert' ,
154+ personType : { }
155+ } ) } ' view="twoLines"></mgt-person>`
156+ ) ;
157+ expect ( person ) . not . toBeUndefined ( ) ;
158+ const initials = await screen . findByText ( 'H' ) ;
159+ expect ( initials ) . toBeDefined ( ) ;
160+ } ) ;
161+
162+ it ( 'should render with one initial when only displayName of one word is supplied' , async ( ) => {
163+ Providers . globalProvider = new MockProvider ( true ) ;
164+ person = await fixture (
165+ `<mgt-person person-details='${ JSON . stringify ( {
166+ displayName : 'Frank' ,
167+ 168+ givenName : null ,
169+ surname : null ,
170+ personType : { }
171+ } ) } ' view="twoLines"></mgt-person>`
172+ ) ;
173+ expect ( person ) . not . toBeUndefined ( ) ;
174+ const initials = await screen . findByText ( 'F' ) ;
175+ expect ( initials ) . toBeDefined ( ) ;
176+ } ) ;
177+
178+ it ( 'should render with two initial when only displayName of more than two words is supplied' , async ( ) => {
179+ Providers . globalProvider = new MockProvider ( true ) ;
180+ person = await fixture (
181+ `<mgt-person person-details='${ JSON . stringify ( {
182+ displayName : 'Frank van Herbert' ,
183+ 184+ givenName : null ,
185+ surname : null ,
186+ personType : { }
187+ } ) } ' view="twoLines"></mgt-person>`
188+ ) ;
189+ expect ( person ) . not . toBeUndefined ( ) ;
190+ const initials = await screen . findByText ( 'FV' ) ;
191+ expect ( initials ) . toBeDefined ( ) ;
192+ } ) ;
66193} ) ;
0 commit comments