This repository has been archived by the owner on Aug 15, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* test(getAttribute.test.js): adding unit tests for getAttribute * feat(getAuthorizationHeader.test.js): including getAuthorizationHeader.test.js * feat(getName.test.js): adding getName tests * feat(getNumber.test.js): adding getNumber.test.js * feat(getString.test.js): adding getString.test.js * feat(index.test.js): adding index.test.js file * feat(index.test.js): improviments on index test file * feat(getModalities.test.js): adding getModalities tests * feat(index.test.js): emoving call tests since the expect test already covers it * adding and refactoring absoluteUrl function * adding addServer.test.js * adding unit tests for guid * adding unit tests for index.js * fixing typo in guid.test.js and adding isImage.test.js file * adding tests for objectPath.js * replacing toBeCalled to toBeCalledWith * fixing typo * removing beforeEach * making the test description and variables clear * Clearing all mocks after tests run * improving addServer tests
- Loading branch information
Showing
10 changed files
with
717 additions
and
85 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
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,51 @@ | ||
import absoluteUrl from './absoluteUrl'; | ||
|
||
describe('absoluteUrl', () => { | ||
test('should return /path_1/path_2/path_3/path_to_destination when the window.location.origin is http://dummy.com/path_1/path_2 and the path is /path_3/path_to_destination', () => { | ||
let global = { | ||
window: Object.create(window), | ||
}; | ||
const url = 'http://dummy.com/path_1/path_2'; | ||
Object.defineProperty(window, 'location', { | ||
value: { | ||
origin: url, | ||
}, | ||
writable: true, | ||
}); | ||
const absoluteUrlOutput = absoluteUrl('/path_3/path_to_destination'); | ||
expect(absoluteUrlOutput).toEqual( | ||
'/path_1/path_2/path_3/path_to_destination' | ||
); | ||
}); | ||
|
||
test('should return / when the path is not defined', () => { | ||
const absoluteUrlOutput = absoluteUrl(undefined); | ||
expect(absoluteUrlOutput).toBe('/'); | ||
}); | ||
|
||
test('should return the original path when there path in the window.origin after the domain and port', () => { | ||
global.window = Object.create(window); | ||
const url = 'http://dummy.com'; | ||
Object.defineProperty(window, 'location', { | ||
value: { | ||
origin: url, | ||
}, | ||
writable: true, | ||
}); | ||
const absoluteUrlOutput = absoluteUrl('path_1/path_2/path_3'); | ||
expect(absoluteUrlOutput).toEqual('/path_1/path_2/path_3'); | ||
}); | ||
|
||
test('should be able to return the absolute path even when the path contains duplicates', () => { | ||
global.window = Object.create(window); | ||
const url = 'http://dummy.com'; | ||
Object.defineProperty(window, 'location', { | ||
value: { | ||
origin: url, | ||
}, | ||
writable: true, | ||
}); | ||
const absoluteUrlOutput = absoluteUrl('path_1/path_1/path_1'); | ||
expect(absoluteUrlOutput).toEqual('/path_1/path_1/path_1'); | ||
}); | ||
}); |
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,82 @@ | ||
import addServers from './addServers'; | ||
|
||
describe('addServers', () => { | ||
const servers = { | ||
dicomWeb: [ | ||
{ | ||
name: 'DCM4CHEE', | ||
wadoUriRoot: 'https://server.dcmjs.org/dcm4chee-arc/aets/DCM4CHEE/wado', | ||
qidoRoot: 'https://server.dcmjs.org/dcm4chee-arc/aets/DCM4CHEE/rs', | ||
wadoRoot: 'https://server.dcmjs.org/dcm4chee-arc/aets/DCM4CHEE/rs', | ||
qidoSupportsIncludeField: true, | ||
imageRendering: 'wadors', | ||
thumbnailRendering: 'wadors', | ||
requestOptions: { | ||
requestFromBrowser: true, | ||
}, | ||
}, | ||
], | ||
oidc: [ | ||
{ | ||
authority: 'http://127.0.0.1/auth/realms/ohif', | ||
client_id: 'ohif-viewer', | ||
redirect_uri: 'http://127.0.0.1/callback', | ||
response_type: 'code', | ||
scope: 'openid', | ||
post_logout_redirect_uri: '/logout-redirect.html', | ||
}, | ||
], | ||
}; | ||
|
||
const store = { | ||
dispatch: jest.fn(), | ||
}; | ||
|
||
test('should be able to add a server and dispatch to the store successfuly', () => { | ||
addServers(servers, store); | ||
expect(store.dispatch).toBeCalledWith({ | ||
server: { | ||
authority: 'http://127.0.0.1/auth/realms/ohif', | ||
client_id: 'ohif-viewer', | ||
post_logout_redirect_uri: '/logout-redirect.html', | ||
redirect_uri: 'http://127.0.0.1/callback', | ||
response_type: 'code', | ||
scope: 'openid', | ||
type: 'oidc', | ||
}, | ||
type: 'ADD_SERVER', | ||
}); | ||
expect(store.dispatch).toBeCalledWith({ | ||
server: { | ||
imageRendering: 'wadors', | ||
name: 'DCM4CHEE', | ||
qidoRoot: 'https://server.dcmjs.org/dcm4chee-arc/aets/DCM4CHEE/rs', | ||
qidoSupportsIncludeField: true, | ||
requestOptions: { requestFromBrowser: true }, | ||
thumbnailRendering: 'wadors', | ||
type: 'dicomWeb', | ||
wadoRoot: 'https://server.dcmjs.org/dcm4chee-arc/aets/DCM4CHEE/rs', | ||
wadoUriRoot: 'https://server.dcmjs.org/dcm4chee-arc/aets/DCM4CHEE/wado', | ||
}, | ||
type: 'ADD_SERVER', | ||
}); | ||
}); | ||
|
||
test('should throw an error if servers list is not defined', () => { | ||
expect(() => addServers(undefined, store)).toThrowError( | ||
new Error('The servers and store must be defined') | ||
); | ||
}); | ||
|
||
test('should throw an error if store is not defined', () => { | ||
expect(() => addServers(servers, undefined)).toThrowError( | ||
new Error('The servers and store must be defined') | ||
); | ||
}); | ||
|
||
test('should throw an error when both server and store are not defined', () => { | ||
expect(() => addServers(undefined, undefined)).toThrowError( | ||
new Error('The servers and store must be defined') | ||
); | ||
}); | ||
}); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import guid from './guid'; | ||
|
||
describe('guid', () => { | ||
Math.random = jest.fn(() => 0.4677647565236618); | ||
const guidValue = guid(); | ||
|
||
afterAll(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
test('should return 77bf77bf-77bf-77bf-77bf-77bf77bf77bf when the random value is fixed on 0.4677647565236618', () => { | ||
expect(guidValue).toBe('77bf77bf-77bf-77bf-77bf-77bf77bf77bf'); | ||
}); | ||
|
||
test('should always return a guid of size 36', () => { | ||
expect(guidValue.length).toBe(36); | ||
}); | ||
|
||
test('should always return a guid with five sequences', () => { | ||
expect(guidValue.split('-').length).toBe(5); | ||
}); | ||
|
||
test('should always return a guid with four dashes', () => { | ||
expect(guidValue.split('-').length - 1).toBe(4); | ||
}); | ||
|
||
test('should return the first sequence with length of eigth', () => { | ||
expect(guidValue.split('-')[0].length).toBe(8); | ||
}); | ||
|
||
test('should return the second sequence with length of four', () => { | ||
expect(guidValue.split('-')[1].length).toBe(4); | ||
}); | ||
|
||
test('should return the third sequence with length of four', () => { | ||
expect(guidValue.split('-')[2].length).toBe(4); | ||
}); | ||
|
||
test('should return the fourth sequence with length of four', () => { | ||
expect(guidValue.split('-')[3].length).toBe(4); | ||
}); | ||
|
||
test('should return the last sequence with length of twelve', () => { | ||
expect(guidValue.split('-')[4].length).toBe(12); | ||
}); | ||
}); |
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,23 @@ | ||
import * as utils from './index.js'; | ||
|
||
describe('Top level exports', () => { | ||
test('should export the modules ', () => { | ||
const expectedExports = [ | ||
'guid', | ||
'ObjectPath', | ||
'absoluteUrl', | ||
'addServers', | ||
'sortBy', | ||
'writeScript', | ||
'StackManager', | ||
'studyMetadataManager', | ||
// Updates WADO-RS metaDataManager | ||
'updateMetaDataManager', | ||
'DICOMTagDescriptions', | ||
].sort(); | ||
|
||
const exports = Object.keys(utils.default).sort(); | ||
|
||
expect(exports).toEqual(expectedExports); | ||
}); | ||
}); |
Oops, something went wrong.