@@ -23,12 +23,14 @@ module.exports = function (appClient) {
2323 speechCapabilities ,
2424 alertCompletionListener ,
2525 alertSoftButtonClearListener ;
26+
2627 /**
2728 * Gets the windowCapability
2829 * @param {Number } numberOfAlertFields - number of lines
30+ * @param {Boolean } supportsAlertIcon - whether alert icon is supported by the capability
2931 * @returns {WindowCapability } - the capability
3032 */
31- function getWindowCapability ( numberOfAlertFields ) {
33+ function getWindowCapability ( numberOfAlertFields , supportsAlertIcon ) {
3234 const alertText1 = new SDL . rpc . structs . TextField ( ) ;
3335 alertText1 . setNameParam ( SDL . rpc . enums . TextFieldName . alertText1 ) ;
3436 const alertText2 = new SDL . rpc . structs . TextField ( ) ;
@@ -55,13 +57,13 @@ module.exports = function (appClient) {
5557 const windowCapability = new SDL . rpc . structs . WindowCapability ( ) ;
5658 windowCapability . setTextFields ( returnList ) ;
5759
58- const imageField = new SDL . rpc . structs . ImageField ( ) ;
59- imageField . setNameParam ( SDL . rpc . enums . ImageFieldName . alertIcon ) ;
60- const imageFieldList = [ ] ;
61- imageFieldList . push ( imageField ) ;
62- windowCapability . setImageFields ( imageFieldList ) ;
63-
64- windowCapability . setImageFields ( imageFieldList ) ;
60+ if ( supportsAlertIcon ) {
61+ const imageField = new SDL . rpc . structs . ImageField ( ) ;
62+ imageField . setNameParam ( SDL . rpc . enums . ImageFieldName . alertIcon ) ;
63+ const imageFieldList = [ ] ;
64+ imageFieldList . push ( imageField ) ;
65+ windowCapability . setImageFields ( imageFieldList ) ;
66+ }
6567
6668 const softButtonCapabilities = new SDL . rpc . structs . SoftButtonCapabilities ( ) ;
6769 softButtonCapabilities . setImageSupported ( true ) ;
@@ -135,7 +137,7 @@ module.exports = function (appClient) {
135137 alertView . setShowWaitIndicator ( true ) ;
136138 alertView . canceledListener = ( ) => { } ;
137139
138- defaultMainWindowCapability = getWindowCapability ( 3 ) ;
140+ defaultMainWindowCapability = getWindowCapability ( 3 , true ) ;
139141 speechCapabilities = [ ] ;
140142 speechCapabilities . push ( SDL . rpc . enums . SpeechCapabilities . FILE ) ;
141143 alertCompletionListener = new SDL . manager . screen . utils . AlertCompletionListener ( ) . setOnComplete ( ( success , tryAgainTime ) => { } ) ;
@@ -158,13 +160,13 @@ module.exports = function (appClient) {
158160 . setMinorVersion ( 0 )
159161 . setPatchVersion ( 0 ) ;
160162 } ) ;
161- let windowCapability = getWindowCapability ( 1 ) ;
163+ let windowCapability = getWindowCapability ( 1 , true ) ;
162164 let presentAlertOperation = new SDL . manager . screen . utils . _PresentAlertOperation ( lifecycleManager , alertView , windowCapability , speechCapabilities , fileManager , 1 , ( ) => { } , new SDL . manager . screen . _AlertManagerBase . _AlertSoftButtonClearListener ( ) . setOnButtonClear ( ( ) => { } ) ) ;
163165 let alert = presentAlertOperation . alertRpc ( ) ;
164166
165167 Validator . assertEquals ( alert . getAlertText1 ( ) , `${ alertView . getText ( ) } - ${ alertView . getSecondaryText ( ) } - ${ alertView . getTertiaryText ( ) } ` ) ;
166168
167- windowCapability = getWindowCapability ( 2 ) ;
169+ windowCapability = getWindowCapability ( 2 , true ) ;
168170
169171 presentAlertOperation = new SDL . manager . screen . utils . _PresentAlertOperation ( lifecycleManager , alertView , windowCapability , speechCapabilities , fileManager , 1 , ( ) => { } , new SDL . manager . screen . _AlertManagerBase . _AlertSoftButtonClearListener ( ) . setOnButtonClear ( ( ) => { } ) ) ;
170172 alert = presentAlertOperation . alertRpc ( ) ;
@@ -199,7 +201,7 @@ module.exports = function (appClient) {
199201 // Test Images need to be uploaded, sending text and uploading images
200202 await presentAlertOperation . onExecute ( ) ;
201203
202- // Verifies that uploadArtworks gets called only with the fist presentAlertOperation.onExecute call
204+ // Verifies that uploadArtworks gets called only with the first presentAlertOperation.onExecute call
203205 Validator . assertTrue ( artStub . calledOnce ) ;
204206 Validator . assertTrue ( fileStub . calledOnce ) ;
205207 Validator . assertTrue ( alertStub . calledOnce ) ;
@@ -234,7 +236,7 @@ module.exports = function (appClient) {
234236 // Test Images need to be uploaded, sending text and uploading images
235237 await presentAlertOperation . _start ( ) ;
236238
237- // Verifies that uploadArtworks gets called only with the fist presentAlertOperation.onExecute call
239+ // Verifies that uploadArtworks gets called only with the first presentAlertOperation.onExecute call
238240 Validator . assertTrue ( artStub . notCalled ) ;
239241 Validator . assertTrue ( fileStub . notCalled ) ;
240242 Validator . assertTrue ( alertStub . calledOnce ) ;
@@ -262,7 +264,7 @@ module.exports = function (appClient) {
262264 // Test Images need to be uploaded, sending text and uploading images
263265 await presentAlertOperation . _start ( ) ;
264266
265- // Verifies that uploadArtworks gets called only with the fist presentAlertOperation.onExecute call
267+ // Verifies that uploadArtworks gets called only with the first presentAlertOperation.onExecute call
266268 Validator . assertTrue ( artStub . calledOnce ) ;
267269 Validator . assertTrue ( alertStub . calledOnce ) ;
268270
@@ -281,5 +283,51 @@ module.exports = function (appClient) {
281283 Validator . assertTrue ( callback . notCalled ) ;
282284 stub . restore ( ) ;
283285 } ) ;
286+
287+ it ( 'testNoImageSetOnFailedUpload' , async function ( ) {
288+ const alertRpc = presentAlertOperation . alertRpc ( ) ;
289+ Validator . assertNull ( alertRpc . getAlertIcon ( ) ) ;
290+ } ) ;
291+
292+ it ( 'testImageSetOnSuccessfulUpload' , async function ( ) {
293+ presentAlertOperation . _alertIconUploaded = true ;
294+ const alertRpc = presentAlertOperation . alertRpc ( ) ;
295+ Validator . assertEquals ( alertRpc . getAlertIcon ( ) . getValueParam ( ) , alertView . getIcon ( ) . getName ( ) ) ;
296+ } ) ;
297+
298+ it ( 'testPresentStaticIcon' , async function ( ) {
299+ const alertStub = sinon . stub ( lifecycleManager , 'sendRpcResolve' )
300+ . callsFake ( onAlertSuccess ) ;
301+ const artStub = sinon . stub ( fileManager , 'uploadArtworks' )
302+ . callsFake ( onArtworkUploadSuccess ) ;
303+ const fileStub = sinon . stub ( fileManager , 'uploadFiles' )
304+ . callsFake ( onArtworkUploadSuccess ) ;
305+ const versionStub = sinon . stub ( lifecycleManager , 'getSdlMsgVersion' )
306+ . callsFake ( function ( ) {
307+ return new SDL . rpc . structs . SdlMsgVersion ( )
308+ . setMajorVersion ( 6 )
309+ . setMinorVersion ( 0 )
310+ . setPatchVersion ( 0 ) ;
311+ } ) ;
312+
313+
314+ testAlertArtwork = new SDL . manager . file . filetypes . SdlArtwork ( SDL . manager . file . enums . StaticIconName . LEFT ) ;
315+ testAlertArtwork . setStaticIcon ( true ) ;
316+ alertView . setIcon ( testAlertArtwork ) ;
317+ alertView . setSoftButtons ( [ ] ) ;
318+
319+ presentAlertOperation = new SDL . manager . screen . utils . _PresentAlertOperation ( lifecycleManager , alertView , defaultMainWindowCapability , speechCapabilities , fileManager , 1 , alertCompletionListener , alertSoftButtonClearListener ) ;
320+ // Test Images need to be uploaded, sending text and uploading images
321+ await presentAlertOperation . _start ( ) ;
322+
323+ // upload artworks should not be called since this is a static icon
324+ Validator . assertTrue ( artStub . notCalled ) ;
325+ Validator . assertTrue ( alertStub . calledOnce ) ;
326+
327+ versionStub . restore ( ) ;
328+ fileStub . restore ( ) ;
329+ artStub . restore ( ) ;
330+ alertStub . restore ( ) ;
331+ } ) ;
284332 } ) ;
285333} ;
0 commit comments