Skip to content
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

Added variant to facets query #682

Merged
merged 3 commits into from
Nov 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

## [Unreleased]

### Added

- `variant` to `facets` query, used to execute A/B tests.

## [3.133.1] - 2024-10-02

### Fixed
Expand Down
1 change: 1 addition & 0 deletions react/__tests__/Gallery.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ beforeEach(() => {
jest.clearAllMocks()

mockUseRuntime.mockImplementation(() => ({
route: { routeId: 'routeId' },
getSettings: () => ({}),
}))

Expand Down
17 changes: 11 additions & 6 deletions react/__tests__/components/PriceRange.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,17 @@ import { useRuntime } from 'vtex.render-runtime'
import PriceRange from '../../components/PriceRange'

const mockUseRuntime = useRuntime
const mockSetQuery = jest.fn()
const mockOnChangePriceRange = jest.fn()

jest.spyOn(window, 'scroll').mockImplementation(jest.fn())

beforeEach(() => {
jest.clearAllMocks()

mockUseRuntime.mockImplementation(() => ({
setQuery: mockSetQuery,
query: {
priceRange: {},
},
getSettings: () => ({}),
culture: { country: 'USA', currency: 'USD' },
}))
Expand Down Expand Up @@ -62,6 +66,7 @@ const mockProps = {
},
],
preventRouteChange: false,
onChangePriceRange: mockOnChangePriceRange,
}

describe('<PriceRange />', () => {
Expand All @@ -78,11 +83,11 @@ describe('<PriceRange />', () => {

fireEvent.click(getByText('$1.00 $10.00'))

expect(mockSetQuery).not.toBeCalled()
expect(mockOnChangePriceRange).not.toBeCalled()

jest.runAllTimers()

expect(mockSetQuery).toHaveBeenCalledTimes(1)
expect(mockOnChangePriceRange).toHaveBeenCalledTimes(1)
})

it('should call setQuery on Slider change only once after multiple interactions', () => {
Expand All @@ -93,11 +98,11 @@ describe('<PriceRange />', () => {
fireEvent.click(getByText('$1.00 $10.00'))
fireEvent.click(getByText('$1.00 $10.00'))

expect(mockSetQuery).not.toBeCalled()
expect(mockOnChangePriceRange).not.toBeCalled()

jest.runAllTimers()

expect(mockSetQuery).toHaveBeenCalledTimes(1)
expect(mockOnChangePriceRange).toHaveBeenCalledTimes(1)
})

it('should render defaultValues', () => {
Expand Down
1 change: 1 addition & 0 deletions react/components/SearchQuery.js
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@ const useQueries = (variables, facetsArgs, price) => {
fuzzy: variables.fuzzy,
searchState: variables.searchState || undefined,
initialAttributes: getInitialAttributes(),
variant: getCookie('sp-variant'),
},
skip: !facetsArgs.withFacets,
})
Expand Down
2 changes: 1 addition & 1 deletion react/hooks/useSession.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const useSession = () => {
}

return JSON.parse(data.namespaces.public.shippingOption.value)
}, [])
}, [rootPath])

return { getSession }
}
Expand Down
2 changes: 1 addition & 1 deletion react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
"vtex.store-drawer": "http://vtex.vtexassets.com/_v/public/typings/v1/[email protected]/public/@types/vtex.store-drawer",
"vtex.store-graphql": "http://vtex.vtexassets.com/_v/public/typings/v1/[email protected]/public/@types/vtex.store-graphql",
"vtex.store-icons": "http://vtex.vtexassets.com/_v/public/typings/v1/[email protected]/public/@types/vtex.store-icons",
"vtex.store-resources": "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.store-resources@0.95.0/public/@types/vtex.store-resources",
"vtex.store-resources": "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.store-resources@0.101.0/public/@types/vtex.store-resources",
Dismissed Show dismissed Hide dismissed
"vtex.structured-data": "http://vtex.vtexassets.com/_v/public/typings/v1/[email protected]/public/@types/vtex.structured-data",
"vtex.styleguide": "http://vtex.vtexassets.com/_v/public/typings/v1/[email protected]/public/@types/vtex.styleguide",
"vtex.tab-layout": "http://vtex.vtexassets.com/_v/public/typings/v1/[email protected]/public/@types/vtex.tab-layout"
Expand Down
2 changes: 1 addition & 1 deletion react/utils/compatibilityLayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export const buildSelectedFacetsAndFullText = (query, map, priceRange) => {
}

const addMap = facet => {
facet['map'] = facet.key
facet.map = facet.key

if (facet.children) {
facet.children.forEach(facetChild => addMap(facetChild))
Expand Down
6 changes: 3 additions & 3 deletions react/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5624,9 +5624,9 @@ validate-npm-package-license@^3.0.1:
version "0.18.0"
resolved "http://vtex.vtexassets.com/_v/public/typings/v1/[email protected]/public/@types/vtex.store-icons#0ee94d549aa283ce3a13ab987c13eac4fdfd1bba"

"vtex.store-resources@http://vtex.vtexassets.com/_v/public/typings/v1/vtex.store-resources@0.95.0/public/@types/vtex.store-resources":
version "0.95.0"
resolved "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.store-resources@0.95.0/public/@types/vtex.store-resources#74a95451b866ad56d7032e78298eba2174e5e2a0"
"vtex.store-resources@http://vtex.vtexassets.com/_v/public/typings/v1/vtex.store-resources@0.101.0/public/@types/vtex.store-resources":
version "0.101.0"
resolved "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.store-resources@0.101.0/public/@types/vtex.store-resources#d692dadaabcbbd879a611dc5bec3dcd0d4f3fb31"

"vtex.structured-data@http://vtex.vtexassets.com/_v/public/typings/v1/[email protected]/public/@types/vtex.structured-data":
version "0.9.1"
Expand Down
Loading