Skip to content

Commit

Permalink
Merge branch 'develop' into feature/renovate_update_actions
Browse files Browse the repository at this point in the history
  • Loading branch information
giancorderoortiz authored Nov 4, 2024
2 parents f0031d7 + 79c60bf commit f840a7d
Show file tree
Hide file tree
Showing 23 changed files with 520 additions and 133 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,18 +36,17 @@ class MockAbstractOrderContext {
class MockUrlPipe implements PipeTransform {
transform(): any {}
}

const mockRouterState: any = {
const mockBaseRouterState: any = {
state: {
semanticRoute: 'home',
},
};

let routerState: RouterState;
let mockRouterState: RouterState;

class MockRoutingService {
getRouterState(): Observable<RouterState> {
return of(routerState);
return of(mockRouterState);
}
}

Expand All @@ -59,8 +58,6 @@ describe('ConfigureCartEntryComponent', () => {
const orderOrCartEntry: OrderEntry = {};

function configureTestingModule(): TestBed {
routerState = mockRouterState;

return TestBed.configureTestingModule({
imports: [I18nTestingModule, RouterTestingModule, RouterModule],
declarations: [ConfigureCartEntryComponent, MockUrlPipe],
Expand All @@ -74,6 +71,7 @@ describe('ConfigureCartEntryComponent', () => {
}

function assignTestArtifacts(): void {
mockRouterState = structuredClone(mockBaseRouterState);
fixture = TestBed.createComponent(ConfigureCartEntryComponent);
component = fixture.componentInstance;
htmlElem = fixture.nativeElement;
Expand Down Expand Up @@ -136,6 +134,10 @@ describe('ConfigureCartEntryComponent', () => {
});

describe('getDisplayOnly', () => {
beforeEach(() => {
configureTestingModule().compileComponents();
assignTestArtifacts();
});
it('should return true in case readOnly is true', () => {
component.readOnly = true;
expect(component.getDisplayOnly()).toBe(true);
Expand Down Expand Up @@ -173,6 +175,10 @@ describe('ConfigureCartEntryComponent', () => {
});

describe('isInCheckout', () => {
beforeEach(() => {
configureTestingModule().compileComponents();
assignTestArtifacts();
});
it('should return false in case the url does not contain checkoutReviewOrder', (done) => {
component['isInCheckout']()
.pipe(take(1), delay(0))
Expand Down Expand Up @@ -217,6 +223,7 @@ describe('ConfigureCartEntryComponent', () => {

describe('getOwnerType', () => {
it('should find correct default owner type', () => {
component.cartEntry.orderCode = undefined;
expect(component.getOwnerType()).toBe(
CommonConfigurator.OwnerType.CART_ENTRY
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ const mockProductNotConfigurable: Product = {
configurable: false,
};

const testProduct = { ...mockProduct };
let testProduct: Product;

class MockCurrentProductService implements Partial<CurrentProductService> {
getProduct(): Observable<Product> {
Expand Down Expand Up @@ -173,6 +173,7 @@ function setupWithCurrentProductService(
fixture = TestBed.createComponent(ConfigureProductComponent);
component = fixture.componentInstance;
htmlElem = fixture.nativeElement;
testProduct = structuredClone(mockProduct);
}

describe('ConfigureProductComponent', () => {
Expand Down Expand Up @@ -356,6 +357,10 @@ describe('ConfigureProductComponent', () => {
});

describe('isReadOnlyBaseProduct', () => {
beforeEach(() => {
testProduct = structuredClone(mockProduct);
setupWithCurrentProductService(true);
});
it('should return `false` in case configurator type is CPQCONFIGURATOR', () => {
expect(component.isReadOnlyBaseProduct(testProduct)).toEqual(false);
});
Expand All @@ -380,6 +385,10 @@ describe('ConfigureProductComponent', () => {
});

describe('isBaseProduct', () => {
beforeEach(() => {
testProduct = structuredClone(mockProduct);
setupWithCurrentProductService(true);
});
it('should return `false` in case base product and product code are not equal', () => {
testProduct.baseProduct = 'BASE_PRODUCT';
expect(component['isBaseProduct'](testProduct)).toEqual(false);
Expand All @@ -405,10 +414,6 @@ describe('ConfigureProductComponent', () => {
expect(component['isConfiguratorTypeReadOnly'](undefined)).toBe(false);
});

it('should return false in case configurator type is null', () => {
expect(component['isConfiguratorTypeReadOnly'](null)).toBe(false);
});

it('should return false in case configurator type is empty string', () => {
expect(component['isConfiguratorTypeReadOnly']('')).toBe(false);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ describe('ConfigAttributeHeaderComponent', () => {

let htmlElem: HTMLElement;

const TestConfiguratorUISettings: ConfiguratorUISettingsConfig = {
const testConfiguratorUISettings: ConfiguratorUISettingsConfig = {
productConfigurator: {
enableNavigationToConflict: false,
descriptions: {
Expand Down Expand Up @@ -148,7 +148,7 @@ describe('ConfigAttributeHeaderComponent', () => {
},
{
provide: ConfiguratorUISettingsConfig,
useValue: TestConfiguratorUISettings,
useValue: structuredClone(testConfiguratorUISettings),
},

{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,10 +171,15 @@ describe('ConfiguratorAttributeSingleSelectionBaseComponent', () => {
});

describe('onSelectAdditionalValue', () => {
const configFormUpdateEvent: ConfigFormUpdateEvent = {
ownerKey: ownerKey,
changedAttribute: { name: 'Attr' },
};
let configFormUpdateEvent: ConfigFormUpdateEvent;

beforeEach(() => {
configFormUpdateEvent = {
ownerKey: ownerKey,
changedAttribute: { name: 'Attr' },
};
});

it('should not call emit of selectionChange in case no user input is present', () => {
spyOn(
component['configuratorCommonsService'],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,9 @@ describe('ConfigAttributeCheckBoxComponent', () => {

describe('rendering description at value level', () => {
it('should not render description in case description not present on model', () => {
(component.attribute.values ?? [{ description: '' }])[0].description =
undefined;
fixture.detectChanges();
CommonConfiguratorTestUtilsService.expectElementNotPresent(
expect,
htmlElem,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ class MockConfiguratorAttributePriceChangeService {
}
}

const ATTRIBUTE_VALUES_MISSING = 'attribute values are missing';

describe('ConfiguratorAttributeDropDownComponent', () => {
let component: ConfiguratorAttributeDropDownComponent;
let htmlElem: HTMLElement;
Expand All @@ -116,17 +118,6 @@ describe('ConfiguratorAttributeDropDownComponent', () => {
const groupId = 'theGroupId';
const selectedValue = 'selectedValue';

const value1 = createValue(
Configurator.RetractValueCode,
'Please select a value',
true,
true
);
const value2 = createValue('2', 'value_1_1', false);
const value3 = createValue('3', 'value_1_2', false);

const values: Configurator.Value[] = [value1, value2, value3];

function createComponentWithData(
isCartEntryOrGroupVisited: boolean = true
): ConfiguratorAttributeDropDownComponent {
Expand All @@ -135,6 +126,16 @@ describe('ConfiguratorAttributeDropDownComponent', () => {
fixture = TestBed.createComponent(ConfiguratorAttributeDropDownComponent);
htmlElem = fixture.nativeElement;
component = fixture.componentInstance;
const value1 = createValue(
Configurator.RetractValueCode,
'Please select a value',
true,
true
);
const value2 = createValue('2', 'value_1_1', false);
const value3 = createValue('3', 'value_1_2', false);
const values: Configurator.Value[] = [value1, value2, value3];

component.attribute = {
key: name,
name: name,
Expand Down Expand Up @@ -326,8 +327,15 @@ describe('ConfiguratorAttributeDropDownComponent', () => {
formattedValue: '500.00$',
value: 500,
};
value1.selected = false;
value2.selected = true;

const attributeValues = component.attribute.values;
if (attributeValues) {
attributeValues[0].selected = false;
attributeValues[1].selected = true;
} else {
fail(ATTRIBUTE_VALUES_MISSING);
}

fixture.detectChanges();

CommonConfiguratorTestUtilsService.expectElementPresent(
Expand All @@ -350,13 +358,16 @@ describe('ConfiguratorAttributeDropDownComponent', () => {
formattedValue: '500.00$',
value: 500,
};

value2.selected = true;
value2.valuePrice = {
currencyIso: '$',
formattedValue: '$100.00',
value: 100,
};
if (component.attribute.values) {
component.attribute.values[1].selected = true;
component.attribute.values[1].valuePrice = {
currencyIso: '$',
formattedValue: '$100.00',
value: 100,
};
} else {
fail(ATTRIBUTE_VALUES_MISSING);
}

fixture.detectChanges();

Expand Down Expand Up @@ -391,11 +402,15 @@ describe('ConfiguratorAttributeDropDownComponent', () => {
});

it('should display price formula', () => {
value1.valuePrice = {
currencyIso: '$',
formattedValue: '$100.00',
value: 100,
};
if (component.attribute.values) {
component.attribute.values[0].valuePrice = {
currencyIso: '$',
formattedValue: '$100.00',
value: 100,
};
} else {
fail(ATTRIBUTE_VALUES_MISSING);
}

fixture.detectChanges();

Expand Down Expand Up @@ -479,10 +494,16 @@ describe('ConfiguratorAttributeDropDownComponent', () => {
});

it("should contain option elements with 'aria-label' attribute for value without price that defines an accessible name to label the current element", () => {
value2.valuePrice = undefined;
value1.selected = false;
value2.selected = true;
value2.valuePrice = undefined;
let value2;
if (component.attribute.values) {
value2 = component.attribute.values[1];
value2.valuePrice = undefined;
component.attribute.values[0].selected = false;
value2.selected = true;
value2.valuePrice = undefined;
} else {
fail(ATTRIBUTE_VALUES_MISSING);
}
fixture.detectChanges();
CommonConfiguratorTestUtilsService.expectElementContainsA11y(
expect,
Expand All @@ -494,17 +515,24 @@ describe('ConfiguratorAttributeDropDownComponent', () => {
'configurator.a11y.selectedValueOfAttributeFull attribute:' +
component.attribute.label +
' value:' +
value2.valueDisplay,
value2.valueDisplay
value2?.valueDisplay,
value2?.valueDisplay
);
});

it("should contain option elements with 'aria-label' attribute for value with price that defines an accessible name to label the current element", () => {
value2.valuePrice = {
currencyIso: '$',
formattedValue: '$100.00',
value: 100,
};
let value2;
if (component.attribute.values) {
value2 = component.attribute.values[1];
value2.selected = true;
value2.valuePrice = {
currencyIso: '$',
formattedValue: '$100.00',
value: 100,
};
} else {
fail(ATTRIBUTE_VALUES_MISSING);
}

fixture.detectChanges();

Expand All @@ -518,19 +546,27 @@ describe('ConfiguratorAttributeDropDownComponent', () => {
'configurator.a11y.selectedValueOfAttributeFullWithPrice attribute:' +
component.attribute.label +
' price:' +
value2.valuePrice?.formattedValue +
value2?.valuePrice?.formattedValue +
' value:' +
value2.valueDisplay,
value2.valueDisplay
value2?.valueDisplay,
value2?.valueDisplay
);
});

it("should contain option elements with 'aria-label' attribute for value with total price that defines an accessible name to label the current element", () => {
value2.valuePriceTotal = {
currencyIso: '$',
formattedValue: '$100.00',
value: 100,
};
let value2;
if (component.attribute.values) {
value2 = component.attribute.values[1];
value2.selected = true;
value2.valuePriceTotal = {
currencyIso: '$',
formattedValue: '$100.00',
value: 100,
};
} else {
fail(ATTRIBUTE_VALUES_MISSING);
}

fixture.detectChanges();

CommonConfiguratorTestUtilsService.expectElementContainsA11y(
Expand All @@ -543,10 +579,10 @@ describe('ConfiguratorAttributeDropDownComponent', () => {
'configurator.a11y.selectedValueOfAttributeFullWithPrice attribute:' +
component.attribute.label +
' price:' +
value2.valuePrice?.formattedValue +
value2?.valuePriceTotal?.formattedValue +
' value:' +
value2.valueDisplay,
value2.valueDisplay
value2?.valueDisplay,
value2?.valueDisplay
);
});
});
Expand Down
Loading

0 comments on commit f840a7d

Please sign in to comment.