Add UrlHandlerRegistry

This commit is contained in:
Michelle Tilley
2017-09-18 17:33:51 -07:00
parent bf4985e265
commit 0ae64c37de
2 changed files with 137 additions and 0 deletions

View File

@@ -0,0 +1,38 @@
/** @babel */
import {it} from './async-spec-helpers'
import UrlHandlerRegistry from '../src/url-handler-registry'
describe('UrlHandlerRegistry', () => {
let registry = new UrlHandlerRegistry()
it('handles URLs on a per-host basis', () => {
const testPackageSpy = jasmine.createSpy()
const otherPackageSpy = jasmine.createSpy()
registry.registerHostHandler('test-package', testPackageSpy)
registry.registerHostHandler('other-package', otherPackageSpy)
registry.handleUrl("atom://yet-another-package/path")
expect(testPackageSpy).not.toHaveBeenCalled()
expect(otherPackageSpy).not.toHaveBeenCalled()
registry.handleUrl("atom://test-package/path")
expect(testPackageSpy).toHaveBeenCalledWith("atom://test-package/path")
expect(otherPackageSpy).not.toHaveBeenCalled()
registry.handleUrl("atom://other-package/path")
expect(otherPackageSpy).toHaveBeenCalledWith("atom://other-package/path")
})
it('refuses to handle bad URLs', () => {
[
'atom:package/path',
'atom:8080://package/path',
'user:pass@atom://package/path',
'smth://package/path'
].forEach(uri => {
expect(() => registry.handleUrl(uri)).toThrow()
})
})
})