-
Notifications
You must be signed in to change notification settings - Fork 86
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: consolidate the display of promotion messages (#448)
- Loading branch information
Showing
10 changed files
with
179 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
e2e/cypress/integration/specs/checkout/basket-promotion-handling.b2c.e2e-spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import { at } from '../../framework'; | ||
import { CartPage } from '../../pages/checkout/cart.page'; | ||
import { ProductDetailPage } from '../../pages/shopping/product-detail.page'; | ||
|
||
const _ = { | ||
productSku: '201807171', | ||
}; | ||
|
||
describe('Promotion Handling in Cart', () => { | ||
before(() => { | ||
ProductDetailPage.navigateTo(_.productSku); | ||
}); | ||
|
||
it('user adds a promotion code that cannot applied yet', () => { | ||
at(ProductDetailPage, page => { | ||
page.addProductToCart().its('status').should('equal', 201); | ||
page.header.miniCart.goToCart(); | ||
}); | ||
at(CartPage, page => { | ||
page.lineItems.should('have.length', 1); | ||
page.collapsePromotionForm(); | ||
page.submitPromotionCode('INTERSHOP'); | ||
page.errorMessage.message.should('contain', 'promotion code'); | ||
page.promotion.should('not.exist'); | ||
}); | ||
}); | ||
|
||
it('user adds a promotion code that can be applied yet', () => { | ||
at(CartPage, page => { | ||
page.lineItem(0).quantity.set(2); | ||
cy.wait(1000); | ||
page.submitPromotionCode('INTERSHOP'); | ||
page.successMessage.message.should('contain', 'applied'); | ||
page.promotion.should('exist'); | ||
}); | ||
}); | ||
|
||
it('user removes a promotion code', () => { | ||
at(CartPage, page => { | ||
page.removePromotionCode(); | ||
page.promotion.should('not.exist'); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
src/app/shared/components/common/success-message/success-message.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<div *ngIf="message && !toast" class="alert alert-success" role="alert"> | ||
{{ message | translate }} | ||
</div> |
58 changes: 58 additions & 0 deletions
58
src/app/shared/components/common/success-message/success-message.component.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import { ComponentFixture, TestBed } from '@angular/core/testing'; | ||
import { TranslateModule } from '@ngx-translate/core'; | ||
import { anything, instance, mock, verify } from 'ts-mockito'; | ||
|
||
import { MessageFacade } from 'ish-core/facades/message.facade'; | ||
|
||
import { SuccessMessageComponent } from './success-message.component'; | ||
|
||
describe('Success Message Component', () => { | ||
let component: SuccessMessageComponent; | ||
let fixture: ComponentFixture<SuccessMessageComponent>; | ||
let element: HTMLElement; | ||
let messageFacade: MessageFacade; | ||
|
||
beforeEach(async () => { | ||
messageFacade = mock(MessageFacade); | ||
await TestBed.configureTestingModule({ | ||
imports: [TranslateModule.forRoot()], | ||
declarations: [SuccessMessageComponent], | ||
providers: [{ provide: MessageFacade, useFactory: () => instance(messageFacade) }], | ||
}).compileComponents(); | ||
}); | ||
|
||
beforeEach(() => { | ||
fixture = TestBed.createComponent(SuccessMessageComponent); | ||
component = fixture.componentInstance; | ||
element = fixture.nativeElement; | ||
}); | ||
|
||
it('should be created', () => { | ||
expect(component).toBeTruthy(); | ||
expect(element).toBeTruthy(); | ||
expect(() => fixture.detectChanges()).not.toThrow(); | ||
}); | ||
|
||
it('should not render a message if no message occurs', () => { | ||
fixture.detectChanges(); | ||
expect(element.querySelector('[role="alert"]')).toBeFalsy(); | ||
}); | ||
|
||
it('should render a message if a message occurs and toast is false', () => { | ||
component.message = 'Test Message'; | ||
component.toast = false; | ||
|
||
component.ngOnChanges(); | ||
fixture.detectChanges(); | ||
expect(element.querySelector('[role="alert"]')).toBeTruthy(); | ||
}); | ||
|
||
it('should trigger success toast if a message occurs and toast is true', () => { | ||
component.message = 'Test Message'; | ||
component.toast = true; | ||
|
||
component.ngOnChanges(); | ||
fixture.detectChanges(); | ||
verify(messageFacade.success(anything())).once(); | ||
}); | ||
}); |
30 changes: 30 additions & 0 deletions
30
src/app/shared/components/common/success-message/success-message.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { ChangeDetectionStrategy, Component, Input, OnChanges } from '@angular/core'; | ||
|
||
import { MessageFacade } from 'ish-core/facades/message.facade'; | ||
|
||
@Component({ | ||
selector: 'ish-success-message', | ||
templateUrl: './success-message.component.html', | ||
changeDetection: ChangeDetectionStrategy.OnPush, | ||
}) | ||
export class SuccessMessageComponent implements OnChanges { | ||
/** key or message is accepted */ | ||
@Input() message: string; | ||
@Input() toast = true; | ||
|
||
constructor(private messagesFacade: MessageFacade) {} | ||
|
||
ngOnChanges() { | ||
if (this.toast) { | ||
this.displayToast(); | ||
} | ||
} | ||
|
||
private displayToast() { | ||
if (this.message) { | ||
this.messagesFacade.success({ | ||
message: this.message, | ||
}); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters