Skip to content

Commit

Permalink
Merge pull request #108 from PagerDuty/issue-80
Browse files Browse the repository at this point in the history
  • Loading branch information
gsreynolds authored Jun 28, 2023
2 parents f30cf1d + 18b430c commit 0ab676a
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const PersonInitialsComponent = ({
// initials: getInitials(user.summary),
id: user.id,
html_url: user.html_url,
color: CSS.supports('color', color) ? color : 'black',
color: CSS.supports && CSS.supports('color', color) ? color : 'black',
};
})
: [];
Expand All @@ -44,10 +44,18 @@ const PersonInitialsComponent = ({
<Avatar
color="white"
mr={1}
whiteSpace="nowrap"
overflow="hidden"
name={user.summary}
href={user.html_url}
size="sm"
bg={user.color}
getInitials={(name) => {
const allNames = name.trim().split(' ');
const firstInitial = allNames[0].match(/./u);
const lastInitial = allNames[allNames.length - 1].match(/./u);
return `${firstInitial}${lastInitial}`;
}}
/>
</Link>
</Tooltip>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import {
Provider,
} from 'react-redux';

import {
mockStore,
} from 'mocks/store.test';

import {
generateMockUsers,
} from 'mocks/users.test';

import {
mount,
} from 'enzyme';

import PersonInitialsComponents from './PersonInitialsComponents';

describe('PersonInitialsComponents', () => {
const users = generateMockUsers(2);
users[0].summary = 'Abraham Lincoln';
users[1].summary = 'George Washington 📟';
let baseStore;
let store;
beforeEach(() => {
const usersMap = {};
users.forEach((user) => {
usersMap[user.id] = user;
});
baseStore = {
users: {
usersMap,
},
};
store = mockStore(baseStore);
global.CSS = jest.fn();
});

it('should render component with assignee initials', () => {
const displayedUsers = users.map((user) => ({
user,
}));
const wrapper = mount(
<Provider store={store}>
<PersonInitialsComponents displayedUsers={displayedUsers} />
</Provider>,
);
// Initials should be rendered
expect(wrapper.find('div[role="img"]').contains('AL')).toBeTruthy();
// Emojis should also be rendered as initials
expect(wrapper.find('div[role="img"]').contains('G📟')).toBeTruthy();
});
});
2 changes: 2 additions & 0 deletions src/mocks/users.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@ const generateMockUser = () => {
// Generate Faker stubs for user
const id = faker.string.alphanumeric(7);
const userName = faker.person.fullName();
const color = faker.color.human();
return {
id,
summary: userName,
color,
self: `https://api.pagerduty.com/users/${id}`,
html_url: `https://www.pagerduty.com/users/${id}`,
};
Expand Down

0 comments on commit 0ab676a

Please sign in to comment.