feat: implement loading state for checkout process and enhance stepper component
This commit is contained in:
@@ -14,7 +14,7 @@ import { StepComponent } from './step.component';
|
||||
<div id="content-2">Content 2</div>
|
||||
</app-step>
|
||||
</app-stepper>
|
||||
`
|
||||
`,
|
||||
})
|
||||
class TestHostComponent {
|
||||
@ViewChild('stepper') stepper!: StepperComponent;
|
||||
@@ -25,7 +25,7 @@ class TestHostComponent {
|
||||
describe('StepperComponent & StepComponent', () => {
|
||||
async function setup() {
|
||||
await TestBed.configureTestingModule({
|
||||
imports: [TestHostComponent, StepperComponent, StepComponent]
|
||||
imports: [TestHostComponent, StepperComponent, StepComponent],
|
||||
}).compileComponents();
|
||||
|
||||
const fixture = TestBed.createComponent(TestHostComponent);
|
||||
@@ -50,6 +50,18 @@ describe('StepperComponent & StepComponent', () => {
|
||||
expect(content2).toBeNull();
|
||||
});
|
||||
|
||||
it('can initialize on a specified step', async () => {
|
||||
await TestBed.configureTestingModule({
|
||||
imports: [StepperComponent, StepComponent],
|
||||
}).compileComponents();
|
||||
|
||||
const fixture = TestBed.createComponent(StepperComponent);
|
||||
fixture.componentRef.setInput('initialStepIndex', 1);
|
||||
fixture.detectChanges();
|
||||
|
||||
expect(fixture.componentInstance.currentStepIndex()).toBe(1);
|
||||
});
|
||||
|
||||
it('advances to step 2 when next() is called and current step is valid', async () => {
|
||||
const { fixture, component } = await setup();
|
||||
|
||||
|
||||
@@ -1,4 +1,10 @@
|
||||
import { ChangeDetectionStrategy, Component, contentChildren, signal } from '@angular/core';
|
||||
import {
|
||||
ChangeDetectionStrategy,
|
||||
Component,
|
||||
contentChildren,
|
||||
input,
|
||||
linkedSignal,
|
||||
} from '@angular/core';
|
||||
import { StepComponent } from './step.component';
|
||||
import { NgClass } from '@angular/common';
|
||||
|
||||
@@ -11,7 +17,8 @@ import { NgClass } from '@angular/common';
|
||||
})
|
||||
export class StepperComponent {
|
||||
readonly steps = contentChildren(StepComponent);
|
||||
readonly currentStepIndex = signal(0);
|
||||
readonly initialStepIndex = input(0);
|
||||
readonly currentStepIndex = linkedSignal(() => this.initialStepIndex());
|
||||
|
||||
next() {
|
||||
const currentSteps = this.steps();
|
||||
|
||||
Reference in New Issue
Block a user