-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs: add last missing docs, fix failing test
- Loading branch information
1 parent
fa9c638
commit 3dac81e
Showing
7 changed files
with
212 additions
and
39 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
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
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
42 changes: 41 additions & 1 deletion
42
packages/snap-preact-components/src/components/Molecules/CalloutBadge/readme.md
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,2 +1,42 @@ | ||
# CalloutBadge // TODO | ||
# CalloutBadge | ||
|
||
Renders callout badges configured in the Searchspring Management Console and returned from the API. This component is intended to be used within a `Result` component to display callout badges. | ||
|
||
## Usage | ||
|
||
### name | ||
The required `name` prop specifies the name of the callout badge to display. | ||
|
||
```jsx | ||
<CalloutBadge name={'callout'} controller={controller} result={controller.store.results[0]} /> | ||
``` | ||
|
||
### controller | ||
The required `controller` prop specifies a reference to the controller. | ||
|
||
```jsx | ||
<CalloutBadge name={'callout'} controller={controller} result={controller.store.results[0]} /> | ||
``` | ||
|
||
### result | ||
The required `result` prop specifies a reference to a product object from the `results` store array. | ||
|
||
```jsx | ||
<CalloutBadge name={'callout'} controller={controller} result={controller.store.results[0]} /> | ||
``` | ||
|
||
### componentMap | ||
The `componentMap` prop allows for custom badge components. This functionallity requires the component and accompanying files to be synced to the Searchspring Management Console using Snapfu. | ||
|
||
```jsx | ||
<CalloutBadge | ||
name={'callout'} | ||
controller={controller} | ||
result={controller.store.results[0]} | ||
componentMap={{ | ||
'customOnSaleBadge': () => <div>On Sale</div> | ||
}} | ||
/> | ||
``` | ||
|
||
|
57 changes: 56 additions & 1 deletion
57
packages/snap-preact-components/src/components/Molecules/OverlayBadge/readme.md
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,2 +1,57 @@ | ||
# OverlayBadge // TODO | ||
# OverlayBadge | ||
|
||
Renders overlay badges configured in the Searchspring Management Console and returned from the API. This component is intended to be used within a `Result` component to wrap elements (children) that should have overlay badges. | ||
|
||
## Usage | ||
|
||
### children | ||
The required children provided to the component will be wrapped and rendered in a relative div to allow badges to be positioned absolutely. | ||
|
||
```jsx | ||
<OverlayBadge controller={controller} result={controller.store.results[0]}> | ||
<div> | ||
<img src='/images/example.png'/> | ||
</div> | ||
</OverlayBadge> | ||
``` | ||
|
||
### controller | ||
The required `controller` prop specifies a reference to the controller. | ||
|
||
```jsx | ||
<OverlayBadge controller={controller} result={controller.store.results[0]}> | ||
<div> | ||
<img src='/images/example.png'/> | ||
</div> | ||
</OverlayBadge> | ||
``` | ||
|
||
### result | ||
The required `result` prop specifies a reference to a product object from the `results` store array. | ||
|
||
```jsx | ||
<OverlayBadge controller={controller} result={controller.store.results[0]}> | ||
<div> | ||
<img src='/images/example.png'/> | ||
</div> | ||
</OverlayBadge> | ||
``` | ||
|
||
### componentMap | ||
The `componentMap` prop allows for custom badge components. This functionallity requires the component and accompanying files to be synced to the Searchspring Management Console using Snapfu. | ||
|
||
```jsx | ||
<OverlayBadge | ||
controller={controller} | ||
result={controller.store.results[0]} | ||
componentMap={{ | ||
'customOnSaleBadge': () => <div>On Sale</div> | ||
}} | ||
> | ||
<div> | ||
<img src='/images/example.png'/> | ||
</div> | ||
</OverlayBadge> | ||
``` | ||
|
||
|
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
112 changes: 112 additions & 0 deletions
112
packages/snap-store-mobx/src/Search/Stores/SearchBadgeStore.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,112 @@ | ||
import { UrlManager, UrlTranslator } from '@searchspring/snap-url-manager'; | ||
import { MockData } from '@searchspring/snap-shared'; | ||
|
||
import { SearchBadgeStore } from './SearchBadgeStore'; | ||
import type { Product } from './SearchResultStore'; | ||
|
||
const services = { | ||
urlManager: new UrlManager(new UrlTranslator()), | ||
}; | ||
|
||
const mockData = new MockData(); | ||
|
||
describe('Sorting Store', () => { | ||
beforeEach(() => { | ||
expect.hasAssertions(); | ||
}); | ||
|
||
it('can construct', () => { | ||
const searchData = mockData.searchMeta(); | ||
// @ts-ignore - badges missing from MetaResponseModel | ||
const badgeStore = new SearchBadgeStore(searchData.meta); | ||
// @ts-ignore - private property | ||
expect(badgeStore.meta).toStrictEqual(searchData.meta); | ||
}); | ||
|
||
it('can get callout badge', () => { | ||
const searchData = mockData.searchMeta(); | ||
const meta = searchData.meta as any; | ||
|
||
const badgeStore = new SearchBadgeStore(meta); | ||
|
||
const calloutTag = Object.keys(meta.badges.tags || {}).find((tag) => { | ||
return meta.badges.tags[tag].location === 'callout'; | ||
})!; | ||
expect(calloutTag).toBeDefined(); | ||
|
||
const index = searchData.results!.findIndex((result: any) => result?.badges?.find((badge: any) => badge.tag === calloutTag))!; | ||
expect(index).toBeGreaterThanOrEqual(0); | ||
|
||
// mock a SearchResultStore | ||
const result = { | ||
...searchData.results![index], | ||
badges: [ | ||
{ | ||
...(searchData.results![index] as any).badges[0], | ||
...(searchData.meta as any).badges.tags[calloutTag], | ||
}, | ||
], | ||
} as Product; | ||
|
||
expect(result.badges[0]).toHaveProperty('tag'); | ||
expect(result.badges[0]).toHaveProperty('label'); | ||
expect(result.badges[0]).toHaveProperty('location'); | ||
expect(result.badges[0]).toHaveProperty('component'); | ||
expect(result.badges[0]).toHaveProperty('parameters'); | ||
|
||
const badge = badgeStore.getCalloutBadge(result, 'callout')!; | ||
|
||
expect(badge).toBeDefined(); | ||
expect(badge.tag).toBe(calloutTag); | ||
expect(badge.location).toBe('callout'); | ||
}); | ||
|
||
it('can get overlay badge', () => { | ||
const searchData = mockData.searchMeta(); | ||
const meta = searchData.meta as any; | ||
|
||
const badgeStore = new SearchBadgeStore(meta); | ||
|
||
let overlayTag = ''; | ||
const index = searchData.results!.findIndex((result: any) => { | ||
const tag = result.badges?.[0]?.tag; | ||
if (!tag) return false; | ||
const metaTag = meta.badges.tags[tag]; | ||
const location = metaTag.location; | ||
|
||
const hasOverlayBadge = | ||
meta.badges.locations.overlay.left.find((overlayLocation: any) => overlayLocation.name === location) || | ||
meta.badges.locations.overlay.right.find((overlayLocation: any) => overlayLocation.name === location); | ||
|
||
if (hasOverlayBadge) { | ||
overlayTag = tag; | ||
return true; | ||
} | ||
}); | ||
expect(index).toBeGreaterThanOrEqual(0); | ||
expect(overlayTag.length).toBeGreaterThan(0); | ||
|
||
// mock a SearchResultStore | ||
const result = { | ||
...searchData.results![index], | ||
badges: [ | ||
{ | ||
...(searchData.results![index] as any).badges[0], | ||
...(searchData.meta as any).badges.tags[overlayTag], | ||
}, | ||
], | ||
} as Product; | ||
|
||
expect(result.badges[0]).toHaveProperty('tag'); | ||
expect(result.badges[0]).toHaveProperty('label'); | ||
expect(result.badges[0]).toHaveProperty('location'); | ||
expect(result.badges[0]).toHaveProperty('component'); | ||
expect(result.badges[0]).toHaveProperty('parameters'); | ||
|
||
const badges = badgeStore.getOverlayBadges(result)!; | ||
|
||
expect(badges).toBeDefined(); | ||
expect(badges.length).toBeGreaterThan(0); | ||
expect(badges[0].tag).toBe(overlayTag); | ||
}); | ||
}); |