-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Enterprise Search] Add helpers for flash messages (#77677)
* [Enterprise Search] Add a helper for success messages * Move method to separate file * Update test names * D R Y * I really need to slow down 🤦🏼♂️ * PR feedback * Typo
- Loading branch information
1 parent
6683026
commit bd6b389
Showing
3 changed files
with
82 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
...s/enterprise_search/public/applications/shared/flash_messages/set_message_helpers.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import { | ||
FlashMessagesLogic, | ||
setSuccessMessage, | ||
setErrorMessage, | ||
setQueuedSuccessMessage, | ||
} from './'; | ||
|
||
describe('Flash Message Helpers', () => { | ||
const message = 'I am a message'; | ||
|
||
beforeEach(() => { | ||
FlashMessagesLogic.mount(); | ||
}); | ||
|
||
it('setSuccessMessage()', () => { | ||
setSuccessMessage(message); | ||
|
||
expect(FlashMessagesLogic.values.messages).toEqual([ | ||
{ | ||
message, | ||
type: 'success', | ||
}, | ||
]); | ||
}); | ||
|
||
it('setErrorMessage()', () => { | ||
setErrorMessage(message); | ||
|
||
expect(FlashMessagesLogic.values.messages).toEqual([ | ||
{ | ||
message, | ||
type: 'error', | ||
}, | ||
]); | ||
}); | ||
|
||
it('setQueuedSuccessMessage()', () => { | ||
setQueuedSuccessMessage(message); | ||
|
||
expect(FlashMessagesLogic.values.queuedMessages).toEqual([ | ||
{ | ||
message, | ||
type: 'success', | ||
}, | ||
]); | ||
}); | ||
}); |
28 changes: 28 additions & 0 deletions
28
...lugins/enterprise_search/public/applications/shared/flash_messages/set_message_helpers.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import { FlashMessagesLogic } from './'; | ||
|
||
export const setSuccessMessage = (message: string) => { | ||
FlashMessagesLogic.actions.setFlashMessages({ | ||
type: 'success', | ||
message, | ||
}); | ||
}; | ||
|
||
export const setErrorMessage = (message: string) => { | ||
FlashMessagesLogic.actions.setFlashMessages({ | ||
type: 'error', | ||
message, | ||
}); | ||
}; | ||
|
||
export const setQueuedSuccessMessage = (message: string) => { | ||
FlashMessagesLogic.actions.setQueuedMessages({ | ||
type: 'success', | ||
message, | ||
}); | ||
}; |