Skip to content

Commit

Permalink
[Enterprise Search] Add helpers for flash messages (#77677)
Browse files Browse the repository at this point in the history
* [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
scottybollinger authored Sep 16, 2020
1 parent 6683026 commit bd6b389
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ export {
} from './flash_messages_logic';
export { FlashMessagesProvider } from './flash_messages_provider';
export { flashAPIErrors } from './handle_api_errors';
export { setSuccessMessage, setErrorMessage, setQueuedSuccessMessage } from './set_message_helpers';
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',
},
]);
});
});
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,
});
};

0 comments on commit bd6b389

Please sign in to comment.