-
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.
feat: Create Order Template from Order (#1610)
Co-authored-by: LucasHengelhaupt <l.hengelhaupt@intershop.com> Co-authored-by: Silke <s.grueber@intershop.de>
- Loading branch information
1 parent
11495fc
commit 553e05a
Showing
25 changed files
with
491 additions
and
145 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
8 changes: 1 addition & 7 deletions
8
...templates/shared/basket-create-order-template/basket-create-order-template.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
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
23 changes: 23 additions & 0 deletions
23
...r-templates/shared/order-create-order-template/order-create-order-template.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,23 @@ | ||
<button | ||
type="button" | ||
class="btn btn-secondary btn-block" | ||
[ngClass]="cssClass" | ||
(click)="openModal(modal)" | ||
[disabled]="displaySpinner()" | ||
data-testing-id="addOrderToOrderTemplateButton" | ||
> | ||
<ng-container *ngIf="displaySpinner() !== true; else spinning"> | ||
{{ 'order_template.create.heading' | translate }} | ||
</ng-container> | ||
<!-- spinning animation after clicking button --> | ||
<ng-template #spinning> | ||
<fa-icon [icon]="['fas', 'spinner']" [spin]="true" ngClass="pr-3" /> | ||
<span>{{ 'common.button.spinning.label' | translate }}</span></ng-template | ||
> | ||
</button> | ||
|
||
<ish-order-template-preferences-dialog | ||
#modal | ||
modalTitle="account.order_template.new_from_order.heading" | ||
(submitOrderTemplate)="createOrderTemplate($event)" | ||
/> |
55 changes: 55 additions & 0 deletions
55
...emplates/shared/order-create-order-template/order-create-order-template.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,55 @@ | ||
import { ComponentFixture, TestBed } from '@angular/core/testing'; | ||
import { TranslateModule } from '@ngx-translate/core'; | ||
import { MockComponent } from 'ng-mocks'; | ||
import { of } from 'rxjs'; | ||
import { anything, instance, mock, verify, when } from 'ts-mockito'; | ||
|
||
import { OrderTemplatesFacade } from '../../facades/order-templates.facade'; | ||
import { OrderTemplate } from '../../models/order-template/order-template.model'; | ||
import { OrderTemplatePreferencesDialogComponent } from '../order-template-preferences-dialog/order-template-preferences-dialog.component'; | ||
|
||
import { OrderCreateOrderTemplateComponent } from './order-create-order-template.component'; | ||
|
||
describe('Order Create Order Template Component', () => { | ||
let component: OrderCreateOrderTemplateComponent; | ||
let fixture: ComponentFixture<OrderCreateOrderTemplateComponent>; | ||
let element: HTMLElement; | ||
|
||
let orderTemplatesFacadeMock: OrderTemplatesFacade; | ||
|
||
beforeEach(async () => { | ||
orderTemplatesFacadeMock = mock(OrderTemplatesFacade); | ||
|
||
when(orderTemplatesFacadeMock.orderTemplateLoading$).thenReturn(of(false)); | ||
|
||
await TestBed.configureTestingModule({ | ||
declarations: [MockComponent(OrderTemplatePreferencesDialogComponent), OrderCreateOrderTemplateComponent], | ||
imports: [TranslateModule.forRoot()], | ||
providers: [{ provide: OrderTemplatesFacade, useFactory: () => instance(orderTemplatesFacadeMock) }], | ||
}).compileComponents(); | ||
}); | ||
|
||
beforeEach(() => { | ||
fixture = TestBed.createComponent(OrderCreateOrderTemplateComponent); | ||
component = fixture.componentInstance; | ||
element = fixture.nativeElement; | ||
}); | ||
|
||
it('should be created', () => { | ||
expect(component).toBeTruthy(); | ||
expect(element).toBeTruthy(); | ||
expect(() => fixture.detectChanges()).not.toThrow(); | ||
}); | ||
|
||
it('should render the create order-template from order button', () => { | ||
fixture.detectChanges(); | ||
|
||
expect(element.querySelector('button[data-testing-id="addOrderToOrderTemplateButton"]')).toBeTruthy(); | ||
}); | ||
|
||
it('should trigger createOrderTemplatesFromLineItems when createOrderTemplates is called', () => { | ||
component.createOrderTemplate({ id: 'orderTemplateId' } as OrderTemplate); | ||
|
||
verify(orderTemplatesFacadeMock.createOrderTemplateFromLineItems(anything(), anything())).once(); | ||
}); | ||
}); |
38 changes: 38 additions & 0 deletions
38
...der-templates/shared/order-create-order-template/order-create-order-template.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,38 @@ | ||
import { ChangeDetectionStrategy, Component, Input, Signal } from '@angular/core'; | ||
import { toSignal } from '@angular/core/rxjs-interop'; | ||
|
||
import { LineItemView } from 'ish-core/models/line-item/line-item.model'; | ||
import { GenerateLazyComponent } from 'ish-core/utils/module-loader/generate-lazy-component.decorator'; | ||
|
||
import { OrderTemplatesFacade } from '../../facades/order-templates.facade'; | ||
import { OrderTemplate } from '../../models/order-template/order-template.model'; | ||
import { OrderTemplatePreferencesDialogComponent } from '../order-template-preferences-dialog/order-template-preferences-dialog.component'; | ||
|
||
@Component({ | ||
selector: 'ish-order-create-order-template', | ||
templateUrl: './order-create-order-template.component.html', | ||
changeDetection: ChangeDetectionStrategy.OnPush, | ||
}) | ||
/** | ||
* The Create Order Template from Order displays a button which adds the current order to to a new order template. | ||
*/ | ||
|
||
@GenerateLazyComponent() | ||
export class OrderCreateOrderTemplateComponent { | ||
@Input({ required: true }) lineItems: LineItemView[]; | ||
@Input() cssClass: string; | ||
|
||
displaySpinner: Signal<boolean>; | ||
|
||
constructor(private orderTemplatesFacade: OrderTemplatesFacade) { | ||
this.displaySpinner = toSignal(this.orderTemplatesFacade.orderTemplateLoading$, { initialValue: false }); | ||
} | ||
|
||
openModal(modal: OrderTemplatePreferencesDialogComponent) { | ||
modal.show(); | ||
} | ||
|
||
createOrderTemplate(orderTemplate: OrderTemplate) { | ||
this.orderTemplatesFacade.createOrderTemplateFromLineItems(orderTemplate, this.lineItems); | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
...shared/order-template-preferences-dialog/order-template-preferences-dialog.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
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
Oops, something went wrong.