|
| 1 | +path = require 'path' |
| 2 | +{Editor, WorkspaceView} = require 'atom' |
| 3 | + |
| 4 | +{Stacktrace, Frame} = require '../lib/stacktrace' |
| 5 | +editorDecorator = require '../lib/editor-decorator' |
| 6 | + |
| 7 | +framePath = (fname) -> path.join __dirname, 'fixtures', fname |
| 8 | + |
| 9 | +frames = [ |
| 10 | + new Frame('raw0', framePath('bottom.rb'), 12, 'botfunc') |
| 11 | + new Frame('raw1', framePath('middle.rb'), 42, 'midfunc') |
| 12 | + new Frame('raw2', framePath('top.rb'), 37, 'topfunc') |
| 13 | + new Frame('raw3', framePath('middle.rb'), 5, 'otherfunc') |
| 14 | +] |
| 15 | +trace = new Stacktrace(frames, 'Boom') |
| 16 | + |
| 17 | +describe 'editorDecorator', -> |
| 18 | + [editor, editorView] = [] |
| 19 | + |
| 20 | + beforeEach -> |
| 21 | + atom.workspaceView = new WorkspaceView |
| 22 | + |
| 23 | + afterEach -> |
| 24 | + Stacktrace.getActivated()?.deactivate() |
| 25 | + |
| 26 | + withEditorOn = (fname, callback) -> |
| 27 | + waitsForPromise -> |
| 28 | + atom.workspace.open(framePath fname) |
| 29 | + |
| 30 | + runs -> |
| 31 | + atom.workspaceView.attachToDom() |
| 32 | + editorView = atom.workspaceView.getActiveView() |
| 33 | + editor = editorView.getEditor() |
| 34 | + callback() |
| 35 | + |
| 36 | + it 'does nothing if there is no active trace', -> |
| 37 | + expect(Stacktrace.getActivated()).toBeNull() |
| 38 | + |
| 39 | + withEditorOn 'bottom.rb', -> |
| 40 | + editorDecorator(editor) |
| 41 | + expect(editorView.find '.line.line-stackframe').toHaveLength 0 |
| 42 | + |
| 43 | + describe 'with an active trace', -> |
| 44 | + |
| 45 | + beforeEach -> trace.activate() |
| 46 | + |
| 47 | + it "does nothing if the file doesn't appear in the active trace", -> |
| 48 | + withEditorOn 'context.txt', -> |
| 49 | + editorDecorator(editor) |
| 50 | + expect(editorView.find '.line.line-stackframe').toHaveLength 0 |
| 51 | + |
| 52 | + it 'decorates stackframe lines in applicable editors', -> |
| 53 | + withEditorOn 'bottom.rb', -> |
| 54 | + editorDecorator(editor) |
| 55 | + decorated = editorView.find '.line.line-stackframe' |
| 56 | + expect(decorated).toHaveLength 1 |
| 57 | + expect(decorated.text()).toEqual(" puts 'this is the stack line'") |
| 58 | + |
| 59 | + it 'removes prior decorations when deactivated', -> |
| 60 | + withEditorOn 'bottom.rb', -> |
| 61 | + editorDecorator(editor) |
| 62 | + trace.deactivate() |
| 63 | + editorDecorator(editor) |
| 64 | + expect(editorView.find '.line.line-stackframe').toHaveLength 0 |
0 commit comments