Merge branch '16245-horizontal-scroll-bar-is-at-the-bottom-of-the-page-instead-of...
[arvados.git] / src / models / user.test.ts
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: AGPL-3.0
4
5 import { User, getUserDisplayName } from './user';
6
7 describe('User', () => {
8     it('gets the user display name', () => {
9         type UserCase = {
10             caseName: string;
11             withEmail?: boolean;
12             user: User;
13             expect: string;
14         };
15         const testCases: UserCase[] = [
16             {
17                 caseName: 'Full data available',
18                 user: {
19                     email: 'someuser@example.com', username: 'someuser',
20                     firstName: 'Some', lastName: 'User',
21                     uuid: 'zzzzz-tpzed-someusersuuid',
22                     ownerUuid: 'zzzzz-tpzed-someusersowneruuid',
23                     prefs: {}, isAdmin: false, isActive: true
24                 },
25                 expect: 'Some User'
26             },
27             {
28                 caseName: 'Full data available (with email)',
29                 withEmail: true,
30                 user: {
31                     email: 'someuser@example.com', username: 'someuser',
32                     firstName: 'Some', lastName: 'User',
33                     uuid: 'zzzzz-tpzed-someusersuuid',
34                     ownerUuid: 'zzzzz-tpzed-someusersowneruuid',
35                     prefs: {}, isAdmin: false, isActive: true
36                 },
37                 expect: 'Some User <<someuser@example.com>>'
38             },
39             {
40                 caseName: 'Missing first name',
41                 user: {
42                     email: 'someuser@example.com', username: 'someuser',
43                     firstName: '', lastName: 'User',
44                     uuid: 'zzzzz-tpzed-someusersuuid',
45                     ownerUuid: 'zzzzz-tpzed-someusersowneruuid',
46                     prefs: {}, isAdmin: false, isActive: true
47                 },
48                 expect: 'someuser@example.com'
49             },
50             {
51                 caseName: 'Missing last name',
52                 user: {
53                     email: 'someuser@example.com', username: 'someuser',
54                     firstName: 'Some', lastName: '',
55                     uuid: 'zzzzz-tpzed-someusersuuid',
56                     ownerUuid: 'zzzzz-tpzed-someusersowneruuid',
57                     prefs: {}, isAdmin: false, isActive: true
58                 },
59                 expect: 'someuser@example.com'
60             },
61             {
62                 caseName: 'Missing first & last names',
63                 user: {
64                     email: 'someuser@example.com', username: 'someuser',
65                     firstName: '', lastName: '',
66                     uuid: 'zzzzz-tpzed-someusersuuid',
67                     ownerUuid: 'zzzzz-tpzed-someusersowneruuid',
68                     prefs: {}, isAdmin: false, isActive: true
69                 },
70                 expect: 'someuser@example.com'
71             },
72             {
73                 caseName: 'Missing first & last names (with email)',
74                 withEmail: true,
75                 user: {
76                     email: 'someuser@example.com', username: 'someuser',
77                     firstName: '', lastName: '',
78                     uuid: 'zzzzz-tpzed-someusersuuid',
79                     ownerUuid: 'zzzzz-tpzed-someusersowneruuid',
80                     prefs: {}, isAdmin: false, isActive: true
81                 },
82                 expect: 'someuser@example.com'
83             },
84             {
85                 caseName: 'Missing first & last names, and email address',
86                 user: {
87                     email: '', username: 'someuser',
88                     firstName: '', lastName: '',
89                     uuid: 'zzzzz-tpzed-someusersuuid',
90                     ownerUuid: 'zzzzz-tpzed-someusersowneruuid',
91                     prefs: {}, isAdmin: false, isActive: true
92                 },
93                 expect: 'someuser'
94             },
95             {
96                 caseName: 'Missing first & last names, and email address (with email)',
97                 withEmail: true,
98                 user: {
99                     email: '', username: 'someuser',
100                     firstName: '', lastName: '',
101                     uuid: 'zzzzz-tpzed-someusersuuid',
102                     ownerUuid: 'zzzzz-tpzed-someusersowneruuid',
103                     prefs: {}, isAdmin: false, isActive: true
104                 },
105                 expect: 'someuser'
106             },
107             {
108                 caseName: 'Missing all data (should not happen)',
109                 user: {
110                     email: '', username: '',
111                     firstName: '', lastName: '',
112                     uuid: 'zzzzz-tpzed-someusersuuid',
113                     ownerUuid: 'zzzzz-tpzed-someusersowneruuid',
114                     prefs: {}, isAdmin: false, isActive: true
115                 },
116                 expect: 'zzzzz-tpzed-someusersuuid'
117             },
118         ];
119         testCases.forEach(c => {
120             const dispName = getUserDisplayName(c.user, c.withEmail);
121             expect(dispName).toEqual(c.expect);
122         })
123     });
124 });