mirror of
https://github.com/strapi/strapi.git
synced 2025-12-29 08:04:51 +00:00
handle entries with no creator users
This commit is contained in:
parent
4a7f4c4926
commit
2aeb3e8253
@ -6,9 +6,15 @@
|
||||
* @property {string} username
|
||||
* @property {string} email
|
||||
*
|
||||
* @type {(user: AdminUserNamesAttributes, formatMessage: import('react-intl').formatMessage) => string}
|
||||
* @type {(user: AdminUserNamesAttributes | null, formatMessage: import('react-intl').formatMessage) => string}
|
||||
*/
|
||||
const getDisplayName = ({ firstname, lastname, username, email }, formatMessage) => {
|
||||
const getDisplayName = (user, formatMessage) => {
|
||||
if (!user) {
|
||||
return '-';
|
||||
}
|
||||
|
||||
const { firstname, lastname, username, email } = user;
|
||||
|
||||
if (username) {
|
||||
return username;
|
||||
}
|
||||
|
||||
@ -0,0 +1,49 @@
|
||||
import { getDisplayName } from '../getDisplayName';
|
||||
|
||||
const mockFormatMessage = jest.fn((message, values) => {
|
||||
return `${values.firstname} ${values.lastname}`;
|
||||
});
|
||||
|
||||
describe('getDisplayName', () => {
|
||||
it('should return username if username is defined', () => {
|
||||
expect(
|
||||
getDisplayName(
|
||||
{
|
||||
username: 'johnDoe',
|
||||
firstname: 'John',
|
||||
lastname: 'Doe',
|
||||
email: 'john@doe.com',
|
||||
},
|
||||
mockFormatMessage
|
||||
)
|
||||
).toEqual('johnDoe');
|
||||
});
|
||||
|
||||
it('should return firstname and lastname if firstname is defined', () => {
|
||||
expect(
|
||||
getDisplayName(
|
||||
{
|
||||
firstname: 'John',
|
||||
lastname: 'Doe',
|
||||
email: 'john@doe.com',
|
||||
},
|
||||
mockFormatMessage
|
||||
)
|
||||
).toEqual('John Doe');
|
||||
});
|
||||
|
||||
it('should return email if username and firstname are not defined', () => {
|
||||
expect(
|
||||
getDisplayName(
|
||||
{
|
||||
email: 'john@doe.com',
|
||||
},
|
||||
mockFormatMessage
|
||||
)
|
||||
).toEqual('john@doe.com');
|
||||
});
|
||||
|
||||
it('should return a dash if user is null', () => {
|
||||
expect(getDisplayName(null, mockFormatMessage)).toEqual('-');
|
||||
});
|
||||
});
|
||||
Loading…
x
Reference in New Issue
Block a user