Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
[disabled]="disabled"
(click)="!disabled ? handleStepClick() : ''"
[tabindex]="disabled ? -1 : tabIndexValue"
[attr.aria-current]="isCurrent"
>
<div class="stepHeader">
<div class="iconContainer">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ TestBed.initTestEnvironment(

describe("DxcWizardComponent tests", () => {
test("should render dxc-wizard", async () => {
const { getByText } = await render(
const { getByText, getAllByRole } = await render(
`<dxc-wizard>
<dxc-wizard-step label="first-step"></dxc-wizard-step>
<dxc-wizard-step label="second-step"></dxc-wizard-step>
Expand All @@ -28,11 +28,14 @@ describe("DxcWizardComponent tests", () => {

expect(getByText("first-step"));
expect(getByText("second-step"));
const btn = getAllByRole("button");
expect(btn[0].getAttribute("aria-current")).toBe("true");
expect(btn[1].getAttribute("aria-current")).toBe("false");
});

test("click on step text", async () => {
const onClickFunction = jest.fn((i) => null);
const { getByText } = await render(
const { getByText, getAllByRole } = await render(
`<dxc-wizard (onStepClick)="onClickFunction($event)">
<dxc-wizard-step label="first-step"></dxc-wizard-step>
<dxc-wizard-step label="second-step"></dxc-wizard-step>
Expand All @@ -49,11 +52,14 @@ describe("DxcWizardComponent tests", () => {
const step = getByText("first-step");
fireEvent.click(step);
expect(onClickFunction).toHaveBeenCalledWith(0);
const btn = getAllByRole("button");
expect(btn[0].getAttribute("aria-current")).toBe("true");
expect(btn[1].getAttribute("aria-current")).toBe("false");
});

test("click on step text", async () => {
test("click on step text with description", async () => {
const onClickFunction = jest.fn((i) => null);
const { getByText } = await render(
const { getByText, getAllByRole } = await render(
`<dxc-wizard (onStepClick)="onClickFunction($event)">
<dxc-wizard-step label="first-step"></dxc-wizard-step>
<dxc-wizard-step label="second-step" description="step-description"></dxc-wizard-step>
Expand All @@ -70,11 +76,14 @@ describe("DxcWizardComponent tests", () => {
const step = getByText("step-description");
fireEvent.click(step);
expect(onClickFunction).toHaveBeenCalledWith(1);
const btn = getAllByRole("button");
expect(btn[0].getAttribute("aria-current")).toBe("false");
expect(btn[1].getAttribute("aria-current")).toBe("true");
});

test("click on step number", async () => {
const onClickFunction = jest.fn((i) => null);
const { getByText } = await render(
const { getByText, getAllByRole } = await render(
`<dxc-wizard (onStepClick)="onClickFunction($event)">
<dxc-wizard-step label="first-step"></dxc-wizard-step>
<dxc-wizard-step label="second-step" description="step-description"></dxc-wizard-step>
Expand All @@ -91,11 +100,14 @@ describe("DxcWizardComponent tests", () => {
const step = getByText("1");
fireEvent.click(step);
expect(onClickFunction).toHaveBeenCalledWith(0);
const btn = getAllByRole("button");
expect(btn[0].getAttribute("aria-current")).toBe("true");
expect(btn[1].getAttribute("aria-current")).toBe("false");
});

test("click on disable step", async () => {
test("click on disabled step", async () => {
const onClickFunction = jest.fn((i) => null);
const { getByText } = await render(
const { getByText, getAllByRole } = await render(
`<dxc-wizard (onStepClick)="onClickFunction($event)">
<dxc-wizard-step label="first-step"></dxc-wizard-step>
<dxc-wizard-step label="second-step" disabled="true"></dxc-wizard-step>
Expand All @@ -112,5 +124,52 @@ describe("DxcWizardComponent tests", () => {
const step = getByText("second-step");
fireEvent.click(step);
expect(onClickFunction).toHaveBeenCalledTimes(0);
const btn = getAllByRole("button");
expect(btn[0].getAttribute("aria-current")).toBe("true");
expect(btn[1].getAttribute("aria-current")).toBe("false");
});

test("wizard with default step", async () => {
const onClickFunction = jest.fn((i) => null);
const { getAllByRole } = await render(
`<dxc-wizard defaultCurrentStep="2">
<dxc-wizard-step label="first-step"></dxc-wizard-step>
<dxc-wizard-step label="second-step"></dxc-wizard-step>
<dxc-wizard-step label="third-step"></dxc-wizard-step>
</dxc-wizard>`,
{
componentProperties: {
onClickFunction,
},
imports: [DxcWizardModule],
excludeComponentDeclaration: true,
}
);
const btn = getAllByRole("button");
expect(btn[0].getAttribute("aria-current")).toBe("false");
expect(btn[1].getAttribute("aria-current")).toBe("false");
expect(btn[2].getAttribute("aria-current")).toBe("true");
});

test("wizard with default step and current step", async () => {
const onClickFunction = jest.fn((i) => null);
const { getAllByRole } = await render(
`<dxc-wizard defaultCurrentStep="2" currentStep="1">
<dxc-wizard-step label="first-step"></dxc-wizard-step>
<dxc-wizard-step label="second-step"></dxc-wizard-step>
<dxc-wizard-step label="third-step"></dxc-wizard-step>
</dxc-wizard>`,
{
componentProperties: {
onClickFunction,
},
imports: [DxcWizardModule],
excludeComponentDeclaration: true,
}
);
const btn = getAllByRole("button");
expect(btn[0].getAttribute("aria-current")).toBe("false");
expect(btn[1].getAttribute("aria-current")).toBe("true");
expect(btn[2].getAttribute("aria-current")).toBe("false");
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ export class DxcWizardComponent {
currentStep: 0,
margin: null,
tabIndexValue: 0,
defaultCurrentStep: 0,
});

constructor(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ export interface WizardProperties {
mode?: string;
currentStep?: number;
margin?: Spacing | Space;
defaultCurrentStep?: number;
tabIndexValue?: number;
}

Expand Down