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
28 caseName: 'Full data available (with email)',
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
37 expect: 'Some User <<someuser@example.com>>'
40 caseName: 'Missing first name',
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
48 expect: 'someuser@example.com'
51 caseName: 'Missing last name',
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
59 expect: 'someuser@example.com'
62 caseName: 'Missing first & last names',
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
70 expect: 'someuser@example.com'
73 caseName: 'Missing first & last names (with email)',
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
82 expect: 'someuser@example.com'
85 caseName: 'Missing first & last names, and email address',
87 email: '', username: 'someuser',
88 firstName: '', lastName: '',
89 uuid: 'zzzzz-tpzed-someusersuuid',
90 ownerUuid: 'zzzzz-tpzed-someusersowneruuid',
91 prefs: {}, isAdmin: false, isActive: true
96 caseName: 'Missing first & last names, and email address (with email)',
99 email: '', username: 'someuser',
100 firstName: '', lastName: '',
101 uuid: 'zzzzz-tpzed-someusersuuid',
102 ownerUuid: 'zzzzz-tpzed-someusersowneruuid',
103 prefs: {}, isAdmin: false, isActive: true
108 caseName: 'Missing all data (should not happen)',
110 email: '', username: '',
111 firstName: '', lastName: '',
112 uuid: 'zzzzz-tpzed-someusersuuid',
113 ownerUuid: 'zzzzz-tpzed-someusersowneruuid',
114 prefs: {}, isAdmin: false, isActive: true
116 expect: 'zzzzz-tpzed-someusersuuid'
119 testCases.forEach(c => {
120 const dispName = getUserDisplayName(c.user, c.withEmail);
121 expect(dispName).toEqual(c.expect);