|
| 1 | +'use babel'; |
| 2 | + |
| 3 | +import { ClickProvider } from '../lib/clickProvider'; |
| 4 | + |
| 5 | +// Use the command `window:run-package-specs` (cmd-alt-ctrl-p) to run specs. |
| 6 | +// |
| 7 | +// To run a specific `it` or `describe` block add an `f` to the front (e.g. `fit` |
| 8 | +// or `fdescribe`). Remove the `f` to unfocus the block. |
| 9 | + |
| 10 | +let clickProvider; |
| 11 | +const clickHandlers = { |
| 12 | + goToDefinitions: () => {}, |
| 13 | +}; |
| 14 | + |
| 15 | +describe('AtomIdeClick', () => { |
| 16 | + beforeEach(function() { |
| 17 | + spyOn(atom.config, 'get').andCallFake(function(value) { |
| 18 | + const config = { |
| 19 | + 'atom-ide-definitions.clickGrammarScopes': [], |
| 20 | + 'atom-ide-definitions.clickPriority': 0, |
| 21 | + }; |
| 22 | + return config[value]; |
| 23 | + }); |
| 24 | + |
| 25 | + spyOn(atom.views, 'getView').andReturn('FakeEditorView'); |
| 26 | + |
| 27 | + spyOn(clickHandlers, 'goToDefinitions'); |
| 28 | + clickProvider = new ClickProvider({ |
| 29 | + clickHandler: clickHandlers.goToDefinitions, |
| 30 | + }); |
| 31 | + }); |
| 32 | + |
| 33 | + it('verify provider result', () => { |
| 34 | + const provider = clickProvider.getProvider(); |
| 35 | + |
| 36 | + expect(provider.priority).toEqual(0); |
| 37 | + expect(provider.grammarScopes).toBeNull(); |
| 38 | + expect(typeof provider.getSuggestionForWord).toEqual('function'); |
| 39 | + }); |
| 40 | + |
| 41 | + it('verify suggestionForWord result', () => { |
| 42 | + const suggestionForWord = clickProvider.suggestionForWordHandler( |
| 43 | + 'FakeEditor', |
| 44 | + 'FakeText', |
| 45 | + 'FakeRange' |
| 46 | + ); |
| 47 | + |
| 48 | + expect(suggestionForWord.range).toEqual('FakeRange'); |
| 49 | + expect(typeof suggestionForWord.callback).toEqual('function'); |
| 50 | + }); |
| 51 | + |
| 52 | + it('verify suggestionForWord handler stops if there is no text value', () => { |
| 53 | + const suggestionForWord = clickProvider.suggestionForWordHandler( |
| 54 | + 'FakeEditor', |
| 55 | + '', |
| 56 | + 'FakeRange' |
| 57 | + ); |
| 58 | + |
| 59 | + expect(suggestionForWord).toBeUndefined(); |
| 60 | + }); |
| 61 | + |
| 62 | + it('verify suggestionForWord callback assignment', () => { |
| 63 | + const suggestionForWord = clickProvider.suggestionForWordHandler( |
| 64 | + 'FakeEditor', |
| 65 | + 'FakeText', |
| 66 | + 'FakeRange' |
| 67 | + ); |
| 68 | + |
| 69 | + expect(typeof suggestionForWord.callback).toEqual('function'); |
| 70 | + |
| 71 | + suggestionForWord.callback(); |
| 72 | + expect(clickHandlers.goToDefinitions).toHaveBeenCalled(); |
| 73 | + }); |
| 74 | +}); |
0 commit comments