Skip to content

Commit

Permalink
update test file
Browse files Browse the repository at this point in the history
  • Loading branch information
petarmarkov9449 committed Oct 29, 2024
1 parent 3a68596 commit e2e93f4
Showing 1 changed file with 13 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {
} from '@spartacus/cart/base/root';
import {
ActivatedRouterStateSnapshot,
FeatureConfigService,
I18nTestingModule,
RouterState,
RoutingService,
Expand Down Expand Up @@ -134,13 +135,20 @@ class MockUrlPipe implements PipeTransform {
transform(): any {}
}

class MockFeatureConfigService {
isEnabled() {
return true;
}
}

describe('AddedToCartDialogComponent', () => {
let component: AddedToCartDialogComponent;
let fixture: ComponentFixture<AddedToCartDialogComponent>;
let el: DebugElement;
let activeCartFacade: ActiveCartFacade;
let launchDialogService: LaunchDialogService;
let routingService: RoutingService;
let featureConfigService: FeatureConfigService;

beforeEach(() => {
TestBed.configureTestingModule({
Expand Down Expand Up @@ -170,6 +178,7 @@ describe('AddedToCartDialogComponent', () => {
useClass: MockRoutingService,
},
{ provide: LaunchDialogService, useClass: MockLaunchDialogService },
{ provide: FeatureConfigService, useClass: MockFeatureConfigService },
],
}).compileComponents();
});
Expand All @@ -182,6 +191,7 @@ describe('AddedToCartDialogComponent', () => {

launchDialogService = TestBed.inject(LaunchDialogService);
routingService = TestBed.inject(RoutingService);
featureConfigService = TestBed.inject(FeatureConfigService);

spyOn(activeCartFacade, 'updateEntry').and.callThrough();

Expand Down Expand Up @@ -247,20 +257,12 @@ describe('AddedToCartDialogComponent', () => {
});
});

it('should display loading placeholder', () => {
component.loaded$ = of(false);
it('should shouw item added to your cart dialog title message in case a11yUpdatingCartNoNarration is enabled', () => {
spyOn(featureConfigService, 'isEnabled').and.returnValue(true);
fixture.detectChanges();
expect(
el.query(By.css('.cx-dialog-title')).nativeElement.textContent.trim()
).toEqual('addToCart.updatingCart');
expect(el.query(By.css('cx-spinner')).nativeElement).toBeDefined();
});

it('should display quantity', () => {
fixture.detectChanges();
expect(
el.query(By.css('.cx-dialog-title')).nativeElement.textContent.trim()
).toEqual('addToCart.itemsAddedToYourCart');
).toEqual('addToCart.itemAddedToYourCart');
});

it('should display cart item', () => {
Expand Down Expand Up @@ -322,29 +324,6 @@ describe('AddedToCartDialogComponent', () => {
});
});

it('should show added dialog title message in case new entry appears in cart', () => {
component.entry$ = of(mockOrderEntries[0]);
component.loaded$ = of(true);
spyOn(activeCartFacade, 'getEntries').and.returnValue(of([]));
fixture.detectChanges();
const dialogTitleEl = el.query(By.css('.cx-dialog-title')).nativeElement;
expect(dialogTitleEl.textContent).toEqual(
' addToCart.itemsAddedToYourCart '
);
});

it('should show increment dialog title message in case no new entry appears in cart', () => {
component.entry$ = of(mockOrderEntries[0]);
component.loaded$ = of(true);
component.addedEntryWasMerged$ = of(true);
spyOn(activeCartFacade, 'getEntries').and.returnValue(of(mockOrderEntries));
fixture.detectChanges();
const dialogTitleEl = el.query(By.css('.cx-dialog-title')).nativeElement;
expect(dialogTitleEl.textContent).toEqual(
' addToCart.itemsIncrementedInYourCart '
);
});

it('should not show cart entry', () => {
component.loaded$ = of(false);
expect(el.query(By.css('cx-cart-item'))).toBeNull();
Expand Down

0 comments on commit e2e93f4

Please sign in to comment.