mirror of
https://github.com/elastic/kibana.git
synced 2025-04-23 17:28:26 -04:00
* handle case where space name is made entirely of whitespace * update space name validation
This commit is contained in:
parent
b893aa76f4
commit
e45921e449
5 changed files with 33 additions and 2 deletions
|
@ -1,5 +1,17 @@
|
|||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`renders with a space name entirely made of whitespace 1`] = `
|
||||
<EuiAvatar
|
||||
color="#DB1374"
|
||||
data-test-subj="space-avatar-"
|
||||
initials=""
|
||||
initialsLength={2}
|
||||
name=""
|
||||
size="m"
|
||||
type="space"
|
||||
/>
|
||||
`;
|
||||
|
||||
exports[`renders without crashing 1`] = `
|
||||
<EuiAvatar
|
||||
color="#BFA180"
|
||||
|
|
|
@ -12,3 +12,8 @@ test('renders without crashing', () => {
|
|||
const wrapper = shallow(<SpaceAvatar space={{ name: '', id: '' }} />);
|
||||
expect(wrapper).toMatchSnapshot();
|
||||
});
|
||||
|
||||
test('renders with a space name entirely made of whitespace', () => {
|
||||
const wrapper = shallow(<SpaceAvatar space={{ name: ' ', id: '' }} />);
|
||||
expect(wrapper).toMatchSnapshot();
|
||||
});
|
||||
|
|
|
@ -18,11 +18,13 @@ interface Props {
|
|||
export const SpaceAvatar = (props: Props) => {
|
||||
const { space, size, ...rest } = props;
|
||||
|
||||
const spaceName = space.name ? space.name.trim() : '';
|
||||
|
||||
return (
|
||||
<EuiAvatar
|
||||
type="space"
|
||||
data-test-subj={`space-avatar-${space.id}`}
|
||||
name={space.name || ''}
|
||||
name={spaceName}
|
||||
size={size || 'm'}
|
||||
initialsLength={MAX_SPACE_INITIALS}
|
||||
initials={getSpaceInitials(space)}
|
||||
|
|
|
@ -34,6 +34,18 @@ describe('validateSpaceName', () => {
|
|||
});
|
||||
});
|
||||
|
||||
test('it cannot be composed entirely of whitespace', () => {
|
||||
const space = {
|
||||
id: '',
|
||||
name: ' ',
|
||||
};
|
||||
|
||||
expect(validator.validateSpaceName(space)).toEqual({
|
||||
isInvalid: true,
|
||||
error: `Name is required`,
|
||||
});
|
||||
});
|
||||
|
||||
test('it cannot exceed 1024 characters', () => {
|
||||
const space = {
|
||||
id: '',
|
||||
|
|
|
@ -31,7 +31,7 @@ export class SpaceValidator {
|
|||
return valid();
|
||||
}
|
||||
|
||||
if (!space.name) {
|
||||
if (!space.name || !space.name.trim()) {
|
||||
return invalid(`Name is required`);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue