Skip to content

Commit

Permalink
fix: 'resolveIssues' only if link is in banner (SAP#16709)
Browse files Browse the repository at this point in the history
  • Loading branch information
ChristophHi authored Jan 3, 2023
1 parent 3a61806 commit 8899fa1
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
}
} | cxUrl
"
[queryParams]="{ forceReload: true, resolveIssues: hasIssues() }"
[queryParams]="getQueryParams()"
cxAutoFocus
attr.aria-describedby="{{ getResolveIssuesA11yDescription() }}"
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ import { RouterModule } from '@angular/router';
import { RouterTestingModule } from '@angular/router/testing';
import { OrderEntry } from '@spartacus/cart/base/root';
import { I18nTestingModule } from '@spartacus/core';
import { CommonConfigurator } from '../../core/model/common-configurator.model';
import {
CommonConfigurator,
OrderEntryStatus,
} from '../../core/model/common-configurator.model';
import { CommonConfiguratorTestUtilsService } from '../../testing/common-configurator-test-utils.service';
import { ConfigureCartEntryComponent } from './configure-cart-entry.component';

Expand Down Expand Up @@ -218,6 +221,46 @@ describe('ConfigureCartEntryComponent', () => {
});
});

describe('getQueryParams', () => {
it('should set "forceReload" parameter', () => {
expect(component.getQueryParams().forceReload).toBe(true);
});
it('should not set "resolveIssues" parameter in case no issues exist', () => {
component.readOnly = false;
component.msgBanner = false;
component.cartEntry = {
entryNumber: 0,
product: { configuratorType: configuratorType },
statusSummaryList: [],
};
expect(component.getQueryParams().resolveIssues).toBe(false);
});
it('should set "resolveIssues" parameter in case issues exist', () => {
component.readOnly = false;
component.msgBanner = true;
component.cartEntry = {
entryNumber: 0,
product: { configuratorType: configuratorType },
statusSummaryList: [
{ status: OrderEntryStatus.Error, numberOfIssues: 3 },
],
};
expect(component.getQueryParams().resolveIssues).toBe(true);
});
it('should not set "resolveIssues" parameter in case issues exist but component is not rendered in the context of the resolve issues banner', () => {
component.readOnly = false;
component.msgBanner = false;
component.cartEntry = {
entryNumber: 0,
product: { configuratorType: configuratorType },
statusSummaryList: [
{ status: OrderEntryStatus.Error, numberOfIssues: 3 },
],
};
expect(component.getQueryParams().resolveIssues).toBe(false);
});
});

describe('Accessibility', () => {
it('should contain link element with ID for error message containing cart entry number and aria-describedby attribute that refers to the corresponding resolve issue message', function () {
component.readOnly = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*/

import { ChangeDetectionStrategy, Component, Input } from '@angular/core';
import { Params } from '@angular/router';
import { OrderEntry } from '@spartacus/cart/base/root';
import { CommonConfigurator } from '../../core/model/common-configurator.model';
import { CommonConfiguratorUtilsService } from '../../shared/utils/common-configurator-utils.service';
Expand Down Expand Up @@ -100,6 +101,18 @@ export class ConfigureCartEntryComponent {
return !this.readOnly && this.msgBanner ? errorMsgId : undefined;
}

/**
* Compiles query parameters for the router link. 'resolveIssues' is only set if the component is
* rendered in the context of the message banner, and if issues exist at all
* @returns Query parameters
*/
getQueryParams(): Params {
return {
forceReload: true,
resolveIssues: this.msgBanner && this.hasIssues(),
};
}

constructor(
protected commonConfigUtilsService: CommonConfiguratorUtilsService
) {}
Expand Down

0 comments on commit 8899fa1

Please sign in to comment.