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

test: CXSPA-8759 - fix test isolation issue #19478

Open
wants to merge 6 commits into
base: develop
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ChangeDetectionStrategy, Component, Input, Type } from '@angular/core';
import { Component, Input, Type } from '@angular/core';
import {
ComponentFixture,
TestBed,
Expand Down Expand Up @@ -47,19 +47,18 @@ import { ConfiguratorAddToCartButtonComponent } from './configurator-add-to-cart
import createSpy = jasmine.createSpy;

const CART_ENTRY_KEY = '001+1';
const ORDER_ENTRY_KEY = '001+1';
const PRODUCT_ENTRY_KEY = '001+1';
const QUOTE_CODE = '003';
const ORDER_ENTRY_KEY = '002+1';
const PRODUCT_ENTRY_KEY = '003+1';
const QUOTE_CODE = '004';
const QUOTE_ENTRY_KEY = QUOTE_CODE + '+1';
const QUANTITY = 99;
const QUANTITY_CHANGED = 7;

const configuratorType = ConfiguratorType.VARIANT;

const ROUTE_CONFIGURATION = 'configureCPQCONFIGURATOR';
const ROUTE_OVERVIEW = 'configureOverviewCPQCONFIGURATOR';

const mockProductConfiguration = ConfigurationTestData.productConfiguration;

const mockProductConfigurationWithoutPriceSummary =
ConfigurationTestData.productConfigurationWithConflicts;

Expand All @@ -81,14 +80,9 @@ const navParamsOverview: any = {
};

const queryParams: any = {
queryParams: { productCode: mockProductConfiguration.productCode },
};

const mockOwner = mockProductConfiguration.owner;
const mockRouterData: ConfiguratorRouter.Data = {
pageType: ConfiguratorRouter.PageType.CONFIGURATION,
isOwnerCartEntry: false,
owner: mockOwner,
queryParams: {
productCode: ConfigurationTestData.PRODUCT_CODE,
},
};

const mockOrder: Order = {
Expand Down Expand Up @@ -123,6 +117,10 @@ let productConfigurationObservable: Observable<any>;
let pendingChangesObservable: Observable<any>;
let elementMock: { style: any };
let orderEntryObservable: Observable<any>;
let mockProductConfiguration: Configurator.Configuration;
let mockOwner: CommonConfigurator.Owner;
let mockRouterData: ConfiguratorRouter.Data;
let mockRouterState: any;

function initialize() {
routerStateObservable = of(mockRouterState);
Expand All @@ -135,6 +133,37 @@ function initialize() {
fixture.detectChanges();
}

function initTestData() {
mockProductConfiguration = structuredClone(
ConfigurationTestData.productConfiguration
);
mockOwner = structuredClone(ConfigurationTestData.productConfiguration.owner);
mockProductConfiguration.owner = mockOwner;
mockRouterData = {
pageType: ConfiguratorRouter.PageType.CONFIGURATION,
isOwnerCartEntry: false,
owner: mockOwner,
displayOnly: false,
};
mockRouterState = {
state: {
semanticRoute: ROUTE_CONFIGURATION,
params: {
entityKey: ConfigurationTestData.PRODUCT_CODE,
ownerType: CommonConfigurator.OwnerType.PRODUCT,
},
queryParams: {},
},
};

cart.quoteCode = QUOTE_CODE;
elementMock = {
style: {
position: '',
},
};
}

class MockGlobalMessageService {
add(): void {}
}
Expand Down Expand Up @@ -365,18 +394,6 @@ function performUpdateOnOV() {
component.onAddToCart(mockProductConfiguration, mockRouterData);
}

const ROUTE_CONFIGURATION = 'configureCPQCONFIGURATOR';
const mockRouterState: any = {
state: {
semanticRoute: ROUTE_CONFIGURATION,
params: {
entityKey: ConfigurationTestData.PRODUCT_CODE,
ownerType: CommonConfigurator.OwnerType.PRODUCT,
},
queryParams: {},
},
};

class MockRoutingService {
getRouterState(): Observable<RouterState> {
return routerStateObservable;
Expand Down Expand Up @@ -471,21 +488,11 @@ describe('ConfiguratorAddToCartButtonComponent', () => {
},
{ provide: ActiveCartFacade, useClass: MockActiveCartFacade },
],
})
.overrideComponent(ConfiguratorAddToCartButtonComponent, {
set: {
changeDetection: ChangeDetectionStrategy.Default,
},
})
.compileComponents();
}).compileComponents();
}));

beforeEach(() => {
elementMock = {
style: {
position: '',
},
};
initTestData();
pendingChangesObservable = of(false);
initialize();
routingService = TestBed.inject(RoutingService);
Expand Down Expand Up @@ -516,11 +523,6 @@ describe('ConfiguratorAddToCartButtonComponent', () => {
spyOn(keyboardFocusService, 'clear').and.callThrough();
});

afterEach(() => {
fixture.destroy();
mockRouterData.displayOnly = false;
});

it('should create cart-btn-container', () => {
initialize();
expect(component).toBeTruthy();
Expand Down Expand Up @@ -1109,6 +1111,7 @@ describe('ConfiguratorAddToCartButtonComponent', () => {
});

describe('isQuoteCartActive', () => {
cart.quoteCode = QUOTE_CODE;
it('should return `true` in case quote cart is active', () => {
component['isQuoteCartActive']()
.subscribe((isQuoteCartActive) => {
Expand All @@ -1124,7 +1127,6 @@ describe('ConfiguratorAddToCartButtonComponent', () => {
expect(isQuoteCartActive).toBe(false);
})
.unsubscribe();
cart.quoteCode = QUOTE_CODE;
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ import { ConfiguratorGroupMenuService } from './configurator-group-menu.componen

let mockGroupVisited = false;
let mockDirection = DirectionMode.LTR;
const mockProductConfiguration: Configurator.Configuration =
productConfiguration;
let mockProductConfiguration: Configurator.Configuration =
structuredClone(productConfiguration);

class MockRoutingService {
getRouterState(): Observable<RouterState> {
Expand Down Expand Up @@ -233,15 +233,16 @@ let hamburgerMenuService: HamburgerMenuService;
let htmlElem: HTMLElement;
let configuratorUtils: CommonConfiguratorUtilsService;
let configGroupMenuService: ConfiguratorGroupMenuService;
let routerStateObservable: Observable<RouterState>;
let groupVisitedObservable: Observable<boolean>;
let productConfigurationObservable: Observable<Configurator.Configuration>;
let routerStateObservable: Observable<RouterState> = NEVER;
let groupVisitedObservable: Observable<boolean> = NEVER;
let productConfigurationObservable: Observable<Configurator.Configuration> =
NEVER;
let isConflictGroupType: boolean;
let directionService: DirectionService;
let direction: DirectionMode;
let configUtils: ConfiguratorStorefrontUtilsService;
let configExpertModeService: ConfiguratorExpertModeService;
let breakpointObservable: Observable<boolean>;
let breakpointObservable: Observable<boolean> = NEVER;

function initialize() {
groupVisitedObservable = of(mockGroupVisited);
Expand Down Expand Up @@ -296,7 +297,7 @@ describe('ConfiguratorGroupMenuComponent', () => {
useClass: MockFeatureConfigService,
},
],
});
}).compileComponents();
}));

beforeEach(() => {
Expand Down
Loading