-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(commerce): add pagination and sort sub-controllers (#3800)
In follow-up PRs, I will: - Add pagination to the recs controller - Make sub-controller state handled separated, to allow multiple solution types to coexist - Add the facet generator as sub-controller - Remove the `build[SolutionType]pagination`, `build[SolutionType]sort`, `build[SolutionType]facetGenerator` and similar top-level builders that become sub-controllers [CAPI-719] [CAPI-719]: https://coveord.atlassian.net/browse/CAPI-719?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ
- Loading branch information
1 parent
313164d
commit 5f2d2a2
Showing
4 changed files
with
111 additions
and
1 deletion.
There are no files selected for viewing
81 changes: 81 additions & 0 deletions
81
...ges/headless/src/controllers/commerce/core/sub-controller/headless-sub-controller.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,81 @@ | ||
import {buildMockCommerceState} from '../../../../test/mock-commerce-state'; | ||
import { | ||
MockedCommerceEngine, | ||
buildMockCommerceEngine, | ||
} from '../../../../test/mock-engine-v2'; | ||
import * as CorePagination from '../pagination/headless-core-commerce-pagination'; | ||
import * as CoreInteractiveResult from '../result-list/headless-core-interactive-result'; | ||
import * as CoreSort from '../sort/headless-core-commerce-sort'; | ||
import { | ||
buildSolutionTypeSubControllers, | ||
SolutionTypeSubControllers, | ||
} from './headless-sub-controller'; | ||
|
||
describe('sub controllers', () => { | ||
let engine: MockedCommerceEngine; | ||
let subControllers: SolutionTypeSubControllers; | ||
const mockResponseIdSelector = jest.fn(); | ||
const mockFetchResultsActionCreator = jest.fn(); | ||
|
||
function initSubControllers() { | ||
engine = buildMockCommerceEngine(buildMockCommerceState()); | ||
|
||
subControllers = buildSolutionTypeSubControllers(engine, { | ||
responseIdSelector: mockResponseIdSelector, | ||
fetchResultsActionCreator: mockFetchResultsActionCreator, | ||
}); | ||
} | ||
|
||
beforeEach(() => { | ||
initSubControllers(); | ||
}); | ||
|
||
afterEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
it('#interactiveResult builds interactive result controller', () => { | ||
const buildCoreInteractiveResultMock = jest.spyOn( | ||
CoreInteractiveResult, | ||
'buildCoreInteractiveResult' | ||
); | ||
|
||
const props = { | ||
options: { | ||
product: { | ||
productId: '1', | ||
name: 'Product name', | ||
price: 17.99, | ||
}, | ||
position: 1, | ||
}, | ||
}; | ||
|
||
const interactiveResult = subControllers.interactiveResult({ | ||
...props, | ||
}); | ||
|
||
expect(interactiveResult).toEqual( | ||
buildCoreInteractiveResultMock.mock.results[0].value | ||
); | ||
}); | ||
|
||
it('#pagination builds pagination controller', () => { | ||
const buildCorePaginationMock = jest.spyOn( | ||
CorePagination, | ||
'buildCorePagination' | ||
); | ||
|
||
const pagination = subControllers.pagination(); | ||
|
||
expect(pagination).toEqual(buildCorePaginationMock.mock.results[0].value); | ||
}); | ||
|
||
it('#sort builds sort controller', () => { | ||
const buildCoreSortMock = jest.spyOn(CoreSort, 'buildCoreSort'); | ||
|
||
const sort = subControllers.sort(); | ||
|
||
expect(sort).toEqual(buildCoreSortMock.mock.results[0].value); | ||
}); | ||
}); |
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