diff --git a/docs/migration/4_0.md b/docs/migration/4_0.md index 216cd686241..f944d4a23a9 100644 --- a/docs/migration/4_0.md +++ b/docs/migration/4_0.md @@ -645,6 +645,10 @@ The display of the guest checkout button relies on the presence of the `forced` - `platformId` is now required constructor dependency. +### ProductListComponentService +- `ProductListComponentService` now also requires `ViewConfig`. +- The `defaultPageSize` property was removed. To modify default page size use `provideConfig({ view: { defaultPageSize: { diff --git a/projects/schematics/src/migrations/mechanism/rename-symbol/__snapshots__/rename-symbol_spec.ts.snap b/projects/schematics/src/migrations/mechanism/rename-symbol/__snapshots__/rename-symbol_spec.ts.snap index 54c7dbcdd79..6abb0d9df4f 100644 --- a/projects/schematics/src/migrations/mechanism/rename-symbol/__snapshots__/rename-symbol_spec.ts.snap +++ b/projects/schematics/src/migrations/mechanism/rename-symbol/__snapshots__/rename-symbol_spec.ts.snap @@ -26,3 +26,11 @@ import { Test1Component } from \\"@spartacus/storefront\\"; const array = [OtherComponentTest3, Test1Component, Test2Component]; " `; + +exports[`renamed symbols Should only rename node 1`] = ` +"import { Test2Component } from \\"@spartacus/core\\"; +import { OtherComponentTest4, Test1Component } from \\"@spartacus/storefront\\"; + +const array = [OtherComponentTest4, Test1Component, Test2Component]; +" +`; diff --git a/projects/schematics/src/migrations/mechanism/rename-symbol/rename-symbol.ts b/projects/schematics/src/migrations/mechanism/rename-symbol/rename-symbol.ts index 8131377edb5..3ace3055756 100644 --- a/projects/schematics/src/migrations/mechanism/rename-symbol/rename-symbol.ts +++ b/projects/schematics/src/migrations/mechanism/rename-symbol/rename-symbol.ts @@ -36,6 +36,11 @@ export function migrateRenamedSymbols( : importName; const oldAlias = namedImport.getAliasNode()?.getText(); + let importPath = renamedSymbol.previousImportPath; + + if (renamedSymbol.newImportPath) { + importPath = renamedSymbol.newImportPath; + } if (!oldAlias && renamedSymbol.newNode) { namedImport.renameAlias(newNodeName); @@ -48,7 +53,7 @@ export function migrateRenamedSymbols( alias: oldAlias, }, ], - moduleSpecifier: renamedSymbol.newImportPath, + moduleSpecifier: importPath, } as ImportDeclarationStructure); if ((id.getImportClause()?.getNamedImports()?.length || 0) > 1) { diff --git a/projects/schematics/src/migrations/mechanism/rename-symbol/rename-symbol_spec.ts b/projects/schematics/src/migrations/mechanism/rename-symbol/rename-symbol_spec.ts index 60d8772c10e..e21116781bb 100644 --- a/projects/schematics/src/migrations/mechanism/rename-symbol/rename-symbol_spec.ts +++ b/projects/schematics/src/migrations/mechanism/rename-symbol/rename-symbol_spec.ts @@ -32,6 +32,12 @@ import { Test2Component } from "@spartacus/core"; const array = [OtherComponent3, Test1Component, Test2Component];`; // ----------------------------------------------------------------------- +const fileWithRename = `import { OtherComponent4, Test1Component } from "@spartacus/storefront"; +import { Test2Component } from "@spartacus/core"; + +const array = [OtherComponent4, Test1Component, Test2Component];`; +// ----------------------------------------------------------------------- + describe('renamed symbols', () => { let host: TempScopedNodeJsSyncHost; let appTree = Tree.empty() as UnitTestTree; @@ -113,4 +119,13 @@ describe('renamed symbols', () => { expect(content).toMatchSnapshot(); }); }); + + it('Should only rename node', async () => { + writeFile(host, '/src/index.ts', fileWithRename); + + await runMigration(appTree, schematicRunner, MIGRATION_SCRIPT_NAME); + + const content = appTree.readContent('/src/index.ts'); + expect(content).toMatchSnapshot(); + }); }); diff --git a/projects/schematics/src/migrations/test/rename-symbol/rename-symbol.ts b/projects/schematics/src/migrations/test/rename-symbol/rename-symbol.ts index 325a791dff8..ff1c917e172 100644 --- a/projects/schematics/src/migrations/test/rename-symbol/rename-symbol.ts +++ b/projects/schematics/src/migrations/test/rename-symbol/rename-symbol.ts @@ -23,6 +23,12 @@ export const RENAMED_SYMBOLS_DATA: RenamedSymbol[] = [ newNode: 'OtherComponentTest3', newImportPath: '@spartacus/storefinder/components', }, + { + // 4) For name change + previousNode: 'OtherComponent4', + previousImportPath: '@spartacus/storefront', + newNode: 'OtherComponentTest4', + }, ]; export function migrate(): Rule { diff --git a/projects/schematics/src/shared/constants.ts b/projects/schematics/src/shared/constants.ts index 7d4604efbb7..8cd2a1ad700 100644 --- a/projects/schematics/src/shared/constants.ts +++ b/projects/schematics/src/shared/constants.ts @@ -807,6 +807,8 @@ export const ITEM = 'Item'; export const ORDER_ENTRY = 'OrderEntry'; export const ORDER_PROMOTIONS$ = 'orderPromotions$'; +export const DEFAULT_PAGE_SIZE = 'defaultPageSize'; + /***** Properties end *****/ /***** APIs start *****/ diff --git a/projects/schematics/src/shared/utils/file-utils.ts b/projects/schematics/src/shared/utils/file-utils.ts index 2b97e712be3..caf16b6b3c7 100644 --- a/projects/schematics/src/shared/utils/file-utils.ts +++ b/projects/schematics/src/shared/utils/file-utils.ts @@ -106,7 +106,7 @@ export interface RenamedSymbol { previousNode: string; previousImportPath: string; newNode?: string; - newImportPath: string; + newImportPath?: string; } export function getTsSourceFile(tree: Tree, path: string): ts.SourceFile { diff --git a/projects/storefrontapp-e2e-cypress/cypress/helpers/coupons/my-coupons.ts b/projects/storefrontapp-e2e-cypress/cypress/helpers/coupons/my-coupons.ts index 7a6364cc473..8e4923e3820 100644 --- a/projects/storefrontapp-e2e-cypress/cypress/helpers/coupons/my-coupons.ts +++ b/projects/storefrontapp-e2e-cypress/cypress/helpers/coupons/my-coupons.ts @@ -81,7 +81,7 @@ export function verifyMyCoupons() { verifyCouponsClaiming(); verifyEnableDisableNotification(); verifyReadMore(); - verifyFindProduct(CouponWithOpenCatalog, 10); + verifyFindProduct(CouponWithOpenCatalog, 12); goMyCoupon(); verifyFindProduct(CouponWithProductCategory, 4); goMyCoupon(); diff --git a/projects/storefrontapp-e2e-cypress/cypress/helpers/data-configuration.ts b/projects/storefrontapp-e2e-cypress/cypress/helpers/data-configuration.ts index a7ea4831141..6efb06295d3 100644 --- a/projects/storefrontapp-e2e-cypress/cypress/helpers/data-configuration.ts +++ b/projects/storefrontapp-e2e-cypress/cypress/helpers/data-configuration.ts @@ -1,5 +1,5 @@ export const PRODUCT_LISTING = { - PRODUCTS_PER_PAGE: 10, + PRODUCTS_PER_PAGE: 12, SORTING_TYPES: { BY_TOP_RATED: 'Top Rated', BY_RELEVANCE: 'Relevance', diff --git a/projects/storefrontapp-e2e-cypress/cypress/helpers/infinite-scroll.ts b/projects/storefrontapp-e2e-cypress/cypress/helpers/infinite-scroll.ts index 5718fe4d360..67cbcb4f8f4 100644 --- a/projects/storefrontapp-e2e-cypress/cypress/helpers/infinite-scroll.ts +++ b/projects/storefrontapp-e2e-cypress/cypress/helpers/infinite-scroll.ts @@ -2,8 +2,8 @@ import { PRODUCT_LISTING } from './data-configuration'; import { clickFacet, searchUrlPrefix } from './product-search'; const scrollDuration = 5000; -const defaultNumberOfProducts = 10; -let defaultProductLimit = 10; +const defaultNumberOfProducts = 12; +let defaultProductLimit = 12; const defaultQueryName = `query_relevance`; const defaultQueryAlias = `@${defaultQueryName}`; diff --git a/projects/storefrontapp-e2e-cypress/cypress/integration/regression/infinite-scroll.e2e-spec.ts b/projects/storefrontapp-e2e-cypress/cypress/integration/regression/infinite-scroll.e2e-spec.ts index 0f73a8e3e46..ede7568d7fe 100644 --- a/projects/storefrontapp-e2e-cypress/cypress/integration/regression/infinite-scroll.e2e-spec.ts +++ b/projects/storefrontapp-e2e-cypress/cypress/integration/regression/infinite-scroll.e2e-spec.ts @@ -65,20 +65,19 @@ describe('Infinite scroll', () => { isPaginationNotVisible(); scrollToFooter(totalResults, true); - backToTopIsVisible(); + backToTopIsVisible(true); }); }); - it("should enable infinite scroll and display 'Show more' button after 15th product", () => { - configScroll(true, 15, false); + it("should enable infinite scroll and display 'Show more' button after 12th product", () => { + configScroll(true, 12, false); cy.visit(testUrl); cy.wait(defaultQueryAlias).then((waitXHR) => { const totalResults = waitXHR.response.body.pagination.totalResults; isPaginationNotVisible(); - - backtoTopIsNotVisible(); - scrollToFooter(totalResults, false, 15); + backToTopIsVisible(); + scrollToFooter(totalResults, true, 12); backToTopIsVisible(true); }); }); diff --git a/projects/storefrontlib/src/cms-components/product/config/default-scroll-config.ts b/projects/storefrontlib/src/cms-components/product/config/default-view-config.ts similarity index 72% rename from projects/storefrontlib/src/cms-components/product/config/default-scroll-config.ts rename to projects/storefrontlib/src/cms-components/product/config/default-view-config.ts index 6318372de3c..388a7851749 100644 --- a/projects/storefrontlib/src/cms-components/product/config/default-scroll-config.ts +++ b/projects/storefrontlib/src/cms-components/product/config/default-view-config.ts @@ -1,7 +1,8 @@ import { ViewConfig } from '../../../shared/config/view-config'; -export const defaultScrollConfig: ViewConfig = { +export const defaultViewConfig: ViewConfig = { view: { + defaultPageSize: 12, infiniteScroll: { active: false, productLimit: 0, diff --git a/projects/storefrontlib/src/cms-components/product/index.ts b/projects/storefrontlib/src/cms-components/product/index.ts index 9640e093ced..f94371322bb 100644 --- a/projects/storefrontlib/src/cms-components/product/index.ts +++ b/projects/storefrontlib/src/cms-components/product/index.ts @@ -1,5 +1,5 @@ export * from './carousel/index'; -export * from './config/default-scroll-config'; +export * from './config/default-view-config'; export * from './current-product.service'; export * from './product-images/product-images.component'; export * from './product-images/product-images.module'; diff --git a/projects/storefrontlib/src/cms-components/product/product-list/container/product-list-component.service.spec.ts b/projects/storefrontlib/src/cms-components/product/product-list/container/product-list-component.service.spec.ts index 03f73e66f0c..a8679cbf29d 100644 --- a/projects/storefrontlib/src/cms-components/product/product-list/container/product-list-component.service.spec.ts +++ b/projects/storefrontlib/src/cms-components/product/product-list/container/product-list-component.service.spec.ts @@ -6,8 +6,10 @@ import { LanguageService, ProductSearchPage, ProductSearchService, + provideDefaultConfig, RoutingService, } from '@spartacus/core'; +import { defaultViewConfig, ViewConfig } from '@spartacus/storefront'; import { BehaviorSubject, of, Subscription } from 'rxjs'; import { ProductListComponentService } from './product-list-component.service'; @@ -80,6 +82,7 @@ describe('ProductListComponentService', () => { { provide: ProductSearchService, useClass: MockProductSearchService }, { provide: CurrencyService, useClass: MockCurrencyService }, { provide: LanguageService, useClass: MockLanguageService }, + provideDefaultConfig(defaultViewConfig), ], }); @@ -135,7 +138,7 @@ describe('ProductListComponentService', () => { })); describe('should perform search on change of routing', () => { - it('with default "pageSize" 10', fakeAsync(() => { + it('with default "pageSize" 12', fakeAsync(() => { const subscription: Subscription = service.model$.subscribe(); tick(); @@ -143,7 +146,7 @@ describe('ProductListComponentService', () => { subscription.unsubscribe(); expect(productSearchService.search).toHaveBeenCalledWith(undefined, { - pageSize: 10, + pageSize: 12, }); })); diff --git a/projects/storefrontlib/src/cms-components/product/product-list/container/product-list-component.service.ts b/projects/storefrontlib/src/cms-components/product/product-list/container/product-list-component.service.ts index d99424b17ec..0cd69a452ba 100644 --- a/projects/storefrontlib/src/cms-components/product/product-list/container/product-list-component.service.ts +++ b/projects/storefrontlib/src/cms-components/product/product-list/container/product-list-component.service.ts @@ -19,6 +19,7 @@ import { tap, } from 'rxjs/operators'; import { ProductListRouteParams, SearchCriteria } from './product-list.model'; +import { ViewConfig } from '../../../../shared/config/view-config'; /** * The `ProductListComponentService` is used to search products. The service is used @@ -30,9 +31,6 @@ import { ProductListRouteParams, SearchCriteria } from './product-list.model'; */ @Injectable({ providedIn: 'root' }) export class ProductListComponentService { - // TODO: make it configurable - protected defaultPageSize = 10; - protected readonly RELEVANCE_ALLCATEGORIES = ':relevance:allCategories:'; constructor( @@ -41,7 +39,8 @@ export class ProductListComponentService { protected activatedRoute: ActivatedRoute, protected currencyService: CurrencyService, protected languageService: LanguageService, - protected router: Router + protected router: Router, + protected config: ViewConfig ) {} /** @@ -109,7 +108,7 @@ export class ProductListComponentService { ): SearchCriteria { return { query: queryParams.query || this.getQueryFromRouteParams(routeParams), - pageSize: queryParams.pageSize || this.defaultPageSize, + pageSize: queryParams.pageSize || this.config.view?.defaultPageSize, currentPage: queryParams.currentPage, sortCode: queryParams.sortCode, }; diff --git a/projects/storefrontlib/src/cms-components/product/product-list/product-list.module.ts b/projects/storefrontlib/src/cms-components/product/product-list/product-list.module.ts index d01044ee21d..1c2198ce892 100644 --- a/projects/storefrontlib/src/cms-components/product/product-list/product-list.module.ts +++ b/projects/storefrontlib/src/cms-components/product/product-list/product-list.module.ts @@ -20,7 +20,7 @@ import { } from '../../../shared/index'; import { AddToCartModule } from '../../cart/index'; import { IconModule } from '../../misc/icon/index'; -import { defaultScrollConfig } from '../config/default-scroll-config'; +import { defaultViewConfig } from '../config/default-view-config'; import { ProductListComponent } from './container/product-list.component'; import { ProductScrollComponent } from './container/product-scroll/product-scroll.component'; import { ProductGridItemComponent } from './product-grid-item/product-grid-item.component'; @@ -45,7 +45,7 @@ import { ProductViewComponent } from './product-view/product-view.component'; OutletModule, ], providers: [ - provideDefaultConfig(defaultScrollConfig), + provideDefaultConfig(defaultViewConfig), provideDefaultConfig({ cmsComponents: { CMSProductListComponent: { diff --git a/projects/storefrontlib/src/shared/config/view-config.ts b/projects/storefrontlib/src/shared/config/view-config.ts index 60c240eac27..919fd570f3e 100644 --- a/projects/storefrontlib/src/shared/config/view-config.ts +++ b/projects/storefrontlib/src/shared/config/view-config.ts @@ -10,6 +10,7 @@ export abstract class ViewConfig { /** * Configurations related to the view of the application */ + defaultPageSize?: number; infiniteScroll?: { active?: boolean; productLimit?: number;