@@ -120,18 +120,55 @@ describeWithMockConnection('CSSValueTraceView', () => {
120120 }
121121 } ) ;
122122
123- it ( 'does not have substitutions yet ' , async ( ) => {
123+ it ( 'applies substitutions' , async ( ) => {
124124 const { matchedStyles, stylesPane} = await setUpStyles ( ) ;
125125 const { property, treeElement} =
126- await getTreeElement ( matchedStyles , stylesPane , 'width' , 'var(--w)' , { '--w' : { value : '40em' } } ) ;
126+ await getTreeElement ( matchedStyles , stylesPane , 'width' , 'var(--w)' , { '--w' : { value : '40px' } } ) ;
127+ const input = await showTrace ( property , matchedStyles , treeElement ) ;
128+ const substitutions = input . substitutions . map ( nodes => nodes . map ( node => node . textContent ?? '' ) . join ( ) ) ;
129+ const evaluations = input . evaluations . map ( nodes => nodes . map ( node => node . textContent ?? '' ) . join ( ) ) ;
130+ const result = input . finalResult ?. map ( node => node . textContent ?? '' ) . join ( ) ;
131+ assert . deepEqual ( substitutions , [ ] ) ;
132+ assert . deepEqual ( evaluations , [ ] ) ;
133+ assert . deepEqual ( result , '40px' ) ;
134+ } ) ;
135+
136+ it ( 'substitutes the variable declaration if the variable is found (with fallback)' , async ( ) => {
137+ const { matchedStyles, stylesPane} = await setUpStyles ( ) ;
138+ const { property, treeElement} =
139+ await getTreeElement ( matchedStyles , stylesPane , 'width' , 'var(--w, 10px)' , { '--w' : { value : '40px' } } ) ;
140+ const input = await showTrace ( property , matchedStyles , treeElement ) ;
141+ const substitutions = input . substitutions . map ( nodes => nodes . map ( node => node . textContent ?? '' ) . join ( ) ) ;
142+ const evaluations = input . evaluations . map ( nodes => nodes . map ( node => node . textContent ?? '' ) . join ( ) ) ;
143+ const result = input . finalResult ?. map ( node => node . textContent ?? '' ) . join ( ) ;
144+ assert . deepEqual ( substitutions , [ ] ) ;
145+ assert . deepEqual ( evaluations , [ ] ) ;
146+ assert . deepEqual ( result , '40px' ) ;
147+ } ) ;
148+
149+ it ( 'substitutes the fallback if the variable is found' , async ( ) => {
150+ const { matchedStyles, stylesPane} = await setUpStyles ( ) ;
151+ const { property, treeElement} = await getTreeElement ( matchedStyles , stylesPane , 'width' , 'var(--w, 10px)' ) ;
152+ const input = await showTrace ( property , matchedStyles , treeElement ) ;
153+ const substitutions = input . substitutions . map ( nodes => nodes . map ( node => node . textContent ?? '' ) . join ( ) ) ;
154+ const evaluations = input . evaluations . map ( nodes => nodes . map ( node => node . textContent ?? '' ) . join ( ) ) ;
155+ const result = input . finalResult ?. map ( node => node . textContent ?? '' ) . join ( ) ;
156+ assert . deepEqual ( substitutions , [ ] ) ;
157+ assert . deepEqual ( evaluations , [ ] ) ;
158+ assert . deepEqual ( result , '10px' ) ;
159+ } ) ;
160+
161+ it ( 'shows chains of substitutions' , async ( ) => {
162+ const { matchedStyles, stylesPane} = await setUpStyles ( ) ;
163+ const { property, treeElement} = await getTreeElement (
164+ matchedStyles , stylesPane , 'width' , 'var(--v)' , { '--w' : { value : '40px' } , '--v' : { value : 'var(--w)' } } ) ;
127165 const input = await showTrace ( property , matchedStyles , treeElement ) ;
128166 const substitutions = input . substitutions . map ( nodes => nodes . map ( node => node . textContent ?? '' ) . join ( ) ) ;
129167 const evaluations = input . evaluations . map ( nodes => nodes . map ( node => node . textContent ?? '' ) . join ( ) ) ;
130168 const result = input . finalResult ?. map ( node => node . textContent ?? '' ) . join ( ) ;
131- // TODO(pfaffe) once vars actually substitute this needs to show the first line
132169 assert . deepEqual ( substitutions , [ 'var(--w)' ] ) ;
133170 assert . deepEqual ( evaluations , [ ] ) ;
134- assert . deepEqual ( result , 'var(--w) ' ) ;
171+ assert . deepEqual ( result , '40px ' ) ;
135172 } ) ;
136173
137174 it ( 'shows intermediate evaluation steps' , async ( ) => {
0 commit comments