-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(bannerMessages): sw-884 generic banners
* bannerMessages, replace with generic banners * bannerMessagesContext, hooks for remove, add banners * productView, allow banner messages for all products * redux, actions, types, reducer, restructure
- Loading branch information
Showing
19 changed files
with
589 additions
and
736 deletions.
There are no files selected for viewing
530 changes: 279 additions & 251 deletions
530
src/components/bannerMessages/__tests__/__snapshots__/bannerMessages.test.js.snap
Large diffs are not rendered by default.
Oops, something went wrong.
76 changes: 38 additions & 38 deletions
76
src/components/bannerMessages/__tests__/__snapshots__/bannerMessagesContext.test.js.snap
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 |
---|---|---|
@@ -1,51 +1,51 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`BannerMessagesContext should apply a hook for retrieving messages data from a selectors: error response 1`] = ` | ||
{ | ||
"data": { | ||
"cloudigradeMismatch": false, | ||
}, | ||
"error": true, | ||
"fulfilled": undefined, | ||
"pending": undefined, | ||
} | ||
exports[`BannerMessagesContext should apply a hook for retrieving messages data from a selector and apply new messages: dispatch 1`] = ` | ||
[ | ||
[ | ||
{ | ||
"bannerMessages": [ | ||
{ | ||
"id": "lorem", | ||
"title": "ipsum", | ||
}, | ||
{ | ||
"id": "new message", | ||
"title": "new message", | ||
}, | ||
], | ||
"type": "SET_BANNER_MESSAGES", | ||
"viewId": "dolorSit", | ||
}, | ||
], | ||
] | ||
`; | ||
|
||
exports[`BannerMessagesContext should apply a hook for retrieving messages data from a selectors: mock store error response 1`] = ` | ||
{ | ||
"data": { | ||
"cloudigradeMismatch": false, | ||
}, | ||
"error": true, | ||
"fulfilled": false, | ||
"pending": false, | ||
} | ||
exports[`BannerMessagesContext should apply a hook for retrieving messages data from a selector and remove messages: dispatch 1`] = ` | ||
[ | ||
[ | ||
{ | ||
"bannerMessages": [], | ||
"type": "SET_BANNER_MESSAGES", | ||
"viewId": "dolorSit", | ||
}, | ||
], | ||
] | ||
`; | ||
|
||
exports[`BannerMessagesContext should apply a hook for retrieving messages data from a selectors: mock store success response 1`] = ` | ||
{ | ||
"data": { | ||
"cloudigradeMismatch": true, | ||
exports[`BannerMessagesContext should apply a hook for retrieving messages data from a selector: banner messages 1`] = ` | ||
[ | ||
{ | ||
"id": "lorem", | ||
"title": "ipsum", | ||
}, | ||
"error": false, | ||
"fulfilled": true, | ||
"pending": false, | ||
} | ||
`; | ||
|
||
exports[`BannerMessagesContext should apply a hook for retrieving messages data from a selectors: success response 1`] = ` | ||
{ | ||
"data": { | ||
"cloudigradeMismatch": false, | ||
}, | ||
"error": undefined, | ||
"fulfilled": true, | ||
"pending": undefined, | ||
} | ||
] | ||
`; | ||
|
||
exports[`BannerMessagesContext should return specific properties: specific properties 1`] = ` | ||
{ | ||
"useGetAppMessages": [Function], | ||
"useBannerMessages": [Function], | ||
"useRemoveBannerMessages": [Function], | ||
"useSetBannerMessages": [Function], | ||
} | ||
`; |
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
104 changes: 39 additions & 65 deletions
104
src/components/bannerMessages/__tests__/bannerMessagesContext.test.js
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 |
---|---|---|
@@ -1,86 +1,60 @@ | ||
import { context, useGetAppMessages } from '../bannerMessagesContext'; | ||
import { rhsmConstants } from '../../../services/rhsm/rhsmConstants'; | ||
import { context, useBannerMessages, useRemoveBannerMessages, useSetBannerMessages } from '../bannerMessagesContext'; | ||
|
||
describe('BannerMessagesContext', () => { | ||
it('should return specific properties', () => { | ||
expect(context).toMatchSnapshot('specific properties'); | ||
}); | ||
|
||
it('should apply a hook for retrieving messages data from a selectors', () => { | ||
const { result: errorResponse } = shallowHook(() => | ||
useGetAppMessages({ | ||
useSelectorsResponse: () => ({ | ||
error: true, | ||
data: { | ||
messages: {} | ||
it('should apply a hook for retrieving messages data from a selector', async () => { | ||
const { result } = await shallowHook(() => | ||
useBannerMessages({ | ||
useSelector: () => [ | ||
{ | ||
id: 'lorem', | ||
title: 'ipsum' | ||
} | ||
}) | ||
] | ||
}) | ||
); | ||
|
||
expect(errorResponse).toMatchSnapshot('error response'); | ||
expect(result).toMatchSnapshot('banner messages'); | ||
}); | ||
|
||
const { result: successResponse } = shallowHook(() => | ||
useGetAppMessages({ | ||
useSelectorsResponse: () => ({ | ||
fulfilled: true, | ||
data: { | ||
messages: {} | ||
it('should apply a hook for retrieving messages data from a selector and apply new messages', async () => { | ||
const mockDispatch = jest.fn(); | ||
const { result } = await mountHook(() => | ||
useSetBannerMessages({ | ||
useDispatch: () => mockDispatch, | ||
useProduct: () => ({ productId: 'dolorSit' }), | ||
useBannerMessages: () => [ | ||
{ | ||
id: 'lorem', | ||
title: 'ipsum' | ||
} | ||
}) | ||
] | ||
}) | ||
); | ||
|
||
expect(successResponse).toMatchSnapshot('success response'); | ||
|
||
const { result: mockStoreSuccessResponse } = shallowHook( | ||
() => | ||
useGetAppMessages({ | ||
useProduct: () => ({ productId: 'loremIpsum' }) | ||
}), | ||
{ | ||
state: { | ||
messages: { | ||
report: { | ||
loremIpsum: { | ||
fulfilled: true, | ||
data: { | ||
data: [ | ||
{ | ||
[rhsmConstants.RHSM_API_RESPONSE_TALLY_CAPACITY_META_TYPES.HAS_CLOUDIGRADE_MISMATCH]: true | ||
} | ||
] | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
); | ||
|
||
expect(mockStoreSuccessResponse).toMatchSnapshot('mock store success response'); | ||
result('new message'); | ||
expect(mockDispatch.mock.calls).toMatchSnapshot('dispatch'); | ||
}); | ||
|
||
const { result: mockStoreErrorResponse } = shallowHook( | ||
() => | ||
useGetAppMessages({ | ||
useProduct: () => ({ productId: 'loremIpsum' }) | ||
}), | ||
{ | ||
state: { | ||
messages: { | ||
report: { | ||
loremIpsum: { | ||
error: true, | ||
data: { | ||
data: [] | ||
} | ||
} | ||
} | ||
it('should apply a hook for retrieving messages data from a selector and remove messages', async () => { | ||
const mockDispatch = jest.fn(); | ||
const { result } = await mountHook(() => | ||
useRemoveBannerMessages({ | ||
useDispatch: () => mockDispatch, | ||
useProduct: () => ({ productId: 'dolorSit' }), | ||
useBannerMessages: () => [ | ||
{ | ||
id: 'lorem', | ||
title: 'ipsum' | ||
} | ||
} | ||
} | ||
] | ||
}) | ||
); | ||
|
||
expect(mockStoreErrorResponse).toMatchSnapshot('mock store error response'); | ||
result('ipsum'); | ||
expect(mockDispatch.mock.calls).toMatchSnapshot('dispatch'); | ||
}); | ||
}); |
Oops, something went wrong.