Skip to content

Commit 3181cd5

Browse files
authored
Merge pull request #332 from smartdevicelink/feature/text_and_graphic_tests
Update unit tests to cover TextAndGraphicManager and TextAndGraphicUp…
2 parents 573bf27 + 92c7abf commit 3181cd5

File tree

5 files changed

+1179
-8
lines changed

5 files changed

+1179
-8
lines changed

lib/js/src/manager/screen/_TextAndGraphicUpdateOperation.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -139,14 +139,14 @@ class _TextAndGraphicUpdateOperation extends _Task {
139139
this._updateCurrentScreenDataFromShow(show);
140140
} else {
141141
console.info('Text and Graphic Show failed');
142-
this._currentScreenDataUpdateListener(() => {
142+
this._currentScreenDataUpdateListener(async () => {
143143
throw new Error('Text and Graphic Show failed');
144144
});
145145
}
146146
return response.getSuccess();
147147
} else {
148148
console.info('LifecycleManager is null, Text and Graphic update failed');
149-
this._currentScreenDataUpdateListener(() => {
149+
this._currentScreenDataUpdateListener(async () => {
150150
throw new Error('LifecycleManager is null, Text and Graphic update failed');
151151
});
152152
this._finishOperation(false);
@@ -155,22 +155,22 @@ class _TextAndGraphicUpdateOperation extends _Task {
155155
}
156156

157157
async _sendSetDisplayLayoutWithTemplateConfiguration (configuration) {
158-
const setLayout = new SetDisplayLayout(configuration.getTemplate()).setDayColorScheme(configuration.getDayColorScheme()).setNightColorScheme(configuration.getNightColorScheme());
158+
const setLayout = new SetDisplayLayout().setDisplayLayout(configuration.getTemplate()).setDayColorScheme(configuration.getDayColorScheme()).setNightColorScheme(configuration.getNightColorScheme());
159159
if (this._lifecycleManager !== null) {
160160
const response = await this._lifecycleManager.sendRpcResolve(setLayout);
161161
if (response.getSuccess()) {
162162
console.info('Text and Graphic update complete');
163163
this._updateCurrentScreenDataFromSetDisplayLayout(setLayout);
164164
} else {
165165
console.info('Text and Graphic SetDisplayLayout failed');
166-
this._currentScreenDataUpdateListener(() => {
166+
this._currentScreenDataUpdateListener(async () => {
167167
throw new Error('Text and Graphic SetDisplayLayout failed');
168168
});
169169
}
170170
return response.getSuccess();
171171
} else {
172172
console.info('LifecycleManager is null, Text and Graphic update failed');
173-
this._currentScreenDataUpdateListener(() => {
173+
this._currentScreenDataUpdateListener(async () => {
174174
throw new Error('LifecycleManager is null, Text and Graphic update failed');
175175
});
176176
this._finishOperation(false);
@@ -289,7 +289,7 @@ class _TextAndGraphicUpdateOperation extends _Task {
289289
return show;
290290
}
291291

292-
const numberOfLines = (this._defaultMainWindowCapability === null && this._defaultMainWindowCapability === undefined) || this._shouldUpdateTemplateConfig() ? 4 : _ManagerUtility.getMaxNumberOfMainFieldLines(this._defaultMainWindowCapability);
292+
const numberOfLines = (this._defaultMainWindowCapability === null || this._defaultMainWindowCapability === undefined) || this._shouldUpdateTemplateConfig() ? 4 : _ManagerUtility.getMaxNumberOfMainFieldLines(this._defaultMainWindowCapability);
293293
switch (numberOfLines) {
294294
case 1:
295295
show = this._assembleOneLineShowText(show, nonNullFields);
@@ -399,7 +399,7 @@ class _TextAndGraphicUpdateOperation extends _Task {
399399
const typeList = [];
400400
typeList.push(this._updatedState.getTextField4Type());
401401
if (this._updatedState.getTextField3Type() !== null && this._updatedState.getTextField3Type() !== undefined) {
402-
typeList.add(this._updatedState.getTextField3Type());
402+
typeList.push(this._updatedState.getTextField3Type());
403403
}
404404
tags.setMainField2(typeList);
405405
}
@@ -455,7 +455,7 @@ class _TextAndGraphicUpdateOperation extends _Task {
455455
if (this._updatedState.getTextField4() !== null && this._updatedState.getTextField4() !== undefined && this._updatedState.getTextField4().length > 0) {
456456
if (this._updatedState.getTextField3() !== null && this._updatedState.getTextField3() !== undefined && this._updatedState.getTextField3().length > 0) {
457457
// If text 3 exists, put it in slot 3 formatted
458-
tempString = `${tempString} - ${this._updatedState.getTextField4()}`;
458+
tempString = `${tempString} - ${this._updatedState.getTextField4()}`;
459459
if (this._updatedState.getTextField4Type() !== null && this._updatedState.getTextField4Type() !== undefined) {
460460
const tags4 = [];
461461
if (this._updatedState.getTextField3Type() !== null && this._updatedState.getTextField3Type() !== undefined) {

tests/managers/index.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ const lifecycleManagerTests = require('./lifecycle/LifecycleManagerTests');
77
const fileManagerTests = require('./file/FileManagerTests');
88
const taskTests = require('./TaskTests');
99
const queueTests = require('./QueueTests');
10+
const textAndGraphicManagerTests = require('./screen/TextAndGraphicManagerTests');
11+
const textAndGraphicUpdateOperationTests = require('./screen/TextAndGraphicUpdateOperationTests');
1012

1113
// connect to core and select the app on the HMI to run the tests
1214
describe('ManagerTests', function () {
@@ -16,13 +18,15 @@ describe('ManagerTests', function () {
1618
appWebSocketServer.on('connection', function (connection) {
1719
console.log('Connection');
1820
const appClient = new AppClient(connection, async (teardown) => {
21+
textAndGraphicManagerTests(appClient);
1922
permissionManagerTests(appClient);
2023
softButtonManagerTests(appClient);
2124
screenManagerTests(appClient);
2225
lifecycleManagerTests(appClient);
2326
fileManagerTests(appClient);
2427
taskTests(appClient);
2528
queueTests(appClient);
29+
textAndGraphicUpdateOperationTests(appClient);
2630
setTimeout(function () {
2731
teardown();
2832
done();
Lines changed: 227 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,227 @@
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

Comments
 (0)