mirror of
https://github.com/Foundry376/Mailspring.git
synced 2024-11-12 04:25:31 +08:00
9f309d399b
Summary: - Rename DraftStoreExtension to ComposerExtension - Rename MessageStoreExtension to MessageViewExtension - Rename ContenteditablePlugin to ContenteditableExtension - Update Contenteditable to use new naming convention - Adds support for extension handlers as props - Add ExtensionRegistry to register extensions: - ContenteditableExtensions will not be registered through the ExtensionRegistry. They are meant for internal use, or if anyone wants to use our Contenteditable component directly in their plugins. - Adds specs - Refactors internal_packages and src to use new names and new ExtensionRegistry api - Adds deprecation util function and deprecation notices for old api methods: - DraftStore.{registerExtension, unregisterExtension} - MessageStore.{registerExtension, unregisterExtension} - DraftStoreExtension.{onMouseUp, onTabDown} - MessageStoreExtension - Adds and updates docs Test Plan: - Unit tests Reviewers: bengotow, evan Reviewed By: evan Differential Revision: https://phab.nylas.com/D2293
63 lines
2.4 KiB
CoffeeScript
63 lines
2.4 KiB
CoffeeScript
ExtensionRegistry = require '../src/extension-registry'
|
|
|
|
class TestExtension
|
|
@name: 'TestExtension'
|
|
|
|
describe 'ExtensionRegistry', ->
|
|
beforeEach ->
|
|
@originalAdapters = ExtensionRegistry._deprecationAdapters
|
|
@registry = new ExtensionRegistry.Registry('Test')
|
|
spyOn @registry, 'triggerDebounced'
|
|
|
|
describe 'Registry', ->
|
|
it 'has trigger and listen to defined', ->
|
|
expect(@registry.trigger).toBeDefined()
|
|
expect(@registry.listen).toBeDefined()
|
|
expect(@registry.listenTo).toBeDefined()
|
|
|
|
describe 'register', ->
|
|
it 'throws an exception if extension not passed', ->
|
|
expect(=> @registry.register(null)).toThrow()
|
|
|
|
it 'throws an exception if extension does not have a name', ->
|
|
expect(=> @registry.register({})).toThrow()
|
|
|
|
it 'throws an exception if extension is array', ->
|
|
expect(=> @registry.register([])).toThrow()
|
|
|
|
it 'throws an exception if extension is string', ->
|
|
expect(=> @registry.register('')).toThrow()
|
|
|
|
it 'returns itself', ->
|
|
expect(@registry.register(TestExtension)).toBe(@registry)
|
|
|
|
it 'registers extension and triggers', ->
|
|
@registry.register(TestExtension)
|
|
expect(@registry.extensions().length).toEqual 1
|
|
expect(@registry.triggerDebounced).toHaveBeenCalled()
|
|
|
|
it 'does not add extensions with the same name', ->
|
|
expect(@registry.extensions().length).toEqual 0
|
|
@registry.register(TestExtension)
|
|
expect(@registry.extensions().length).toEqual 1
|
|
@registry.register({name: 'TestExtension'})
|
|
expect(@registry.extensions().length).toEqual 1
|
|
|
|
it 'calls deprecationAdapters if present for a role', ->
|
|
adapterSpy = jasmine.createSpy('adapterSpy').andCallFake (ext) -> ext
|
|
@registry = new ExtensionRegistry.Registry('Test', adapterSpy)
|
|
spyOn @registry, 'triggerDebounced'
|
|
@registry.register(TestExtension)
|
|
expect(adapterSpy.calls.length).toEqual 1
|
|
|
|
describe 'unregister', ->
|
|
it 'unregisters the extension if it exists', ->
|
|
@registry.register(TestExtension)
|
|
@registry.unregister(TestExtension)
|
|
expect(@registry.extensions().length).toEqual 0
|
|
|
|
it 'throws if invalid extension passed', ->
|
|
expect( => @registry.unregister('Test')).toThrow()
|
|
expect( => @registry.unregister(null)).toThrow()
|
|
expect( => @registry.unregister([])).toThrow()
|
|
expect( => @registry.unregister({})).toThrow()
|