-
Notifications
You must be signed in to change notification settings - Fork 87
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: button for clearing cart (#1537)
Co-authored-by: Stefan Hauke <s.hauke@intershop.de> Co-authored-by: Silke <s.grueber@intershop.de> Co-authored-by: Susanne Schneider <s.schneider@intershop.de>
- Loading branch information
1 parent
367fe70
commit dd5f34f
Showing
16 changed files
with
237 additions
and
11 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
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
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
22 changes: 22 additions & 0 deletions
22
src/app/shared/components/basket/clear-basket/clear-basket.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,22 @@ | ||
<button | ||
type="button" | ||
class="btn btn-link" | ||
[ngClass]="cssClass" | ||
[attr.title]="'shopping_cart.clear_cart.button' | translate" | ||
data-testing-id="clearBasketButton" | ||
(click)="clearDialog.show()" | ||
> | ||
{{ 'shopping_cart.clear_cart.button' | translate }} | ||
</button> | ||
|
||
<ish-modal-dialog | ||
#clearDialog | ||
[options]="{ | ||
confirmText: 'shopping_cart.clear_cart.confirm_button' | translate, | ||
rejectText: 'shopping_cart.button.cancel' | translate, | ||
titleText: 'shopping_cart.clear_cart.dialog_header' | translate | ||
}" | ||
(confirmed)="clearBasket()" | ||
> | ||
{{ 'shopping_cart.clear_cart.question' | translate }} | ||
</ish-modal-dialog> |
52 changes: 52 additions & 0 deletions
52
src/app/shared/components/basket/clear-basket/clear-basket.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,52 @@ | ||
import { ComponentFixture, TestBed } from '@angular/core/testing'; | ||
import { TranslateModule } from '@ngx-translate/core'; | ||
import { MockComponent } from 'ng-mocks'; | ||
import { instance, mock, verify, when } from 'ts-mockito'; | ||
|
||
import { CheckoutFacade } from 'ish-core/facades/checkout.facade'; | ||
import { ModalDialogComponent } from 'ish-shared/components/common/modal-dialog/modal-dialog.component'; | ||
|
||
import { ClearBasketComponent } from './clear-basket.component'; | ||
|
||
describe('Clear Basket Component', () => { | ||
let component: ClearBasketComponent; | ||
let fixture: ComponentFixture<ClearBasketComponent>; | ||
let element: HTMLElement; | ||
let checkoutFacade: CheckoutFacade; | ||
|
||
beforeEach(async () => { | ||
checkoutFacade = mock(CheckoutFacade); | ||
|
||
await TestBed.configureTestingModule({ | ||
declarations: [ClearBasketComponent, MockComponent(ModalDialogComponent)], | ||
imports: [TranslateModule.forRoot()], | ||
providers: [{ provide: CheckoutFacade, useFactory: () => instance(checkoutFacade) }], | ||
}).compileComponents(); | ||
|
||
when(checkoutFacade.deleteBasketItems()).thenReturn(undefined); | ||
}); | ||
|
||
beforeEach(() => { | ||
fixture = TestBed.createComponent(ClearBasketComponent); | ||
component = fixture.componentInstance; | ||
element = fixture.nativeElement; | ||
}); | ||
|
||
it('should be created', () => { | ||
expect(component).toBeTruthy(); | ||
expect(element).toBeTruthy(); | ||
expect(() => fixture.detectChanges()).not.toThrow(); | ||
}); | ||
|
||
it('should display a button to trigger the clearing of the basket', () => { | ||
fixture.detectChanges(); | ||
|
||
expect(element.querySelector('button[data-testing-id=clearBasketButton]')).toBeTruthy(); | ||
}); | ||
|
||
it('should call facade when triggered.', () => { | ||
component.clearBasket(); | ||
|
||
verify(checkoutFacade.deleteBasketItems()).once(); | ||
}); | ||
}); |
18 changes: 18 additions & 0 deletions
18
src/app/shared/components/basket/clear-basket/clear-basket.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,18 @@ | ||
import { ChangeDetectionStrategy, Component, Input } from '@angular/core'; | ||
|
||
import { CheckoutFacade } from 'ish-core/facades/checkout.facade'; | ||
|
||
@Component({ | ||
selector: 'ish-clear-basket', | ||
templateUrl: './clear-basket.component.html', | ||
changeDetection: ChangeDetectionStrategy.OnPush, | ||
}) | ||
export class ClearBasketComponent { | ||
@Input() cssClass: string; | ||
|
||
constructor(private checkoutFacade: CheckoutFacade) {} | ||
|
||
clearBasket() { | ||
this.checkoutFacade.deleteBasketItems(); | ||
} | ||
} |
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