1- import { html , observable , ref , when } from '@ni/fast-element' ;
1+ import { html , observable , ref } from '@ni/fast-element' ;
22import { parameterizeSuite } from '@ni/jasmine-parameterized' ;
33import { Stepper , stepperTag } from '..' ;
44import { fixture , type Fixture } from '../../utilities/tests/fixture' ;
55import { Step , stepTag } from '../../step' ;
6- import { anchorStepTag } from '../../anchor-step' ;
6+ import { AnchorStep , anchorStepTag } from '../../anchor-step' ;
7+ import { themeProviderTag } from '../../theme-provider' ;
8+ import { LabelProviderCore , labelProviderCoreTag } from '../../label-provider/core' ;
9+ import { StepPageObject } from '../../step/testing/step.pageobject' ;
10+ import { AnchorStepPageObject } from '../../anchor-step/testing/anchor-step.pageobject' ;
11+ import type { StepBasePageObject } from '../../patterns/step/testing/step-base.pageobject' ;
12+ import { Severity } from '../../patterns/severity/types' ;
13+ import { waitForUpdatesAsync } from '../../testing/async-helpers' ;
714
815describe ( 'Stepper' , ( ) => {
916 it ( 'can construct an element instance' , ( ) => {
@@ -14,89 +21,185 @@ describe('Stepper', () => {
1421 expect ( document . createElement ( stepperTag ) . orientation ) . toBe ( 'horizontal' ) ;
1522 } ) ;
1623
24+ function createStepPageObject ( step : Step | AnchorStep ) : StepBasePageObject {
25+ return step instanceof Step ? new StepPageObject ( step ) : new AnchorStepPageObject ( step ) ;
26+ }
27+
1728 const stepperTests = [
18- { name : 'step' , stepType : stepTag } ,
19- { name : 'anchor step' , stepType : anchorStepTag } ,
29+ { name : 'step' , stepTypeTag : stepTag } ,
30+ { name : 'anchor step' , stepTypeTag : anchorStepTag } ,
2031 ] as const ;
2132 parameterizeSuite ( stepperTests , ( suite , name , value ) => {
2233 suite ( `with ${ name } ` , ( ) => {
23- class FixtureModel {
24- @observable public step1 ! : Step ;
25- @observable public step2 ?: Step ;
26- @observable public multiple = false ;
27- }
28-
29- async function setup ( source : FixtureModel ) : Promise < Fixture < Stepper > > {
30- return await fixture < Stepper > (
31- html < FixtureModel > `<${ stepperTag } >
32- <${ value . stepType } ${ ref ( 'step1' ) } ></${ value . stepType } >
33- ${ when ( x => x . multiple , html < FixtureModel > `<${ value . stepType } ${ ref ( 'step2' ) } ></${ value . stepType } >` ) }
34- </${ stepperTag } >` ,
35- { source }
36- ) ;
37- }
38-
3934 describe ( 'count single' , ( ) => {
40- it ( 'configures stepInternals last' , async ( ) => {
41- const model = new FixtureModel ( ) ;
42- const { connect, disconnect } = await setup ( model ) ;
35+ class Model {
36+ @observable public step ! : Step | AnchorStep ;
37+ public stepPageObject ! : StepBasePageObject ;
38+ }
39+
40+ async function setup ( ) : Promise < Fixture < Stepper > & { model : Model } > {
41+ const model = new Model ( ) ;
42+ const result = await fixture < Stepper > (
43+ html < Model > `
44+ <${ stepperTag } >
45+ <${ value . stepTypeTag } ${ ref ( 'step' ) } ></${ value . stepTypeTag } >
46+ </${ stepperTag } >
47+ ` ,
48+ { source : model }
49+ ) ;
50+ model . stepPageObject = createStepPageObject ( model . step ) ;
51+ return { ...result , model } ;
52+ }
53+
54+ let element : Stepper ;
55+ let connect : ( ) => Promise < void > ;
56+ let disconnect : ( ) => Promise < void > ;
57+ let model : Model ;
58+
59+ beforeEach ( async ( ) => {
60+ ( { connect, element, model, disconnect } = await setup ( ) ) ;
4361 await connect ( ) ;
44- expect ( model . step1 . stepInternals . last ) . toBe ( true ) ;
45- expect ( model . step2 ) . toBe ( undefined ) ;
46- await disconnect ( ) ;
4762 } ) ;
4863
49- it ( 'configures stepInternals orientation default' , async ( ) => {
50- const model = new FixtureModel ( ) ;
51- const { connect, disconnect } = await setup ( model ) ;
52- await connect ( ) ;
53- expect ( model . step1 . stepInternals . orientation ) . toBe ( 'horizontal' ) ;
54- expect ( model . step2 ) . toBe ( undefined ) ;
64+ afterEach ( async ( ) => {
5565 await disconnect ( ) ;
5666 } ) ;
5767
58- it ( 'configures stepInternals orientation vertical set' , async ( ) => {
59- const model = new FixtureModel ( ) ;
60- const { connect, element, disconnect } = await setup ( model ) ;
68+ it ( 'configures stepInternals last' , ( ) => {
69+ expect ( model . step . stepInternals . last ) . toBe ( true ) ;
70+ } ) ;
71+
72+ it ( 'configures stepInternals orientation default' , ( ) => {
73+ expect ( model . step . stepInternals . orientation ) . toBe ( 'horizontal' ) ;
74+ } ) ;
75+
76+ it ( 'configures stepInternals orientation vertical' , async ( ) => {
6177 element . orientation = 'vertical' ;
62- await connect ( ) ;
63- expect ( model . step1 . stepInternals . orientation ) . toBe ( 'vertical' ) ;
64- expect ( model . step2 ) . toBe ( undefined ) ;
65- await disconnect ( ) ;
78+ await waitForUpdatesAsync ( ) ;
79+ expect ( model . step . stepInternals . orientation ) . toBe ( 'vertical' ) ;
6680 } ) ;
6781 } ) ;
6882
6983 describe ( 'count multiple' , ( ) => {
70- it ( 'to configure stepInternals last' , async ( ) => {
71- const model = new FixtureModel ( ) ;
72- model . multiple = true ;
73- const { connect, disconnect } = await setup ( model ) ;
84+ class Model {
85+ @observable public step1 ! : Step | AnchorStep ;
86+ public step1PageObject ! : StepBasePageObject ;
87+ @observable public step2 ! : Step | AnchorStep ;
88+ public step2PageObject ! : StepBasePageObject ;
89+ }
90+
91+ async function setup ( ) : Promise < Fixture < Stepper > & { model : Model } > {
92+ const model = new Model ( ) ;
93+ const result = await fixture < Stepper > (
94+ html < Model > `
95+ <${ stepperTag } >
96+ <${ value . stepTypeTag } ${ ref ( 'step1' ) } ></${ value . stepTypeTag } >
97+ <${ value . stepTypeTag } ${ ref ( 'step2' ) } ></${ value . stepTypeTag } >
98+ </${ stepperTag } >
99+ ` ,
100+ { source : model }
101+ ) ;
102+ model . step1PageObject = createStepPageObject ( model . step1 ) ;
103+ model . step2PageObject = createStepPageObject ( model . step2 ) ;
104+ return { ...result , model } ;
105+ }
106+
107+ let element : Stepper ;
108+ let connect : ( ) => Promise < void > ;
109+ let disconnect : ( ) => Promise < void > ;
110+ let model : Model ;
111+
112+ beforeEach ( async ( ) => {
113+ ( { connect, element, model, disconnect } = await setup ( ) ) ;
74114 await connect ( ) ;
75- expect ( model . step1 . stepInternals . last ) . toBe ( false ) ;
76- expect ( model . step2 ! . stepInternals . last ) . toBe ( true ) ;
115+ } ) ;
116+
117+ afterEach ( async ( ) => {
77118 await disconnect ( ) ;
78119 } ) ;
79120
80- it ( 'configures stepInternals orientation default' , async ( ) => {
81- const model = new FixtureModel ( ) ;
82- model . multiple = true ;
83- const { connect, disconnect } = await setup ( model ) ;
84- await connect ( ) ;
121+ it ( 'to configure stepInternals last' , ( ) => {
122+ expect ( model . step1 . stepInternals . last ) . toBe ( false ) ;
123+ expect ( model . step2 . stepInternals . last ) . toBe ( true ) ;
124+ } ) ;
125+
126+ it ( 'configures stepInternals orientation default' , ( ) => {
85127 expect ( model . step1 . stepInternals . orientation ) . toBe ( 'horizontal' ) ;
86- expect ( model . step2 ! . stepInternals . orientation ) . toBe ( 'horizontal' ) ;
87- await disconnect ( ) ;
128+ expect ( model . step2 . stepInternals . orientation ) . toBe ( 'horizontal' ) ;
88129 } ) ;
89130
90- it ( 'configures stepInternals orientation vertical set' , async ( ) => {
91- const model = new FixtureModel ( ) ;
92- model . multiple = true ;
93- const { connect, element, disconnect } = await setup ( model ) ;
131+ it ( 'configures stepInternals orientation vertical' , async ( ) => {
94132 element . orientation = 'vertical' ;
95- await connect ( ) ;
133+ await waitForUpdatesAsync ( ) ;
96134 expect ( model . step1 . stepInternals . orientation ) . toBe ( 'vertical' ) ;
97- expect ( model . step2 ! . stepInternals . orientation ) . toBe ( 'vertical' ) ;
135+ expect ( model . step2 . stepInternals . orientation ) . toBe ( 'vertical' ) ;
136+ } ) ;
137+ } ) ;
138+
139+ describe ( 'with label provider' , ( ) => {
140+ class Model {
141+ @observable public step ! : Step | AnchorStep ;
142+ public stepPageObject ! : StepBasePageObject ;
143+ @observable public labelProvider ! : LabelProviderCore ;
144+ }
145+
146+ async function setup ( ) : Promise < Fixture < Stepper > & { model : Model } > {
147+ const model = new Model ( ) ;
148+ const result = await fixture < Stepper > (
149+ html < Model > `
150+ <${ themeProviderTag } >
151+ <${ labelProviderCoreTag } ${ ref ( 'labelProvider' ) } ></${ labelProviderCoreTag } >
152+ <${ stepperTag } >
153+ <${ value . stepTypeTag } ${ ref ( 'step' ) } ></${ value . stepTypeTag } >
154+ </${ stepperTag } >
155+ </${ themeProviderTag } >
156+ ` ,
157+ { source : model }
158+ ) ;
159+ model . stepPageObject = createStepPageObject ( model . step ) ;
160+ return { ...result , model } ;
161+ }
162+
163+ let connect : ( ) => Promise < void > ;
164+ let disconnect : ( ) => Promise < void > ;
165+ let model : Model ;
166+
167+ beforeEach ( async ( ) => {
168+ ( { connect, model, disconnect } = await setup ( ) ) ;
169+ await connect ( ) ;
170+ } ) ;
171+
172+ afterEach ( async ( ) => {
98173 await disconnect ( ) ;
99174 } ) ;
175+
176+ it ( 'uses CoreLabelProvider popupIconCompleted for the error icon label' , async ( ) => {
177+ model . step . severity = Severity . error ;
178+ model . labelProvider . popupIconError = 'Custom error' ;
179+ await waitForUpdatesAsync ( ) ;
180+ expect ( model . stepPageObject . getErrorSeverityLabel ( ) ) . toBe ( 'Custom error' ) ;
181+ } ) ;
182+
183+ it ( 'uses CoreLabelProvider popupIconWarning for the warning icon label' , async ( ) => {
184+ model . step . severity = Severity . warning ;
185+ model . labelProvider . popupIconWarning = 'Custom warning' ;
186+ await waitForUpdatesAsync ( ) ;
187+ expect ( model . stepPageObject . getWarningSeverityLabel ( ) ) . toBe ( 'Custom warning' ) ;
188+ } ) ;
189+
190+ it ( 'uses CoreLabelProvider popupIconCompleted for the success icon label' , async ( ) => {
191+ model . step . severity = Severity . success ;
192+ model . labelProvider . popupIconCompleted = 'Custom success' ;
193+ await waitForUpdatesAsync ( ) ;
194+ expect ( model . stepPageObject . getSuccessSeverityLabel ( ) ) . toBe ( 'Custom success' ) ;
195+ } ) ;
196+
197+ it ( 'uses CoreLabelProvider popupIconCurrent for the success icon label' , async ( ) => {
198+ model . step . selected = true ;
199+ model . labelProvider . popupIconCurrent = 'Custom current' ;
200+ await waitForUpdatesAsync ( ) ;
201+ expect ( model . stepPageObject . getSelectedStateLabel ( ) ) . toBe ( 'Custom current' ) ;
202+ } ) ;
100203 } ) ;
101204 } ) ;
102205 } ) ;
0 commit comments