-
Notifications
You must be signed in to change notification settings - Fork 364
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: [M3-6430] - Event entities should only be linked for true labels #9003
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ import getEventMessage, { | |
eventMessageCreators, | ||
safeSecondaryEntityLabel, | ||
} from './eventMessageGenerator'; | ||
import { applyLinking } from './eventMessageGenerator'; | ||
|
||
beforeEach(() => { | ||
jest.spyOn(console, 'error').mockImplementation(() => {}); | ||
|
@@ -87,4 +88,52 @@ describe('Event message generation', () => { | |
).not.toMatch('booted with'); | ||
}); | ||
}); | ||
|
||
describe('apply linking to labels', () => { | ||
it('should return empty string if message is falsy', () => { | ||
const mockEvent = { | ||
action: 'create', | ||
entity: null, | ||
secondary_entity: null, | ||
}; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we use the What can we do to avoid There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
const message = null; | ||
const result = applyLinking(mockEvent as Event, message as any); | ||
|
||
expect(result).toEqual(''); | ||
}); | ||
|
||
it('should replace entity label with link if entity and link exist', () => { | ||
const entity = { id: '123', label: 'foo', type: 'linode' }; | ||
const mockEvent = { action: 'create', entity, secondary_entity: null }; | ||
const message = 'created entity foo'; | ||
const link = '/linodes/123'; | ||
const result = applyLinking(mockEvent as any, message); | ||
|
||
expect(result).toEqual(`created entity <a href="${link}">foo</a> `); | ||
}); | ||
|
||
it('should replace secondary entity label with link if entity and link exist', () => { | ||
jest.clearAllMocks(); | ||
|
||
const entity = { id: '123', label: 'foo', type: 'linode' }; | ||
const secondary_entity = { id: '456', label: 'bar' }; | ||
const mockEvent = { action: 'create', entity, secondary_entity }; | ||
const message = 'created secondary_entity for foo'; | ||
const link = '/linodes/123'; | ||
const result = applyLinking(mockEvent as any, message); | ||
|
||
expect(result).toEqual( | ||
`created secondary_entity for <a href="${link}">foo</a> ` | ||
); | ||
}); | ||
|
||
it('should not replace entity label if label is inside backticks', () => { | ||
const entity = { id: '123', label: 'foo' }; | ||
const mockEvent = { action: 'create', entity, secondary_entity: null }; | ||
const message = 'created `foo`'; | ||
const result = applyLinking(mockEvent as any, message); | ||
|
||
expect(result).toEqual('created `foo`'); | ||
}); | ||
}); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for adding test coverage!