@daffodil/search-product 0.0.0-PLACEHOLDER
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintrc.js +52 -0
- package/README.md +11 -0
- package/driver/in-memory/ng-package.json +8 -0
- package/driver/in-memory/package.json +3 -0
- package/driver/in-memory/src/backend/search.service.spec.ts +72 -0
- package/driver/in-memory/src/backend/search.service.ts +77 -0
- package/driver/in-memory/src/in-memory.module.ts +32 -0
- package/driver/in-memory/src/index.ts +1 -0
- package/driver/in-memory/src/public_api.ts +1 -0
- package/driver/magento/ng-package.json +8 -0
- package/driver/magento/package.json +3 -0
- package/driver/magento/src/core.module.ts +26 -0
- package/driver/magento/src/driver.module.ts +33 -0
- package/driver/magento/src/errors/map.ts +12 -0
- package/driver/magento/src/errors/transform.spec.ts +27 -0
- package/driver/magento/src/errors/transform.ts +46 -0
- package/driver/magento/src/federated-driver.module.ts +53 -0
- package/driver/magento/src/index.ts +1 -0
- package/driver/magento/src/models/get-product-response.interface.ts +18 -0
- package/driver/magento/src/models/public_api.ts +1 -0
- package/driver/magento/src/product-search.service.spec.ts +180 -0
- package/driver/magento/src/product-search.service.ts +124 -0
- package/driver/magento/src/public_api.ts +6 -0
- package/driver/magento/src/queries/fragments/product-result.ts +30 -0
- package/driver/magento/src/queries/product-search.ts +47 -0
- package/driver/ng-package.json +8 -0
- package/driver/package.json +3 -0
- package/driver/src/index.ts +1 -0
- package/driver/src/interfaces/options.interface.ts +4 -0
- package/driver/src/interfaces/public_api.ts +3 -0
- package/driver/src/interfaces/response.interface.ts +7 -0
- package/driver/src/interfaces/search-product-service.interface.ts +23 -0
- package/driver/src/public_api.ts +1 -0
- package/driver/testing/ng-package.json +8 -0
- package/driver/testing/package.json +3 -0
- package/driver/testing/src/index.ts +1 -0
- package/driver/testing/src/public_api.ts +1 -0
- package/driver/testing/src/testing.module.ts +31 -0
- package/karma.conf.js +10 -0
- package/ng-package.json +8 -0
- package/ng-package.prod.json +7 -0
- package/package.json +48 -0
- package/routing/ng-package.json +8 -0
- package/routing/package.json +3 -0
- package/routing/src/effects/collection-route.effects.ts +35 -0
- package/routing/src/index.ts +1 -0
- package/routing/src/module.ts +40 -0
- package/routing/src/public_api.ts +1 -0
- package/src/constants/public_api.ts +1 -0
- package/src/constants/search-result-kind.ts +6 -0
- package/src/index.ts +1 -0
- package/src/models/product-search-result.type.ts +11 -0
- package/src/models/public_api.ts +1 -0
- package/src/public_api.ts +3 -0
- package/src/transforms/products-to-result.spec.ts +34 -0
- package/src/transforms/products-to-result.ts +13 -0
- package/src/transforms/public_api.ts +1 -0
- package/state/ng-package.json +8 -0
- package/state/package.json +3 -0
- package/state/src/actions/product-collection.actions.ts +115 -0
- package/state/src/core.module.ts +37 -0
- package/state/src/effects/collection.effects.spec.ts +363 -0
- package/state/src/effects/collection.effects.ts +90 -0
- package/state/src/facades/collection/facade.ts +24 -0
- package/state/src/facades/public_api.ts +5 -0
- package/state/src/facades/search/incremental.facade.ts +23 -0
- package/state/src/facades/search/page.facade.ts +23 -0
- package/state/src/facades/search/search-facade.interface.ts +15 -0
- package/state/src/facades/search/search.facade.spec.ts +103 -0
- package/state/src/facades/search/search.facade.ts +34 -0
- package/state/src/index.ts +1 -0
- package/state/src/page.module.ts +18 -0
- package/state/src/public_api.ts +7 -0
- package/state/src/reducers/collection/public_api.ts +3 -0
- package/state/src/reducers/collection/reducer.ts +64 -0
- package/state/src/reducers/collection/search-reducers.ts +11 -0
- package/state/src/reducers/collection/search.reducer.spec.ts +156 -0
- package/state/src/reducers/collection/search.reducer.ts +35 -0
- package/state/src/reducers/product/entities.reducer.spec.ts +62 -0
- package/state/src/reducers/product/entities.reducer.ts +33 -0
- package/state/src/reducers/product/public_api.ts +2 -0
- package/state/src/reducers/product/reducers.spec.ts +16 -0
- package/state/src/reducers/product/reducers.ts +13 -0
- package/state/src/reducers/public_api.ts +9 -0
- package/state/src/reducers/reducers.interface.ts +19 -0
- package/state/src/reducers/reducers.spec.ts +10 -0
- package/state/src/reducers/reducers.ts +11 -0
- package/state/src/reducers/store-feature-key.ts +4 -0
- package/state/src/selectors/collection/selectors.ts +24 -0
- package/state/src/selectors/incremental/selectors.ts +10 -0
- package/state/src/selectors/page/selectors.ts +10 -0
- package/state/src/selectors/public_api.ts +5 -0
- package/state/src/selectors/search-feature.selector.ts +25 -0
- package/state/src/selectors/search.selector.spec.ts +113 -0
- package/state/src/selectors/search.selector.ts +52 -0
- package/state/src/state.module.ts +14 -0
- package/state/testing/ng-package.json +8 -0
- package/state/testing/package.json +3 -0
- package/state/testing/src/index.ts +1 -0
- package/state/testing/src/mock-search-facade.ts +21 -0
- package/state/testing/src/public_api.ts +2 -0
- package/state/testing/src/testing.module.ts +22 -0
- package/test.ts +24 -0
- package/testing/ng-package.json +8 -0
- package/testing/package.json +3 -0
- package/testing/src/factories/product-search-result.factory.spec.ts +43 -0
- package/testing/src/factories/product-search-result.factory.ts +26 -0
- package/testing/src/factories/public_api.ts +1 -0
- package/testing/src/index.ts +1 -0
- package/testing/src/public_api.ts +2 -0
- package/testing/src/testing.module.ts +19 -0
- package/tsconfig.json +38 -0
- package/tsconfig.lib.json +28 -0
- package/tsconfig.lib.prod.json +9 -0
- package/tsconfig.spec.json +19 -0
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import {
|
|
2
|
+
inject,
|
|
3
|
+
NgModule,
|
|
4
|
+
} from '@angular/core';
|
|
5
|
+
import { EffectsModule } from '@ngrx/effects';
|
|
6
|
+
|
|
7
|
+
import {
|
|
8
|
+
DaffProductGetCollectionRequestFromRoute,
|
|
9
|
+
DaffProductRoutingModule,
|
|
10
|
+
} from '@daffodil/product/routing';
|
|
11
|
+
import { DaffSearchProductDriverOptions } from '@daffodil/search-product/driver';
|
|
12
|
+
import {
|
|
13
|
+
DaffSearchRoutingModule,
|
|
14
|
+
DaffSearchRoutingOptionBuilder,
|
|
15
|
+
DAFF_SEARCH_ROUTING_OPTIONS_BUILDERS,
|
|
16
|
+
} from '@daffodil/search/routing';
|
|
17
|
+
|
|
18
|
+
import { DaffSearchProductRoutingCollectionEffects } from './effects/collection-route.effects';
|
|
19
|
+
|
|
20
|
+
@NgModule({
|
|
21
|
+
imports: [
|
|
22
|
+
DaffProductRoutingModule,
|
|
23
|
+
DaffSearchRoutingModule,
|
|
24
|
+
EffectsModule.forFeature([
|
|
25
|
+
DaffSearchProductRoutingCollectionEffects,
|
|
26
|
+
]),
|
|
27
|
+
],
|
|
28
|
+
providers: [
|
|
29
|
+
{
|
|
30
|
+
provide: DAFF_SEARCH_ROUTING_OPTIONS_BUILDERS,
|
|
31
|
+
useFactory: () => {
|
|
32
|
+
const service = inject(DaffProductGetCollectionRequestFromRoute);
|
|
33
|
+
const builder: DaffSearchRoutingOptionBuilder<DaffSearchProductDriverOptions> = route => service.getRequest(route.queryParamMap);
|
|
34
|
+
return builder;
|
|
35
|
+
},
|
|
36
|
+
multi: true,
|
|
37
|
+
},
|
|
38
|
+
],
|
|
39
|
+
})
|
|
40
|
+
export class DaffSearchProductRoutingModule {}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { DaffSearchProductRoutingModule } from './module';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { DAFF_SEARCH_PRODUCT_RESULT_KIND } from './search-result-kind';
|
package/src/index.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './public_api';
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { DaffProduct } from '@daffodil/product';
|
|
2
|
+
import { DaffSearchResult } from '@daffodil/search';
|
|
3
|
+
|
|
4
|
+
import { DAFF_SEARCH_PRODUCT_RESULT_KIND } from '../constants/public_api';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* An extension of a {@link DaffSearchResult} for products.
|
|
8
|
+
*/
|
|
9
|
+
export type DaffSearchProductResult<T extends DaffProduct = DaffProduct> = DaffSearchResult & T & {
|
|
10
|
+
kind: typeof DAFF_SEARCH_PRODUCT_RESULT_KIND;
|
|
11
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { DaffSearchProductResult } from './product-search-result.type';
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { TestBed } from '@angular/core/testing';
|
|
2
|
+
|
|
3
|
+
import { DaffProduct } from '@daffodil/product';
|
|
4
|
+
import { DaffDefaultProductFactory } from '@daffodil/product/testing';
|
|
5
|
+
import {
|
|
6
|
+
DaffSearchProductResult,
|
|
7
|
+
DAFF_SEARCH_PRODUCT_RESULT_KIND,
|
|
8
|
+
} from '@daffodil/search-product';
|
|
9
|
+
|
|
10
|
+
import { daffTransformProductsToSearchResults } from './products-to-result';
|
|
11
|
+
|
|
12
|
+
describe('@daffodil/search-product | daffTransformProductsToSearchResults', () => {
|
|
13
|
+
let productFactory: DaffDefaultProductFactory;
|
|
14
|
+
let mockProduct: DaffProduct;
|
|
15
|
+
let result: DaffSearchProductResult[];
|
|
16
|
+
|
|
17
|
+
beforeEach(() => {
|
|
18
|
+
productFactory = TestBed.inject(DaffDefaultProductFactory);
|
|
19
|
+
mockProduct = productFactory.create();
|
|
20
|
+
|
|
21
|
+
result = daffTransformProductsToSearchResults([mockProduct]);
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
it('should set search result fields from the product', () => {
|
|
25
|
+
expect(result[0].id).toEqual(mockProduct.id);
|
|
26
|
+
expect(result[0].url).toEqual(mockProduct.url);
|
|
27
|
+
expect(result[0].description).toEqual(mockProduct.description);
|
|
28
|
+
expect(result[0].name).toEqual(mockProduct.name);
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
it('should set the kind to product', () => {
|
|
32
|
+
expect(result[0].kind).toEqual(DAFF_SEARCH_PRODUCT_RESULT_KIND);
|
|
33
|
+
});
|
|
34
|
+
});
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { DaffProduct } from '@daffodil/product';
|
|
2
|
+
|
|
3
|
+
import { DAFF_SEARCH_PRODUCT_RESULT_KIND } from '../constants/public_api';
|
|
4
|
+
import { DaffSearchProductResult } from '../models/public_api';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Transforms a list of products into a list of product search results.
|
|
8
|
+
*/
|
|
9
|
+
export const daffTransformProductsToSearchResults = <T extends DaffProduct = DaffProduct>(products: T[]): DaffSearchProductResult<T>[] =>
|
|
10
|
+
products.map(product => ({
|
|
11
|
+
...product,
|
|
12
|
+
kind: DAFF_SEARCH_PRODUCT_RESULT_KIND,
|
|
13
|
+
}));
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { daffTransformProductsToSearchResults } from './products-to-result';
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import {
|
|
2
|
+
DaffCollectionRequest,
|
|
3
|
+
DaffFilterRequest,
|
|
4
|
+
DaffFilterToggleRequest,
|
|
5
|
+
} from '@daffodil/core';
|
|
6
|
+
import {
|
|
7
|
+
DaffCollectionChangePageSize,
|
|
8
|
+
DaffCollectionChangeCurrentPage,
|
|
9
|
+
DaffCollectionChangeSortingOption,
|
|
10
|
+
DaffCollectionReplaceFilters,
|
|
11
|
+
DaffCollectionApplyFilters,
|
|
12
|
+
DaffCollectionRemoveFilters,
|
|
13
|
+
DaffCollectionToggleFilter,
|
|
14
|
+
DaffCollectionClearFilters,
|
|
15
|
+
} from '@daffodil/core/state';
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* The search action types enum.
|
|
19
|
+
*/
|
|
20
|
+
export enum DaffSearchProductCollectionActionTypes {
|
|
21
|
+
SearchProductReplaceFiltersAction = '[@daffodil/search-product] Search Product Replace Filters Action',
|
|
22
|
+
SearchProductApplyFiltersAction = '[@daffodil/search-product] Search Product Apply Filters Action',
|
|
23
|
+
SearchProductRemoveFiltersAction = '[@daffodil/search-product] Search Product Remove Filters Action',
|
|
24
|
+
SearchProductClearFiltersAction = '[@daffodil/search-product] Search Product Clear Filters Action',
|
|
25
|
+
SearchProductToggleFiltersAction = '[@daffodil/search-product] Search Product Toggle Filters Action',
|
|
26
|
+
SearchProductChangePageSizeAction = '[@daffodil/search-product] Search Product Change Page Size Action',
|
|
27
|
+
SearchProductChangeCurrentPageAction = '[@daffodil/search-product] Search Product Change Current Page Action',
|
|
28
|
+
SearchProductChangeSortingOptionAction = '[@daffodil/search-product] Search Product Change Sorting Option Action',
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* @inheritdoc
|
|
33
|
+
*/
|
|
34
|
+
export class DaffSearchProductCollectionReplaceFilters implements DaffCollectionReplaceFilters {
|
|
35
|
+
readonly type = DaffSearchProductCollectionActionTypes.SearchProductReplaceFiltersAction;
|
|
36
|
+
|
|
37
|
+
constructor(public filters: DaffFilterRequest[]) {}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* @inheritdoc
|
|
42
|
+
*/
|
|
43
|
+
export class DaffSearchProductCollectionApplyFilters implements DaffCollectionApplyFilters {
|
|
44
|
+
readonly type = DaffSearchProductCollectionActionTypes.SearchProductApplyFiltersAction;
|
|
45
|
+
|
|
46
|
+
constructor(public filters: DaffFilterRequest[]) {}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* @inheritdoc
|
|
51
|
+
*/
|
|
52
|
+
export class DaffSearchProductCollectionRemoveFilters implements DaffCollectionRemoveFilters {
|
|
53
|
+
readonly type = DaffSearchProductCollectionActionTypes.SearchProductRemoveFiltersAction;
|
|
54
|
+
|
|
55
|
+
constructor(public filters: DaffFilterRequest[]) {}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* @inheritdoc
|
|
60
|
+
*/
|
|
61
|
+
export class DaffSearchProductCollectionClearFilters implements DaffCollectionClearFilters {
|
|
62
|
+
readonly type = DaffSearchProductCollectionActionTypes.SearchProductClearFiltersAction;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* @inheritdoc
|
|
67
|
+
*/
|
|
68
|
+
export class DaffSearchProductCollectionToggleFilter implements DaffCollectionToggleFilter {
|
|
69
|
+
readonly type = DaffSearchProductCollectionActionTypes.SearchProductToggleFiltersAction;
|
|
70
|
+
|
|
71
|
+
constructor(public filter: DaffFilterToggleRequest) {}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* @inheritdoc
|
|
76
|
+
*/
|
|
77
|
+
export class DaffSearchProductCollectionChangePageSize implements DaffCollectionChangePageSize {
|
|
78
|
+
readonly type = DaffSearchProductCollectionActionTypes.SearchProductChangePageSizeAction;
|
|
79
|
+
|
|
80
|
+
constructor(public pageSize: number) {}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* @inheritdoc
|
|
85
|
+
*/
|
|
86
|
+
export class DaffSearchProductCollectionChangeCurrentPage implements DaffCollectionChangeCurrentPage {
|
|
87
|
+
readonly type = DaffSearchProductCollectionActionTypes.SearchProductChangeCurrentPageAction;
|
|
88
|
+
|
|
89
|
+
constructor(public currentPage: number) {}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* @inheritdoc
|
|
94
|
+
*/
|
|
95
|
+
export class DaffSearchProductCollectionChangeSortingOption implements DaffCollectionChangeSortingOption {
|
|
96
|
+
readonly type = DaffSearchProductCollectionActionTypes.SearchProductChangeSortingOptionAction;
|
|
97
|
+
|
|
98
|
+
constructor(public sort: {
|
|
99
|
+
option: DaffCollectionRequest['appliedSortOption'];
|
|
100
|
+
direction: DaffCollectionRequest['appliedSortDirection'];
|
|
101
|
+
}) {}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* A union of the search product action types.
|
|
106
|
+
*/
|
|
107
|
+
export type DaffSearchProductCollectionActions =
|
|
108
|
+
| DaffSearchProductCollectionReplaceFilters
|
|
109
|
+
| DaffSearchProductCollectionApplyFilters
|
|
110
|
+
| DaffSearchProductCollectionRemoveFilters
|
|
111
|
+
| DaffSearchProductCollectionClearFilters
|
|
112
|
+
| DaffSearchProductCollectionToggleFilter
|
|
113
|
+
| DaffSearchProductCollectionChangePageSize
|
|
114
|
+
| DaffSearchProductCollectionChangeCurrentPage
|
|
115
|
+
| DaffSearchProductCollectionChangeSortingOption;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ModuleWithProviders,
|
|
3
|
+
NgModule,
|
|
4
|
+
} from '@angular/core';
|
|
5
|
+
import {
|
|
6
|
+
combineReducers,
|
|
7
|
+
StoreModule,
|
|
8
|
+
} from '@ngrx/store';
|
|
9
|
+
|
|
10
|
+
import {
|
|
11
|
+
DaffProductStateModule,
|
|
12
|
+
daffProductProvideExtraReducers,
|
|
13
|
+
} from '@daffodil/product/state';
|
|
14
|
+
import {
|
|
15
|
+
daffSearchProvideExtraReducers,
|
|
16
|
+
DaffSearchStateModule,
|
|
17
|
+
} from '@daffodil/search/state';
|
|
18
|
+
|
|
19
|
+
import {
|
|
20
|
+
DAFF_SEARCH_PRODUCT_STORE_FEATURE_KEY,
|
|
21
|
+
daffSearchProductReducers,
|
|
22
|
+
daffSearchProductCollectionSearchReducers,
|
|
23
|
+
daffSearchProductProductReducers,
|
|
24
|
+
} from './reducers/public_api';
|
|
25
|
+
|
|
26
|
+
@NgModule({
|
|
27
|
+
imports: [
|
|
28
|
+
StoreModule.forFeature(DAFF_SEARCH_PRODUCT_STORE_FEATURE_KEY, daffSearchProductReducers),
|
|
29
|
+
DaffProductStateModule,
|
|
30
|
+
DaffSearchStateModule,
|
|
31
|
+
],
|
|
32
|
+
providers: [
|
|
33
|
+
daffSearchProvideExtraReducers(combineReducers(daffSearchProductCollectionSearchReducers)),
|
|
34
|
+
daffProductProvideExtraReducers(combineReducers(daffSearchProductProductReducers)),
|
|
35
|
+
],
|
|
36
|
+
})
|
|
37
|
+
export class DaffSearchProductStateCoreModule {}
|
|
@@ -0,0 +1,363 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Inject,
|
|
3
|
+
Injectable,
|
|
4
|
+
} from '@angular/core';
|
|
5
|
+
import { TestBed } from '@angular/core/testing';
|
|
6
|
+
import { Actions } from '@ngrx/effects';
|
|
7
|
+
import { provideMockActions } from '@ngrx/effects/testing';
|
|
8
|
+
import { Action } from '@ngrx/store';
|
|
9
|
+
import {
|
|
10
|
+
Observable,
|
|
11
|
+
of,
|
|
12
|
+
} from 'rxjs';
|
|
13
|
+
import { TestScheduler } from 'rxjs/testing';
|
|
14
|
+
|
|
15
|
+
import {
|
|
16
|
+
DaffError,
|
|
17
|
+
DaffInheritableError,
|
|
18
|
+
DaffSortDirectionEnum,
|
|
19
|
+
daffFilterArrayToDict,
|
|
20
|
+
DaffFilterRequest,
|
|
21
|
+
daffFiltersToRequests,
|
|
22
|
+
DaffFilterToggleRequest,
|
|
23
|
+
} from '@daffodil/core';
|
|
24
|
+
import {
|
|
25
|
+
DaffCollectionChangeCurrentPage,
|
|
26
|
+
DaffCollectionChangePageSize,
|
|
27
|
+
DaffCollectionChangeSortingOption,
|
|
28
|
+
daffTransformErrorToStateError,
|
|
29
|
+
DaffCollectionApplyFilters,
|
|
30
|
+
DaffCollectionClearFilters,
|
|
31
|
+
DaffCollectionRemoveFilters,
|
|
32
|
+
DaffCollectionReplaceFilters,
|
|
33
|
+
DaffCollectionToggleFilter,
|
|
34
|
+
} from '@daffodil/core/state';
|
|
35
|
+
import { MockDaffCollectionFacade } from '@daffodil/core/state/testing';
|
|
36
|
+
import {
|
|
37
|
+
DaffCollectionMetadataFactory,
|
|
38
|
+
DaffFilterFactory,
|
|
39
|
+
DaffFilterRequestFactory,
|
|
40
|
+
DaffFilterToggleRequestFactory,
|
|
41
|
+
} from '@daffodil/core/testing';
|
|
42
|
+
import { DaffProductStateTestingModule } from '@daffodil/product/state/testing';
|
|
43
|
+
import { DaffSearchProductDriverResponse } from '@daffodil/search-product/driver';
|
|
44
|
+
import { DaffSearchProductDriverInterface } from '@daffodil/search-product/driver';
|
|
45
|
+
import { DaffSearchProductTestingDriverModule } from '@daffodil/search-product/driver/testing';
|
|
46
|
+
import { DaffSearchProductCollectionActionTypes } from '@daffodil/search-product/state';
|
|
47
|
+
import { DaffSearchProductStateTestingModule } from '@daffodil/search-product/state/testing';
|
|
48
|
+
import { DaffSearchDriver } from '@daffodil/search/driver';
|
|
49
|
+
import { DaffSearchTestingDriverModule } from '@daffodil/search/driver/testing';
|
|
50
|
+
import {
|
|
51
|
+
DaffSearchLoadFailure,
|
|
52
|
+
DaffSearchLoadSuccess,
|
|
53
|
+
} from '@daffodil/search/state';
|
|
54
|
+
import {
|
|
55
|
+
DaffSearchStateTestingModule,
|
|
56
|
+
MockDaffSearchFacade,
|
|
57
|
+
} from '@daffodil/search/state/testing';
|
|
58
|
+
|
|
59
|
+
import { DaffSearchProductCollectionEffects } from './collection.effects';
|
|
60
|
+
|
|
61
|
+
class MockError extends DaffInheritableError implements DaffError {
|
|
62
|
+
code = 'code';
|
|
63
|
+
|
|
64
|
+
constructor() {
|
|
65
|
+
super('message');
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
describe('@daffodil/product/state | DaffProductCollectionEffects', () => {
|
|
70
|
+
let actions$: Observable<any>;
|
|
71
|
+
let effects: DaffSearchProductCollectionEffects;
|
|
72
|
+
let collectionFacade: MockDaffCollectionFacade;
|
|
73
|
+
let facade: MockDaffSearchFacade;
|
|
74
|
+
let driverSpy: jasmine.Spy<DaffSearchProductDriverInterface['search']>;
|
|
75
|
+
|
|
76
|
+
let productCollectionMetadataFactory: DaffCollectionMetadataFactory;
|
|
77
|
+
let filterFactory: DaffFilterFactory;
|
|
78
|
+
let filterRequestFactory: DaffFilterRequestFactory;
|
|
79
|
+
let filterToggleRequestFactory: DaffFilterToggleRequestFactory;
|
|
80
|
+
let query: string;
|
|
81
|
+
|
|
82
|
+
const testDriverSuccess = (cb: () => Action) => {
|
|
83
|
+
describe('throttling the request', () => {
|
|
84
|
+
it('should call immediately, but throttle subsequent events within a specified timeframe, firing off the last event after throttle', () => {
|
|
85
|
+
const testScheduler = new TestScheduler((actual, expected) => {
|
|
86
|
+
expect(actual).toEqual(expected);
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
const stubCollectionMetadata = productCollectionMetadataFactory.create({
|
|
90
|
+
filters: daffFilterArrayToDict(filterFactory.createMany(3)),
|
|
91
|
+
});
|
|
92
|
+
const response: DaffSearchProductDriverResponse = {
|
|
93
|
+
metadata: stubCollectionMetadata,
|
|
94
|
+
collection: {},
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
driverSpy.and.returnValue(of(response));
|
|
98
|
+
|
|
99
|
+
collectionFacade.metadata$.next(stubCollectionMetadata);
|
|
100
|
+
|
|
101
|
+
testScheduler.run(({ hot, expectObservable }) => {
|
|
102
|
+
actions$ = hot('--a-a-a-a-a', { a: cb() });
|
|
103
|
+
|
|
104
|
+
const expectedMarble = '--a 299ms a';
|
|
105
|
+
const expectedValue = {
|
|
106
|
+
a: new DaffSearchLoadSuccess(response),
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
expectObservable(
|
|
110
|
+
effects.update$(300, testScheduler),
|
|
111
|
+
).toBe(expectedMarble, expectedValue);
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
expect(driverSpy).toHaveBeenCalledWith(query, {
|
|
115
|
+
appliedSortOption: stubCollectionMetadata.appliedSortOption,
|
|
116
|
+
appliedSortDirection: stubCollectionMetadata.appliedSortDirection,
|
|
117
|
+
currentPage: stubCollectionMetadata.currentPage,
|
|
118
|
+
pageSize: stubCollectionMetadata.pageSize,
|
|
119
|
+
filterRequests: daffFiltersToRequests(stubCollectionMetadata.filters),
|
|
120
|
+
});
|
|
121
|
+
});
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
describe('and the driver call succeeds', () => {
|
|
125
|
+
it('should call the driver with filter requests merged with state', () => {
|
|
126
|
+
const testScheduler = new TestScheduler((actual, expected) => {
|
|
127
|
+
expect(actual).toEqual(expected);
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
const stubCollectionMetadata = productCollectionMetadataFactory.create({
|
|
131
|
+
filters: daffFilterArrayToDict(filterFactory.createMany(3)),
|
|
132
|
+
});
|
|
133
|
+
const response: DaffSearchProductDriverResponse = {
|
|
134
|
+
metadata: stubCollectionMetadata,
|
|
135
|
+
collection: {},
|
|
136
|
+
};
|
|
137
|
+
|
|
138
|
+
driverSpy.and.returnValue(of(response));
|
|
139
|
+
|
|
140
|
+
collectionFacade.metadata$.next(stubCollectionMetadata);
|
|
141
|
+
|
|
142
|
+
testScheduler.run(({ hot, expectObservable }) => {
|
|
143
|
+
actions$ = hot('--a', { a: cb() });
|
|
144
|
+
|
|
145
|
+
const expectedMarble = '--a';
|
|
146
|
+
const expectedValue = {
|
|
147
|
+
a: new DaffSearchLoadSuccess(response),
|
|
148
|
+
};
|
|
149
|
+
|
|
150
|
+
expectObservable(
|
|
151
|
+
effects.update$(0, testScheduler),
|
|
152
|
+
).toBe(expectedMarble, expectedValue);
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
expect(driverSpy).toHaveBeenCalledWith(query, {
|
|
156
|
+
appliedSortOption: stubCollectionMetadata.appliedSortOption,
|
|
157
|
+
appliedSortDirection: stubCollectionMetadata.appliedSortDirection,
|
|
158
|
+
currentPage: stubCollectionMetadata.currentPage,
|
|
159
|
+
pageSize: stubCollectionMetadata.pageSize,
|
|
160
|
+
filterRequests: daffFiltersToRequests(stubCollectionMetadata.filters),
|
|
161
|
+
});
|
|
162
|
+
});
|
|
163
|
+
});
|
|
164
|
+
};
|
|
165
|
+
|
|
166
|
+
const testDriverFailure = (cb: () => Action) => {
|
|
167
|
+
describe('and the driver call fails', () => {
|
|
168
|
+
it('should emit DaffCategoryPageLoadFailure with the transformed error', () => {
|
|
169
|
+
const testScheduler = new TestScheduler((actual, expected) => {
|
|
170
|
+
expect(actual).toEqual(expected);
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
const stubCollectionMetadata = productCollectionMetadataFactory.create({
|
|
174
|
+
filters: daffFilterArrayToDict(filterFactory.createMany(3)),
|
|
175
|
+
});
|
|
176
|
+
|
|
177
|
+
collectionFacade.metadata$.next(stubCollectionMetadata);
|
|
178
|
+
|
|
179
|
+
testScheduler.run(({ hot, expectObservable }) => {
|
|
180
|
+
actions$ = hot('--a', { a: cb() });
|
|
181
|
+
|
|
182
|
+
const error = new MockError();
|
|
183
|
+
driverSpy.and.returnValue(hot('#', {}, error));
|
|
184
|
+
|
|
185
|
+
const expectedMarble = '--(a)';
|
|
186
|
+
const expectedValue = {
|
|
187
|
+
a: new DaffSearchLoadFailure(daffTransformErrorToStateError(error)),
|
|
188
|
+
};
|
|
189
|
+
|
|
190
|
+
expectObservable(
|
|
191
|
+
effects.update$(0, testScheduler),
|
|
192
|
+
).toBe(expectedMarble, expectedValue);
|
|
193
|
+
});
|
|
194
|
+
|
|
195
|
+
expect(driverSpy).toHaveBeenCalledWith(query, {
|
|
196
|
+
appliedSortOption: stubCollectionMetadata.appliedSortOption,
|
|
197
|
+
appliedSortDirection: stubCollectionMetadata.appliedSortDirection,
|
|
198
|
+
currentPage: stubCollectionMetadata.currentPage,
|
|
199
|
+
pageSize: stubCollectionMetadata.pageSize,
|
|
200
|
+
filterRequests: daffFiltersToRequests(stubCollectionMetadata.filters),
|
|
201
|
+
});
|
|
202
|
+
});
|
|
203
|
+
});
|
|
204
|
+
};
|
|
205
|
+
|
|
206
|
+
|
|
207
|
+
beforeEach(() => {
|
|
208
|
+
TestBed.configureTestingModule({
|
|
209
|
+
imports: [
|
|
210
|
+
DaffSearchStateTestingModule,
|
|
211
|
+
DaffProductStateTestingModule,
|
|
212
|
+
DaffSearchProductStateTestingModule,
|
|
213
|
+
DaffSearchTestingDriverModule.forRoot(),
|
|
214
|
+
DaffSearchProductTestingDriverModule.forRoot(),
|
|
215
|
+
],
|
|
216
|
+
providers: [
|
|
217
|
+
DaffSearchProductCollectionEffects,
|
|
218
|
+
provideMockActions(() => actions$),
|
|
219
|
+
],
|
|
220
|
+
});
|
|
221
|
+
|
|
222
|
+
collectionFacade = TestBed.inject(MockDaffCollectionFacade);
|
|
223
|
+
facade = TestBed.inject(MockDaffSearchFacade);
|
|
224
|
+
effects = TestBed.inject(DaffSearchProductCollectionEffects);
|
|
225
|
+
|
|
226
|
+
driverSpy = spyOn(TestBed.inject(DaffSearchDriver), 'search');
|
|
227
|
+
|
|
228
|
+
productCollectionMetadataFactory = TestBed.inject(DaffCollectionMetadataFactory);
|
|
229
|
+
filterFactory = TestBed.inject(DaffFilterFactory);
|
|
230
|
+
filterRequestFactory = TestBed.inject(DaffFilterRequestFactory);
|
|
231
|
+
filterToggleRequestFactory = TestBed.inject(DaffFilterToggleRequestFactory);
|
|
232
|
+
|
|
233
|
+
query = 'query';
|
|
234
|
+
facade.recent$.next([query]);
|
|
235
|
+
});
|
|
236
|
+
|
|
237
|
+
it('should be created', () => {
|
|
238
|
+
expect(effects).toBeTruthy();
|
|
239
|
+
});
|
|
240
|
+
|
|
241
|
+
describe('when replaceFilters is triggered', () => {
|
|
242
|
+
let filterRequest: DaffFilterRequest;
|
|
243
|
+
let action: DaffCollectionReplaceFilters;
|
|
244
|
+
|
|
245
|
+
beforeEach(() => {
|
|
246
|
+
filterRequest = filterRequestFactory.create();
|
|
247
|
+
action = {
|
|
248
|
+
type: DaffSearchProductCollectionActionTypes.SearchProductReplaceFiltersAction,
|
|
249
|
+
filters: [filterRequest],
|
|
250
|
+
};
|
|
251
|
+
});
|
|
252
|
+
|
|
253
|
+
testDriverSuccess(() => action);
|
|
254
|
+
});
|
|
255
|
+
|
|
256
|
+
describe('when applyFilters is triggered', () => {
|
|
257
|
+
let filterRequest: DaffFilterRequest;
|
|
258
|
+
let action: DaffCollectionApplyFilters;
|
|
259
|
+
|
|
260
|
+
|
|
261
|
+
beforeEach(() => {
|
|
262
|
+
filterRequest = filterRequestFactory.create();
|
|
263
|
+
action = {
|
|
264
|
+
type: DaffSearchProductCollectionActionTypes.SearchProductReplaceFiltersAction,
|
|
265
|
+
filters: [filterRequest],
|
|
266
|
+
};
|
|
267
|
+
});
|
|
268
|
+
|
|
269
|
+
testDriverSuccess(() => action);
|
|
270
|
+
});
|
|
271
|
+
|
|
272
|
+
describe('when clearFilters is triggered', () => {
|
|
273
|
+
let action: DaffCollectionClearFilters;
|
|
274
|
+
|
|
275
|
+
|
|
276
|
+
beforeEach(() => {
|
|
277
|
+
action = {
|
|
278
|
+
type: DaffSearchProductCollectionActionTypes.SearchProductClearFiltersAction,
|
|
279
|
+
};
|
|
280
|
+
});
|
|
281
|
+
|
|
282
|
+
testDriverSuccess(() => action);
|
|
283
|
+
});
|
|
284
|
+
|
|
285
|
+
describe('when removeFilters is triggered', () => {
|
|
286
|
+
let filterRequest: DaffFilterRequest;
|
|
287
|
+
let action: DaffCollectionRemoveFilters;
|
|
288
|
+
|
|
289
|
+
|
|
290
|
+
beforeEach(() => {
|
|
291
|
+
filterRequest = filterRequestFactory.create();
|
|
292
|
+
action = {
|
|
293
|
+
type: DaffSearchProductCollectionActionTypes.SearchProductRemoveFiltersAction,
|
|
294
|
+
filters: [filterRequest],
|
|
295
|
+
};;
|
|
296
|
+
});
|
|
297
|
+
|
|
298
|
+
testDriverSuccess(() => action);
|
|
299
|
+
});
|
|
300
|
+
|
|
301
|
+
describe('when toggleFilter is triggered', () => {
|
|
302
|
+
let toggleRequest: DaffFilterToggleRequest;
|
|
303
|
+
let action: DaffCollectionToggleFilter;
|
|
304
|
+
|
|
305
|
+
beforeEach(() => {
|
|
306
|
+
toggleRequest = filterToggleRequestFactory.create();
|
|
307
|
+
action = {
|
|
308
|
+
type: DaffSearchProductCollectionActionTypes.SearchProductReplaceFiltersAction,
|
|
309
|
+
filter: toggleRequest,
|
|
310
|
+
};
|
|
311
|
+
});
|
|
312
|
+
|
|
313
|
+
testDriverSuccess(() => action);
|
|
314
|
+
});
|
|
315
|
+
|
|
316
|
+
describe('when changePageSize is triggered', () => {
|
|
317
|
+
let toggleRequest: DaffFilterToggleRequest;
|
|
318
|
+
let action: DaffCollectionChangePageSize;
|
|
319
|
+
|
|
320
|
+
beforeEach(() => {
|
|
321
|
+
toggleRequest = filterToggleRequestFactory.create();
|
|
322
|
+
action = {
|
|
323
|
+
type: DaffSearchProductCollectionActionTypes.SearchProductReplaceFiltersAction,
|
|
324
|
+
pageSize: 5,
|
|
325
|
+
};
|
|
326
|
+
});
|
|
327
|
+
|
|
328
|
+
testDriverSuccess(() => action);
|
|
329
|
+
});
|
|
330
|
+
|
|
331
|
+
describe('when changeCurrentPage is triggered', () => {
|
|
332
|
+
let toggleRequest: DaffFilterToggleRequest;
|
|
333
|
+
let action: DaffCollectionChangeCurrentPage;
|
|
334
|
+
|
|
335
|
+
beforeEach(() => {
|
|
336
|
+
toggleRequest = filterToggleRequestFactory.create();
|
|
337
|
+
action = {
|
|
338
|
+
type: DaffSearchProductCollectionActionTypes.SearchProductReplaceFiltersAction,
|
|
339
|
+
currentPage: 5,
|
|
340
|
+
};
|
|
341
|
+
});
|
|
342
|
+
|
|
343
|
+
testDriverSuccess(() => action);
|
|
344
|
+
});
|
|
345
|
+
|
|
346
|
+
describe('when changeSorting is triggered', () => {
|
|
347
|
+
let toggleRequest: DaffFilterToggleRequest;
|
|
348
|
+
let action: DaffCollectionChangeSortingOption;
|
|
349
|
+
|
|
350
|
+
beforeEach(() => {
|
|
351
|
+
toggleRequest = filterToggleRequestFactory.create();
|
|
352
|
+
action = {
|
|
353
|
+
type: DaffSearchProductCollectionActionTypes.SearchProductReplaceFiltersAction,
|
|
354
|
+
sort: {
|
|
355
|
+
option: 'option',
|
|
356
|
+
direction: DaffSortDirectionEnum.Ascending,
|
|
357
|
+
},
|
|
358
|
+
};
|
|
359
|
+
});
|
|
360
|
+
|
|
361
|
+
testDriverSuccess(() => action);
|
|
362
|
+
});
|
|
363
|
+
});
|