@@ -6,6 +6,7 @@ import { RowViewModelFactory } from '../../../src/viewModelFactories/rowViewMode
66import { Table } from '../../../src/models/table' ;
77import { Alignment } from '../../../src/models/alignment' ;
88import { Cell } from '../../../src/models/cell' ;
9+ import { AlignmentMarkerStrategy , IAlignmentMarker } from '../../../src/viewModelFactories/alignmentMarking' ;
910
1011suite ( "RowViewModelFactory.buildRow() tests" , ( ) => {
1112 let _contentPadCalculator : IMock < PadCalculator > ;
@@ -144,43 +145,23 @@ suite("RowViewModelFactory.buildSeparator() tests", () => {
144145 assert . equal ( separatorRowViewModel . getValueAt ( col ) , "----" ) ;
145146 } ) ;
146147
147- test ( "Left aligned column separator starts with :" , ( ) => {
148- const sut = createFactory ( _contentPadCalculator . object , _separatorPadCalculator . object ) ;
149- const table = threeColumnTable ( Alignment . Left ) ;
150-
151- _separatorPadCalculator . setup ( _ => _ . getLeftPadding ( It . isAny ( ) , It . isAny ( ) , It . isAny ( ) ) ) . returns ( ( ) => "--" ) ;
152- _separatorPadCalculator . setup ( _ => _ . getRightPadding ( It . isAny ( ) , It . isAny ( ) , It . isAny ( ) ) ) . returns ( ( ) => "--" ) ;
153-
154- const separatorRowViewModel = sut . buildSeparator ( table ) ;
155-
156- for ( let col = 0 ; col < separatorRowViewModel . columnCount ; col ++ )
157- assert . equal ( separatorRowViewModel . getValueAt ( col ) , ":---" ) ;
158- } ) ;
159-
160- test ( "Right aligned column separator ends with :" , ( ) => {
161- const sut = createFactory ( _contentPadCalculator . object , _separatorPadCalculator . object ) ;
162- const table = threeColumnTable ( Alignment . Right ) ;
163-
164- _separatorPadCalculator . setup ( _ => _ . getLeftPadding ( It . isAny ( ) , It . isAny ( ) , It . isAny ( ) ) ) . returns ( ( ) => "--" ) ;
165- _separatorPadCalculator . setup ( _ => _ . getRightPadding ( It . isAny ( ) , It . isAny ( ) , It . isAny ( ) ) ) . returns ( ( ) => "--" ) ;
166-
167- const separatorRowViewModel = sut . buildSeparator ( table ) ;
168-
169- for ( let col = 0 ; col < separatorRowViewModel . columnCount ; col ++ )
170- assert . equal ( separatorRowViewModel . getValueAt ( col ) , "---:" ) ;
171- } ) ;
148+ test ( "Calls alignment marker strategy and the marker returned from it" , ( ) => {
149+ const alignment = Alignment . Left ;
150+ let marker = Mock . ofType < IAlignmentMarker > ( ) ;
151+ marker . setup ( _ => _ . mark ( "abcd" ) ) . returns ( ( param ) => param ) . verifiable ( Times . exactly ( 3 ) ) ;
152+ let alignmentMarkerStrategy = Mock . ofType < AlignmentMarkerStrategy > ( ) ;
153+ alignmentMarkerStrategy . setup ( _ => _ . markerFor ( alignment ) ) . returns ( ( ) => marker . object ) . verifiable ( Times . exactly ( 3 ) ) ;
172154
173- test ( "Centrally aligned column separator starts and ends with :" , ( ) => {
174- const sut = createFactory ( _contentPadCalculator . object , _separatorPadCalculator . object ) ;
175- const table = threeColumnTable ( Alignment . Center ) ;
155+ const sut = createFactory ( _contentPadCalculator . object , _separatorPadCalculator . object , alignmentMarkerStrategy . object ) ;
156+ const table = threeColumnTable ( alignment ) ;
176157
177- _separatorPadCalculator . setup ( _ => _ . getLeftPadding ( It . isAny ( ) , It . isAny ( ) , It . isAny ( ) ) ) . returns ( ( ) => "-- " ) ;
178- _separatorPadCalculator . setup ( _ => _ . getRightPadding ( It . isAny ( ) , It . isAny ( ) , It . isAny ( ) ) ) . returns ( ( ) => "-- " ) ;
158+ _separatorPadCalculator . setup ( _ => _ . getLeftPadding ( It . isAny ( ) , It . isAny ( ) , It . isAny ( ) ) ) . returns ( ( ) => "ab " ) ;
159+ _separatorPadCalculator . setup ( _ => _ . getRightPadding ( It . isAny ( ) , It . isAny ( ) , It . isAny ( ) ) ) . returns ( ( ) => "cd " ) ;
179160
180- const separatorRowViewModel = sut . buildSeparator ( table ) ;
161+ sut . buildSeparator ( table ) ;
181162
182- for ( let col = 0 ; col < separatorRowViewModel . columnCount ; col ++ )
183- assert . equal ( separatorRowViewModel . getValueAt ( col ) , ":--:" ) ;
163+ marker . verifyAll ( ) ;
164+ alignmentMarkerStrategy . verifyAll ( ) ;
184165 } ) ;
185166} ) ;
186167
@@ -204,6 +185,9 @@ function tableFor(rows: string[][], alignment: Alignment) {
204185 return table ;
205186}
206187
207- function createFactory ( contentPadCalculator : PadCalculator , separatorPadCalculator : PadCalculator ) : RowViewModelFactory {
208- return new RowViewModelFactory ( contentPadCalculator , separatorPadCalculator ) ;
188+ function createFactory ( contentPadCalculator : PadCalculator , separatorPadCalculator : PadCalculator ,
189+ alignmentStrategy : AlignmentMarkerStrategy = null ) : RowViewModelFactory
190+ {
191+ alignmentStrategy = alignmentStrategy == null ? new AlignmentMarkerStrategy ( ) : alignmentStrategy ;
192+ return new RowViewModelFactory ( contentPadCalculator , separatorPadCalculator , alignmentStrategy ) ;
209193}
0 commit comments