1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 import { User, getUserDisplayName } from './user';
7 describe('User', () => {
8 it('gets the user display name', () => {
15 const testCases: UserCase[] = [
17 caseName: 'Full data available',
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 canWrite: false, canManage: false,
29 caseName: 'Full data available (with email)',
32 email: 'someuser@example.com', username: 'someuser',
33 firstName: 'Some', lastName: 'User',
34 uuid: 'zzzzz-tpzed-someusersuuid',
35 ownerUuid: 'zzzzz-tpzed-someusersowneruuid',
36 prefs: {}, isAdmin: false, isActive: true,
37 canWrite: false, canManage: false
39 expect: 'Some User <someuser@example.com>'
42 caseName: 'Missing first name',
44 email: 'someuser@example.com', username: 'someuser',
45 firstName: '', lastName: 'User',
46 uuid: 'zzzzz-tpzed-someusersuuid',
47 ownerUuid: 'zzzzz-tpzed-someusersowneruuid',
48 prefs: {}, isAdmin: false, isActive: true,
49 canWrite: false, canManage: false,
52 expect: 'someuser@example.com'
55 caseName: 'Missing last name',
57 email: 'someuser@example.com', username: 'someuser',
58 firstName: 'Some', lastName: '',
59 uuid: 'zzzzz-tpzed-someusersuuid',
60 ownerUuid: 'zzzzz-tpzed-someusersowneruuid',
61 prefs: {}, isAdmin: false, isActive: true,
62 canWrite: false, canManage: false,
64 expect: 'someuser@example.com'
67 caseName: 'Missing first & last names',
69 email: 'someuser@example.com', username: 'someuser',
70 firstName: '', lastName: '',
71 uuid: 'zzzzz-tpzed-someusersuuid',
72 ownerUuid: 'zzzzz-tpzed-someusersowneruuid',
73 prefs: {}, isAdmin: false, isActive: true,
74 canWrite: false, canManage: false,
76 expect: 'someuser@example.com'
79 caseName: 'Missing first & last names (with email)',
82 email: 'someuser@example.com', username: 'someuser',
83 firstName: '', lastName: '',
84 uuid: 'zzzzz-tpzed-someusersuuid',
85 ownerUuid: 'zzzzz-tpzed-someusersowneruuid',
86 prefs: {}, isAdmin: false, isActive: true,
87 canWrite: false, canManage: false,
89 expect: 'someuser@example.com'
92 caseName: 'Missing first & last names, and email address',
94 email: '', username: 'someuser',
95 firstName: '', lastName: '',
96 uuid: 'zzzzz-tpzed-someusersuuid',
97 ownerUuid: 'zzzzz-tpzed-someusersowneruuid',
98 prefs: {}, isAdmin: false, isActive: true,
99 canWrite: false, canManage: false,
104 caseName: 'Missing first & last names, and email address (with email)',
107 email: '', username: 'someuser',
108 firstName: '', lastName: '',
109 uuid: 'zzzzz-tpzed-someusersuuid',
110 ownerUuid: 'zzzzz-tpzed-someusersowneruuid',
111 prefs: {}, isAdmin: false, isActive: true,
112 canWrite: false, canManage: false,
117 caseName: 'Missing all data (should not happen)',
119 email: '', username: '',
120 firstName: '', lastName: '',
121 uuid: 'zzzzz-tpzed-someusersuuid',
122 ownerUuid: 'zzzzz-tpzed-someusersowneruuid',
123 prefs: {}, isAdmin: false, isActive: true,
124 canWrite: false, canManage: false,
126 expect: 'zzzzz-tpzed-someusersuuid'
129 testCases.forEach(c => {
130 const dispName = getUserDisplayName(c.user, c.withEmail);
131 expect(dispName).toEqual(c.expect);