How to use the @spartacus/core.PageContext function in @spartacus/core

To help you get started, we’ve selected a few @spartacus/core examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github SAP / cloud-commerce-spartacus-storefront / projects / cds / src / merchandising / facade / cds-merchandising-user-context.service.spec.ts View on Github external
it('should return a valid MerchandisingUserContext object, if there are no facets, but a categoryCode exists, and the page is a CATEGORY_PAGE', () => {
    const expectedUserContext: MerchandisingUserContext = {
      category: '574',
      facets: undefined,
    };

    spyOn(routingService, 'getPageContext').and.returnValue(
      of(new PageContext('574', PageType.CATEGORY_PAGE))
    );
    spyOn(productSearchService, 'getResults').and.returnValue(
      of(emptyPageSearchResults)
    );
    spyOn(converterService, 'pipeable')
      .withArgs(MERCHANDISING_FACET_NORMALIZER)
      .and.returnValue(map(() => undefined))
      .withArgs(MERCHANDISING_FACET_TO_QUERYPARAM_NORMALIZER)
      .and.returnValue(map(() => undefined));

    let merchandisingUserContext: MerchandisingUserContext;
    cdsMerchandisingUserContextService
      .getUserContext()
      .subscribe(userContext => (merchandisingUserContext = userContext))
      .unsubscribe();
    expect(merchandisingUserContext).toEqual(expectedUserContext);
github SAP / cloud-commerce-spartacus-storefront / projects / cds / src / merchandising / facade / cds-merchandising-user-context.service.spec.ts View on Github external
it('should return a valid MerchandisingUserContext object, if there are no facets, but a productCode exists, and the page is a PRODUCT_PAGE', () => {
    const expectedUserContext: MerchandisingUserContext = {
      products: ['12345'],
    };

    spyOn(routingService, 'getPageContext').and.returnValue(
      of(new PageContext('12345', PageType.PRODUCT_PAGE))
    );
    spyOn(productSearchService, 'getResults').and.returnValue(
      of(emptyPageSearchResults)
    );

    let merchandisingUserContext: MerchandisingUserContext;
    cdsMerchandisingUserContextService
      .getUserContext()
      .subscribe(userContext => (merchandisingUserContext = userContext))
      .unsubscribe();
    expect(merchandisingUserContext).toEqual(expectedUserContext);
  });
github SAP / cloud-commerce-spartacus-storefront / projects / cds / src / merchandising / facade / cds-merchandising-user-context.service.spec.ts View on Github external
const expectedUserContext: MerchandisingUserContext = {
      category: 'brand123',
      facets: undefined,
    };

    spyOn(converterService, 'pipeable')
      .withArgs(MERCHANDISING_FACET_NORMALIZER)
      .and.returnValue(map(() => undefined))
      .withArgs(MERCHANDISING_FACET_TO_QUERYPARAM_NORMALIZER)
      .and.returnValue(map(() => undefined));

    spyOn(productSearchService, 'getResults').and.returnValue(
      of(emptyPageSearchResults)
    );
    spyOn(routingService, 'getPageContext').and.returnValue(
      of(new PageContext('brand123', PageType.CATEGORY_PAGE))
    );

    let merchandisingUserContext: MerchandisingUserContext;
    cdsMerchandisingUserContextService
      .getUserContext()
      .subscribe(userContext => (merchandisingUserContext = userContext))
      .unsubscribe();
    expect(merchandisingUserContext).toEqual(expectedUserContext);
  });
github SAP / cloud-commerce-spartacus-storefront / projects / cds / src / merchandising / facade / cds-merchandising-user-context.service.spec.ts View on Github external
const merchandisingFacets = [
      {
        code: pageSearchResults.breadcrumbs[0].facetCode,
        value: pageSearchResults.breadcrumbs[0].facetValueCode,
      },
      {
        code: pageSearchResults.breadcrumbs[1].facetCode,
        value: pageSearchResults.breadcrumbs[1].facetValueCode,
      },
    ];

    const queryParams = `${merchandisingFacets[0].code}:${merchandisingFacets[0].value}:${merchandisingFacets[1].code}:${merchandisingFacets[1].value}`;

    spyOn(routingService, 'getPageContext').and.returnValue(
      of(new PageContext('homepage', PageType.CONTENT_PAGE))
    );
    spyOn(productSearchService, 'getResults').and.returnValue(
      of(pageSearchResults)
    );
    spyOn(converterService, 'pipeable')
      .withArgs(MERCHANDISING_FACET_NORMALIZER)
      .and.returnValue(map(() => merchandisingFacets))
      .withArgs(MERCHANDISING_FACET_TO_QUERYPARAM_NORMALIZER)
      .and.returnValue(map(() => queryParams));

    let merchandisingUserContext: MerchandisingUserContext;
    cdsMerchandisingUserContextService
      .getUserContext()
      .subscribe(userContext => (merchandisingUserContext = userContext))
      .unsubscribe();
    expect(merchandisingUserContext).toEqual(undefined);