-
Notifications
You must be signed in to change notification settings - Fork 74
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* enable read from local folder and add tests * electron only for local files * make route hiden if interface is not found * remove focus if value is filled
- Loading branch information
Showing
43 changed files
with
1,002 additions
and
232 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/*********************************************************** | ||
* Copyright (c) Microsoft Corporation. All rights reserved. | ||
* Licensed under the MIT License | ||
**********************************************************/ | ||
import * as LocalRepoService from './localRepoService'; | ||
describe('localRepoService', () => { | ||
|
||
context('fetchLocalFile', () => { | ||
it('returns file content when response is 200', async done => { | ||
// tslint:disable | ||
const content = { | ||
"@id": "urn:FlyYing:EnvironmentalSensor:1", | ||
"@type": "Interface", | ||
"displayName": "Environmental Sensor", | ||
"description": "Provides functionality to report temperature, humidity. Provides telemetry, commands and read-write properties", | ||
"comment": "Requires temperature and humidity sensors.", | ||
"contents": [ | ||
{ | ||
"@type": "Property", | ||
"displayName": "Device State", | ||
"description": "The state of the device. Two states online/offline are available.", | ||
"name": "state", | ||
"schema": "boolean" | ||
} | ||
], | ||
"@context": "http://azureiot.com/v1/contexts/IoTModel.json" | ||
}; | ||
const response = { | ||
status: 200, | ||
json: () => content, | ||
headers: {}, | ||
ok: true | ||
} as any; | ||
// tslint:enable | ||
jest.spyOn(window, 'fetch').mockResolvedValue(response); | ||
|
||
const result = await LocalRepoService.fetchLocalFile('f:/test.json'); | ||
expect(result).toEqual(content); | ||
done(); | ||
}); | ||
|
||
it('throw when response is 404', async done => { | ||
window.fetch = jest.fn().mockRejectedValueOnce(new Error('Not found')); | ||
await expect(LocalRepoService.fetchLocalFile('f:/test.json')).rejects.toThrowError('Not found'); | ||
done(); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
/*********************************************************** | ||
* Copyright (c) Microsoft Corporation. All rights reserved. | ||
* Licensed under the MIT License | ||
**********************************************************/ | ||
import { READ_FILE, CONTROLLER_API_ENDPOINT, DataPlaneStatusCode } from './../../constants/apiConstants'; | ||
|
||
export const fetchLocalFile = async (path: string): Promise<string> => { | ||
try { | ||
const response = await fetch(`${CONTROLLER_API_ENDPOINT}${READ_FILE}/${encodeURIComponent(path)}`); | ||
if (await response.status === DataPlaneStatusCode.NotFound) { | ||
throw new Error(); | ||
} | ||
return await response.json(); | ||
} catch (error) { | ||
throw error; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.