1
+ const SDL = require ( '../../config.js' ) . node ;
2
+
3
+ // Mocking framework
4
+ // Used to stub an RPC call so that it isn't actually sent to Core
5
+ const sinon = require ( 'sinon' ) ;
6
+
7
+ const Validator = require ( '../../Validator' ) ;
8
+
9
+ module . exports = async function ( appClient ) {
10
+ describe ( 'TextAndGraphicManagerTests' , function ( ) {
11
+ const sdlManager = appClient . _sdlManager ;
12
+ const textAndGraphicManager = sdlManager . getScreenManager ( ) . _textAndGraphicManager ;
13
+ const lifecycleManager = sdlManager . _lifecycleManager ;
14
+ const testArtwork1 = new SDL . manager . file . filetypes . SdlArtwork ( 'sdl-logo' , SDL . rpc . enums . FileType . GRAPHIC_PNG )
15
+ . setFilePath ( `${ __dirname } /test_icon_1.png` ) ;
16
+ const testArtwork2 = new SDL . manager . file . filetypes . SdlArtwork ( 'sdl-logo2' , SDL . rpc . enums . FileType . GRAPHIC_PNG )
17
+ . setFilePath ( `${ __dirname } /test_icon_2.png` ) ;
18
+ const configuration1 = new SDL . rpc . structs . TemplateConfiguration ( ) . setTemplate ( SDL . rpc . enums . PredefinedLayout . GRAPHIC_WITH_TEXT ) ;
19
+ const configuration2 = new SDL . rpc . structs . TemplateConfiguration ( ) . setTemplate ( SDL . rpc . enums . PredefinedLayout . DOUBLE_GRAPHIC_WITH_SOFTBUTTONS ) ;
20
+ const blankScreenData = textAndGraphicManager . _currentState ( ) ;
21
+
22
+ /**
23
+ * Returns an empty WindowCapability
24
+ * @returns {WindowCapability } - An empty WindowCapability struct
25
+ */
26
+ function getNullVarWindowCapability ( ) {
27
+ return new SDL . rpc . structs . WindowCapability ( ) ;
28
+ }
29
+
30
+ /**
31
+ * Builds a WindowCapability structs with a specified number of lines
32
+ * @param {Number } numberOfMainFields - The number of lines for the WindowCapability to support
33
+ * @returns {WindowCapability } - The desire window capability
34
+ */
35
+ function getWindowCapability ( numberOfMainFields ) {
36
+ const mainField1 = new SDL . rpc . structs . TextField ( ) ;
37
+ mainField1 . setNameParam ( SDL . rpc . enums . TextFieldName . mainField1 ) ;
38
+ const mainField2 = new SDL . rpc . structs . TextField ( ) ;
39
+ mainField2 . setNameParam ( SDL . rpc . enums . TextFieldName . mainField2 ) ;
40
+ const mainField3 = new SDL . rpc . structs . TextField ( ) ;
41
+ mainField3 . setNameParam ( SDL . rpc . enums . TextFieldName . mainField3 ) ;
42
+ const mainField4 = new SDL . rpc . structs . TextField ( ) ;
43
+ mainField4 . setNameParam ( SDL . rpc . enums . TextFieldName . mainField4 ) ;
44
+
45
+ const textFieldList = [ ] ;
46
+
47
+ textFieldList . push ( mainField1 ) ;
48
+ textFieldList . push ( mainField2 ) ;
49
+ textFieldList . push ( mainField3 ) ;
50
+ textFieldList . push ( mainField4 ) ;
51
+
52
+ const returnList = [ ] ;
53
+
54
+ if ( numberOfMainFields > 0 ) {
55
+ for ( let iterator = 0 ; iterator < numberOfMainFields ; iterator ++ ) {
56
+ returnList . push ( textFieldList [ iterator ] ) ;
57
+ }
58
+ }
59
+
60
+ const windowCapability = new SDL . rpc . structs . WindowCapability ( ) ;
61
+ windowCapability . setTextFields ( returnList ) ;
62
+
63
+ return windowCapability ;
64
+ }
65
+
66
+ /**
67
+ * Handle Show successes.
68
+ * @returns {Promise } - A promise.
69
+ */
70
+ function onShowSuccess ( ) {
71
+ const responseSuccess = new SDL . rpc . messages . ShowResponse ( {
72
+ functionName : SDL . rpc . enums . FunctionID . ShowResponse ,
73
+ } )
74
+ . setSuccess ( true ) ;
75
+ // _handleRpc triggers the listener
76
+ sdlManager . _lifecycleManager . _handleRpc ( responseSuccess ) ;
77
+
78
+ return new Promise ( ( resolve , reject ) => {
79
+ resolve ( responseSuccess ) ;
80
+ } ) ;
81
+ }
82
+
83
+ it ( 'testInstantiation' , function ( done ) {
84
+ Validator . assertNull ( textAndGraphicManager . getTextField1 ( ) ) ;
85
+ Validator . assertNull ( textAndGraphicManager . getTextField2 ( ) ) ;
86
+ Validator . assertNull ( textAndGraphicManager . getTextField3 ( ) ) ;
87
+ Validator . assertNull ( textAndGraphicManager . getTextField4 ( ) ) ;
88
+ Validator . assertNull ( textAndGraphicManager . getTitle ( ) ) ;
89
+ Validator . assertNull ( textAndGraphicManager . getMediaTrackTextField ( ) ) ;
90
+ Validator . assertNull ( textAndGraphicManager . getPrimaryGraphic ( ) ) ;
91
+ Validator . assertNull ( textAndGraphicManager . getSecondaryGraphic ( ) ) ;
92
+ Validator . assertEquals ( textAndGraphicManager . getTextAlignment ( ) , null ) ;
93
+ Validator . assertNull ( textAndGraphicManager . getTextField1Type ( ) ) ;
94
+ Validator . assertNull ( textAndGraphicManager . getTextField2Type ( ) ) ;
95
+ Validator . assertNull ( textAndGraphicManager . getTextField3Type ( ) ) ;
96
+ Validator . assertNull ( textAndGraphicManager . getTextField4Type ( ) ) ;
97
+ Validator . assertNotNull ( textAndGraphicManager . _currentScreenData ) ;
98
+ Validator . assertNotNull ( textAndGraphicManager . _defaultMainWindowCapability ) ;
99
+ Validator . assertTrue ( ! textAndGraphicManager . _isDirty ) ;
100
+ Validator . assertNotNull ( textAndGraphicManager . _getBlankArtwork ( ) ) ;
101
+ done ( ) ;
102
+ } ) ;
103
+
104
+ it ( 'testGetMainLines' , function ( done ) {
105
+ // We want to test that the looping works. By default, it will return 4 if display cap is null
106
+ let defaultMainWindowCapability = getNullVarWindowCapability ( ) ;
107
+
108
+ // Null test
109
+ Validator . assertEquals ( 0 , SDL . manager . _ManagerUtility . getMaxNumberOfMainFieldLines ( defaultMainWindowCapability ) ) ;
110
+
111
+ defaultMainWindowCapability = getWindowCapability ( 3 ) ;
112
+ Validator . assertEquals ( SDL . manager . _ManagerUtility . getMaxNumberOfMainFieldLines ( defaultMainWindowCapability ) , 3 ) ;
113
+ done ( ) ;
114
+ } ) ;
115
+
116
+ it ( 'testMediaTrackTextField' , function ( done ) {
117
+ const stub = sinon . stub ( lifecycleManager , 'sendRpcResolve' )
118
+ . callsFake ( onShowSuccess ) ;
119
+ const songTitle = 'Wild For The Night' ;
120
+ textAndGraphicManager . setMediaTrackTextField ( songTitle ) ;
121
+ Validator . assertEquals ( textAndGraphicManager . getMediaTrackTextField ( ) , songTitle ) ;
122
+ stub . restore ( ) ;
123
+ done ( ) ;
124
+ } ) ;
125
+
126
+ it ( 'testTemplateTitle' , function ( done ) {
127
+ const stub = sinon . stub ( lifecycleManager , 'sendRpcResolve' )
128
+ . callsFake ( onShowSuccess ) ;
129
+ const title = 'template title' ;
130
+ textAndGraphicManager . setTitle ( title ) ;
131
+ Validator . assertEquals ( textAndGraphicManager . getTitle ( ) , title ) ;
132
+ stub . restore ( ) ;
133
+ done ( ) ;
134
+ } ) ;
135
+
136
+ it ( 'testAlignment' , function ( done ) {
137
+ const stub = sinon . stub ( lifecycleManager , 'sendRpcResolve' )
138
+ . callsFake ( onShowSuccess ) ;
139
+ textAndGraphicManager . setTextAlignment ( SDL . rpc . enums . TextAlignment . LEFT_ALIGNED ) ;
140
+ Validator . assertEquals ( textAndGraphicManager . getTextAlignment ( ) , SDL . rpc . enums . TextAlignment . LEFT_ALIGNED ) ;
141
+ stub . restore ( ) ;
142
+ done ( ) ;
143
+ } ) ;
144
+
145
+ it ( 'testSetPrimaryGraphic' , function ( done ) {
146
+ const stub = sinon . stub ( lifecycleManager , 'sendRpcResolve' )
147
+ . callsFake ( onShowSuccess ) ;
148
+ textAndGraphicManager . setPrimaryGraphic ( testArtwork1 ) ;
149
+ Validator . assertEquals ( textAndGraphicManager . getPrimaryGraphic ( ) , testArtwork1 ) ;
150
+ stub . restore ( ) ;
151
+ done ( ) ;
152
+ } ) ;
153
+
154
+ it ( 'testSetSecondaryGraphic' , function ( done ) {
155
+ const stub = sinon . stub ( lifecycleManager , 'sendRpcResolve' )
156
+ . callsFake ( onShowSuccess ) ;
157
+ textAndGraphicManager . setSecondaryGraphic ( testArtwork1 ) ;
158
+ Validator . assertEquals ( textAndGraphicManager . getSecondaryGraphic ( ) , testArtwork1 ) ;
159
+ stub . restore ( ) ;
160
+ done ( ) ;
161
+ } ) ;
162
+
163
+ it ( 'resetFieldsToCurrentScreenDataTest' , function ( done ) {
164
+ const stub = sinon . stub ( lifecycleManager , 'sendRpcResolve' )
165
+ . callsFake ( onShowSuccess ) ;
166
+ textAndGraphicManager . setTextField1 ( 'textField1' ) ;
167
+ textAndGraphicManager . setTextField2 ( 'textField2' ) ;
168
+ textAndGraphicManager . setTextField3 ( 'textField3' ) ;
169
+ textAndGraphicManager . setTextField4 ( 'textField4' ) ;
170
+ textAndGraphicManager . setMediaTrackTextField ( 'mediaTrackTextField' ) ;
171
+ textAndGraphicManager . setTitle ( 'title' ) ;
172
+ textAndGraphicManager . setPrimaryGraphic ( testArtwork1 ) ;
173
+ textAndGraphicManager . setSecondaryGraphic ( testArtwork1 ) ;
174
+ textAndGraphicManager . changeLayout ( configuration1 ) ;
175
+ const currentScreenData = textAndGraphicManager . _currentState ( ) ;
176
+
177
+ Validator . assertEquals ( currentScreenData . getTextField1 ( ) , textAndGraphicManager . getTextField1 ( ) ) ;
178
+ Validator . assertEquals ( currentScreenData . getTextField2 ( ) , textAndGraphicManager . getTextField2 ( ) ) ;
179
+ Validator . assertEquals ( currentScreenData . getTextField3 ( ) , textAndGraphicManager . getTextField3 ( ) ) ;
180
+ Validator . assertEquals ( currentScreenData . getTextField4 ( ) , textAndGraphicManager . getTextField4 ( ) ) ;
181
+ Validator . assertEquals ( currentScreenData . getTitle ( ) , textAndGraphicManager . getTitle ( ) ) ;
182
+ Validator . assertEquals ( currentScreenData . getMediaTrackTextField ( ) , textAndGraphicManager . getMediaTrackTextField ( ) ) ;
183
+ Validator . assertEquals ( currentScreenData . getPrimaryGraphic ( ) . getName ( ) , textAndGraphicManager . getPrimaryGraphic ( ) . getName ( ) ) ;
184
+ Validator . assertEquals ( currentScreenData . getSecondaryGraphic ( ) . getName ( ) , textAndGraphicManager . getSecondaryGraphic ( ) . getName ( ) ) ;
185
+ Validator . assertEquals ( currentScreenData . getTemplateConfiguration ( ) . getParameters ( ) , textAndGraphicManager . getTemplateConfiguration ( ) . getParameters ( ) ) ;
186
+
187
+ textAndGraphicManager . setTextField1 ( 'BadData' ) ;
188
+ textAndGraphicManager . setTextField2 ( 'BadData' ) ;
189
+ textAndGraphicManager . setTextField3 ( 'BadData' ) ;
190
+ textAndGraphicManager . setTextField4 ( 'BadData' ) ;
191
+ textAndGraphicManager . setMediaTrackTextField ( 'BadData' ) ;
192
+ textAndGraphicManager . setTitle ( 'BadData' ) ;
193
+ textAndGraphicManager . setPrimaryGraphic ( testArtwork2 ) ;
194
+ textAndGraphicManager . setSecondaryGraphic ( testArtwork2 ) ;
195
+ textAndGraphicManager . changeLayout ( configuration2 ) ;
196
+
197
+ Validator . assertTrue ( currentScreenData . getTextField1 ( ) !== textAndGraphicManager . getTextField1 ( ) ) ;
198
+ Validator . assertTrue ( currentScreenData . getTextField2 ( ) !== textAndGraphicManager . getTextField2 ( ) ) ;
199
+ Validator . assertTrue ( currentScreenData . getTextField3 ( ) !== textAndGraphicManager . getTextField3 ( ) ) ;
200
+ Validator . assertTrue ( currentScreenData . getTextField4 ( ) !== textAndGraphicManager . getTextField4 ( ) ) ;
201
+ Validator . assertTrue ( currentScreenData . getTitle ( ) !== textAndGraphicManager . getTitle ( ) ) ;
202
+ Validator . assertTrue ( currentScreenData . getMediaTrackTextField ( ) !== textAndGraphicManager . getMediaTrackTextField ( ) ) ;
203
+ Validator . assertTrue ( currentScreenData . getPrimaryGraphic ( ) . getName ( ) !== textAndGraphicManager . getPrimaryGraphic ( ) . getName ( ) ) ;
204
+ Validator . assertTrue ( currentScreenData . getSecondaryGraphic ( ) . getName ( ) !== textAndGraphicManager . getSecondaryGraphic ( ) . getName ( ) ) ;
205
+ Validator . assertTrue ( currentScreenData . getTemplateConfiguration ( ) . getParameters ( ) !== textAndGraphicManager . getTemplateConfiguration ( ) . getParameters ( ) ) ;
206
+
207
+ textAndGraphicManager . _currentScreenData = currentScreenData ;
208
+ textAndGraphicManager . _resetFieldsToCurrentScreenData ( ) ;
209
+
210
+ Validator . assertTrue ( textAndGraphicManager . _currentScreenData . getTextField1 ( ) === textAndGraphicManager . getTextField1 ( ) ) ;
211
+ Validator . assertTrue ( textAndGraphicManager . _currentScreenData . getTextField2 ( ) === textAndGraphicManager . getTextField2 ( ) ) ;
212
+ Validator . assertTrue ( textAndGraphicManager . _currentScreenData . getTextField3 ( ) === textAndGraphicManager . getTextField3 ( ) ) ;
213
+ Validator . assertTrue ( textAndGraphicManager . _currentScreenData . getTextField4 ( ) === textAndGraphicManager . getTextField4 ( ) ) ;
214
+ Validator . assertTrue ( textAndGraphicManager . _currentScreenData . getTitle ( ) === textAndGraphicManager . getTitle ( ) ) ;
215
+ Validator . assertTrue ( textAndGraphicManager . _currentScreenData . getMediaTrackTextField ( ) === textAndGraphicManager . getMediaTrackTextField ( ) ) ;
216
+ Validator . assertTrue ( textAndGraphicManager . _currentScreenData . getPrimaryGraphic ( ) . getName ( ) === textAndGraphicManager . getPrimaryGraphic ( ) . getName ( ) ) ;
217
+ Validator . assertTrue ( textAndGraphicManager . _currentScreenData . getSecondaryGraphic ( ) . getName ( ) === textAndGraphicManager . getSecondaryGraphic ( ) . getName ( ) ) ;
218
+ Validator . assertTrue ( textAndGraphicManager . _currentScreenData . getTemplateConfiguration ( ) . getParameters ( ) === textAndGraphicManager . getTemplateConfiguration ( ) . getParameters ( ) ) ;
219
+
220
+ // reset screen data for other tests
221
+ textAndGraphicManager . _currentScreenData = blankScreenData ;
222
+ textAndGraphicManager . _resetFieldsToCurrentScreenData ( ) ;
223
+ stub . restore ( ) ;
224
+ done ( ) ;
225
+ } ) ;
226
+ } ) ;
227
+ } ;
0 commit comments