feat: implement loading state for checkout process and enhance stepper component

This commit is contained in:
2026-07-28 09:25:04 -03:00
parent c41c60f349
commit 7845c8f20e
6 changed files with 219 additions and 49 deletions

View File

@@ -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();

View File

@@ -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();