@@ -10,50 +10,63 @@ import { render } from '@ember/test-helpers';
1010// Because of how the `step` subcomponent is built,
1111// it's practically impossible to test in isolation, so in our tests
1212// in this file it will be wrapped inside its parent comoponent.
13- import Nav from " @hashicorp/design-system-components/components/hds/stepper/nav/index" ;
14- import Step from " @hashicorp/design-system-components/components/hds/stepper/nav/step" ;
13+ import Nav from ' @hashicorp/design-system-components/components/hds/stepper/nav/index' ;
14+ import Step from ' @hashicorp/design-system-components/components/hds/stepper/nav/step' ;
15+ import type { HdsStepperTitleTags } from ' @hashicorp/design-system-components/components/hds/stepper/types' ;
16+
17+ const createNavStep = async (options : {
18+ title? : string ;
19+ description? : string ;
20+ currentStep? : number ;
21+ stepNumber? : number ;
22+ isNavInteractive? : boolean ;
23+ titleTag? : HdsStepperTitleTags ;
24+ }) => {
25+ const currentStep = options .currentStep ?? 0 ;
26+
27+ return await render (
28+ <template >
29+ <Nav
30+ @ ariaLabel =" Sample stepper"
31+ @ currentStep ={{currentStep }}
32+ @ isInteractive ={{options.isNavInteractive }}
33+ as | S |
34+ >
35+ <S.Step @ titleTag ={{options.titleTag }} >
36+ <: title >{{options.title }} </: title >
37+ <: description >{{options.description }} </: description >
38+ </S.Step >
39+ <S.Panel />
40+ </Nav >
41+ </template >,
42+ );
43+ };
1544
1645module (' Integration | Component | hds/stepper/nav/step' , function (hooks ) {
1746 setupRenderingTest (hooks );
1847
19- hooks .beforeEach (function () {
20- this .set (' createNavStep' , async (args = {}) => {
21- this .title = args .title ?? undefined ;
22- this .description = args .description ?? undefined ;
23- this .currentStep = args .currentStep ?? undefined ;
24- this .stepNumber = args .stepNumber ?? undefined ;
25- this .isNavInteractive = args .isNavInteractive ?? undefined ;
26- this .titleTag = args .titleTag ?? undefined ;
27- return await render (<template >
28- <Nav @ currentStep ={{this .currentStep }} @ isInteractive ={{this .isNavInteractive }} as | S | >
29- <S.Step @ stepNumber ={{this .stepNumber }} @ titleTag ={{this .titleTag }} >
30- <: title >{{this .title }} </: title >
31- <: description >{{this .description }} </: description >
32- </S.Step >
33- <S.Panel />
34- </Nav >
35- </template >);
36- });
37- });
38-
3948 // CLASSES
4049
4150 test (' it should render the component with a CSS class that matches the component name' , async function (assert ) {
42- await render (<template ><Step id =" test-stepper-nav-step" /></template >);
51+ await render (
52+ <template >
53+ <Step id =" test-stepper-nav-step" @ currentStep ={{ 0 }} />
54+ </template >,
55+ );
4356 assert .dom (' #test-stepper-nav-step' ).hasClass (' hds-stepper-nav__step' );
4457 });
4558
4659 // STEP NUMBER
4760
4861 test (' it sets the step number automatically based on the step ids provided' , async function (assert ) {
49- await this . createNavStep ();
62+ await createNavStep ({} );
5063 assert .dom (' .hds-stepper-indicator-step__text' ).hasText (' 1' );
5164 });
5265
5366 // NAV INTERACTIVE
5467
5568 test (' it sets the step to interactive when the @isNavInteractive argument is not provided to the parent' , async function (assert ) {
56- await this . createNavStep ();
69+ await createNavStep ({} );
5770 assert .dom (' .hds-stepper-nav__step' ).hasAttribute (' role' , ' presentation' );
5871 assert
5972 .dom (' .hds-stepper-nav__step' )
@@ -67,7 +80,7 @@ module('Integration | Component | hds/stepper/nav/step', function (hooks) {
6780 });
6881
6982 test (' it sets the step to non-interactive when the @isNavInteractive argument is provided to the parent' , async function (assert ) {
70- await this . createNavStep ({ isNavInteractive: false });
83+ await createNavStep ({ isNavInteractive: false });
7184 assert .dom (' .hds-stepper-nav__step' ).hasNoAttribute (' role' );
7285 assert
7386 .dom (' .hds-stepper-nav__step' )
@@ -85,10 +98,11 @@ module('Integration | Component | hds/stepper/nav/step', function (hooks) {
8598 test (' it sets the step to incomplete when the @currentStep is less than the nodeIndex and @isNavInteractive is true' , async function (assert ) {
8699 await render (
87100 <template >
88- <Step @ stepNumber = {{ 1 }} @ currentStep ={{ 2 }} @ isNavInteractive ={{ true }} >
101+ <Step @ currentStep ={{ 2 }} @ isNavInteractive ={{ true }} >
89102 <: title >Title</: title >
90103 <: description >Description</: description >
91- </Step ></template >,
104+ </Step >
105+ </template >,
92106 );
93107 assert
94108 .dom (' .hds-stepper-nav__step' )
@@ -104,7 +118,7 @@ module('Integration | Component | hds/stepper/nav/step', function (hooks) {
104118 });
105119
106120 test (' it sets the step to complete when the @currentStep is greater than the nodeIndex and @isNavInteractive is true' , async function (assert ) {
107- await this . createNavStep ({ currentStep: 1 });
121+ await createNavStep ({ currentStep: 1 });
108122 assert
109123 .dom (' .hds-stepper-nav__step' )
110124 .hasClass (' hds-stepper-nav__step--complete' );
@@ -119,7 +133,7 @@ module('Integration | Component | hds/stepper/nav/step', function (hooks) {
119133 });
120134
121135 test (' it sets the step to active when the @currentStep is equal to the nodeIndex and @isNavInteractive is true' , async function (assert ) {
122- await this . createNavStep ({ currentStep: 0 });
136+ await createNavStep ({ currentStep: 0 });
123137 assert
124138 .dom (' .hds-stepper-nav__step' )
125139 .hasClass (' hds-stepper-nav__step--active' );
@@ -138,10 +152,11 @@ module('Integration | Component | hds/stepper/nav/step', function (hooks) {
138152 test (' it sets the step to incomplete when the @currentStep is less than the nodeIndex and @isNavInteractive is false' , async function (assert ) {
139153 await render (
140154 <template >
141- <Step @ stepNumber = {{ 1 }} @ currentStep ={{ 2 }} @ isNavInteractive ={{ false }} >
155+ <Step @ currentStep ={{ 2 }} @ isNavInteractive ={{ false }} >
142156 <: title >Title</: title >
143157 <: description >Description</: description >
144- </Step ></template >,
158+ </Step >
159+ </template >,
145160 );
146161 assert
147162 .dom (' .hds-stepper-nav__step' )
@@ -154,7 +169,7 @@ module('Integration | Component | hds/stepper/nav/step', function (hooks) {
154169 });
155170
156171 test (' it sets the step to complete when the @currentStep is greater than the nodeIndex and @isNavInteractive is false' , async function (assert ) {
157- await this . createNavStep ({ currentStep: 1 , isNavInteractive: false });
172+ await createNavStep ({ currentStep: 1 , isNavInteractive: false });
158173 assert
159174 .dom (' .hds-stepper-nav__step' )
160175 .hasClass (' hds-stepper-nav__step--complete' );
@@ -166,7 +181,7 @@ module('Integration | Component | hds/stepper/nav/step', function (hooks) {
166181 });
167182
168183 test (' it sets the step to active when the @currentStep is equal to the nodeIndex and @isNavInteractive is false' , async function (assert ) {
169- await this . createNavStep ({ currentStep: 0 , isNavInteractive: false });
184+ await createNavStep ({ currentStep: 0 , isNavInteractive: false });
170185 assert
171186 .dom (' .hds-stepper-nav__step' )
172187 .hasClass (' hds-stepper-nav__step--active' );
@@ -180,31 +195,31 @@ module('Integration | Component | hds/stepper/nav/step', function (hooks) {
180195 // TITLE TAG
181196
182197 test (' it renders a div when the @titleTag argument is not provided' , async function (assert ) {
183- await this . createNavStep ();
198+ await createNavStep ({} );
184199 assert .dom (' .hds-stepper-nav__step-title' ).hasTagName (' div' );
185200 });
186201
187202 test (' it renders the custom title tag when the @titleTag argument is provided' , async function (assert ) {
188- await this . createNavStep ({ titleTag: ' h2' });
203+ await createNavStep ({ titleTag: ' h2' });
189204 assert .dom (' .hds-stepper-nav__step-title' ).hasTagName (' h2' );
190205 });
191206
192207 // TITLE
193208
194209 test (' it renders the title when the title contextual component block is used' , async function (assert ) {
195- await this . createNavStep ({ title: ' Test' });
210+ await createNavStep ({ title: ' Test' });
196211 assert .dom (' .hds-stepper-nav__step-title' ).containsText (' Test' );
197212 });
198213
199214 // DESCRIPTION
200215
201216 test (' it does not render the description when the description contextual component block is not used' , async function (assert ) {
202- await render (<template ><Step ></ Step ></template >);
217+ await render (<template ><Step @ currentStep = {{ 0 }} / ></template >);
203218 assert .dom (' .hds-stepper-nav__step-description' ).doesNotExist ();
204219 });
205220
206221 test (' it renders the description when the description contextual component block is used' , async function (assert ) {
207- await this . createNavStep ({ description: ' Test' });
222+ await createNavStep ({ description: ' Test' });
208223 assert .dom (' .hds-stepper-nav__step-description' ).exists ();
209224 assert .dom (' .hds-stepper-nav__step-description' ).containsText (' Test' );
210225 });
0 commit comments