Skip to content

Commit 32e7a89

Browse files
authored
Merge pull request #144 from smartdevicelink/feature/rc1-unit-tests
Include FileManager tests
2 parents f91449e + 3b9edae commit 32e7a89

7 files changed

Lines changed: 545 additions & 47 deletions

File tree

lib/js/src/manager/file/FileManager.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,11 @@ class FileManager extends _FileManagerBase {
5656
*/
5757
async _createPutFile (file) {
5858
const putFile = new PutFile();
59-
putFile.setFileName(file.getName());
59+
if (file.getName() === null || file.getName() === undefined) {
60+
throw new Error('You must specify a file name in the SdlFile');
61+
} else {
62+
putFile.setFileName(file.getName());
63+
}
6064
if (typeof file.getFilePath() === 'string') {
6165
const data = await _FileUtils.getFileData(file.getFilePath());
6266

package-lock.json

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
"babel-plugin-transform-async-to-promises": "^0.8.15",
4242
"bson": "^4.0.2",
4343
"chai": "^4.2.0",
44+
"chai-as-promised": "^7.1.1",
4445
"eslint": "^6.8.0",
4546
"eslint-plugin-jsdoc": "^22.1.0",
4647
"esm": "^3.2.25",

tests/managers/AppClient.js

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,6 @@ const CONFIG = require('./config.js');
3535

3636
class AppClient {
3737
constructor (wsClient, ready) {
38-
const fileName = `${CONFIG.appId}_icon.gif`;
39-
const file = new SDL.manager.file.filetypes.SdlFile()
40-
.setName(fileName)
41-
.setFilePath('./test_icon_1.png')
42-
.setType(SDL.rpc.enums.FileType.GRAPHIC_PNG)
43-
.setPersistent(true);
44-
4538
this._lifecycleConfig = new SDL.manager.LifecycleConfig()
4639
.setAppId(CONFIG.appId)
4740
.setAppName(CONFIG.appName)
@@ -54,8 +47,7 @@ class AppClient {
5447
wsClient,
5548
CONFIG.connectionLostTimeout
5649
)
57-
)
58-
.setAppIcon(file);
50+
);
5951

6052
this._appConfig = new SDL.manager.AppConfig()
6153
.setLifecycleConfig(this._lifecycleConfig);
@@ -75,19 +67,30 @@ class AppClient {
7567
.addRpcListener(SDL.rpc.enums.FunctionID.OnHMIStatus, this._onHmiStatusListener.bind(this));
7668

7769
this._ready = ready;
70+
// for a cloud server app the hmi full will be received before the managers report that they're ready!
71+
this._managersReady = false;
72+
this._hmiFull = false;
7873
}
7974

8075
async _onConnected () {
81-
76+
this._managersReady = true;
77+
this._checkReadyState();
8278
}
8379

8480
async _onHmiStatusListener (onHmiStatus) {
8581
const hmiLevel = onHmiStatus.getHmiLevel();
8682

8783
// wait for the FULL state for more functionality
8884
if (hmiLevel === SDL.rpc.enums.HMILevel.HMI_FULL) {
85+
this._hmiFull = true;
86+
this._checkReadyState();
87+
}
88+
}
89+
90+
async _checkReadyState () {
91+
if (this._managersReady && this._hmiFull) {
8992
if (typeof this._ready === 'function') {
90-
this._ready(async () => {
93+
await this._ready(async () => {
9194
// tests complete. tear down the app
9295
await this._sdlManager.sendRpc(new SDL.rpc.messages.UnregisterAppInterface());
9396
this._sdlManager.dispose();
@@ -103,4 +106,4 @@ class AppClient {
103106
}
104107
}
105108

106-
module.exports = AppClient;
109+
module.exports = AppClient;

0 commit comments

Comments
 (0)