|
| 1 | +{WorkspaceView} = require 'atom' |
| 2 | +{Stacktrace, Frame} = require '../lib/stacktrace' |
| 3 | +{NavigationView} = require '../lib/navigation-view' |
| 4 | + |
| 5 | +path = require 'path' |
| 6 | + |
| 7 | +fixturePath = (p) -> |
| 8 | + path.join __dirname, 'fixtures', p |
| 9 | + |
| 10 | +frames = [ |
| 11 | + new Frame('raw0', fixturePath('bottom.rb'), 12, 'botfunc') |
| 12 | + new Frame('raw1', fixturePath('middle.rb'), 42, 'midfunc') |
| 13 | + new Frame('raw2', fixturePath('top.rb'), 37, 'topfunc') |
| 14 | + new Frame('raw3', fixturePath('middle.rb'), 5, 'otherfunc') |
| 15 | +] |
| 16 | +trace = new Stacktrace(frames, 'Boom') |
| 17 | + |
| 18 | +describe 'NavigationView', -> |
| 19 | + [view] = [] |
| 20 | + |
| 21 | + beforeEach -> |
| 22 | + atom.workspaceView = new WorkspaceView |
| 23 | + atom.workspaceView.attachToDom() |
| 24 | + activationPromise = atom.packages.activatePackage('stacktrace') |
| 25 | + |
| 26 | + atom.workspaceView.trigger 'stacktrace:paste' |
| 27 | + |
| 28 | + waitsForPromise -> activationPromise |
| 29 | + |
| 30 | + runs -> |
| 31 | + view = atom.workspaceView.find('.stacktrace.navigation').view() |
| 32 | + |
| 33 | + afterEach -> |
| 34 | + Stacktrace.getActivated()?.deactivate() |
| 35 | + Stacktrace.clearRegistry() |
| 36 | + |
| 37 | + it 'attaches itself to the workspace', -> |
| 38 | + expect(view).not.toBeNull() |
| 39 | + |
| 40 | + describe 'with an active stacktrace', -> |
| 41 | + |
| 42 | + beforeEach -> |
| 43 | + trace.register() |
| 44 | + trace.activate() |
| 45 | + |
| 46 | + it 'should be visible', -> |
| 47 | + expect(view.hasClass 'inactive').toBeFalsy() |
| 48 | + |
| 49 | + it 'shows the active trace name', -> |
| 50 | + text = view.find('.message').text() |
| 51 | + expect(text).toEqual('Boom') |
| 52 | + |
| 53 | + it 'navigates back to the trace on a click', -> |
| 54 | + waitsForPromise -> view.backToTrace() |
| 55 | + |
| 56 | + runs -> |
| 57 | + expect(atom.workspaceView.getActiveView().hasClass 'traceview').toBeTruthy() |
| 58 | + |
| 59 | + it 'deactivates the trace', -> |
| 60 | + view.deactivateTrace() |
| 61 | + expect(trace.isActive()).toBeFalsy() |
| 62 | + |
| 63 | + describe 'on an editor corresponding to a single frame', -> |
| 64 | + [editor] = [] |
| 65 | + |
| 66 | + beforeEach -> |
| 67 | + waitsForPromise -> trace.frames[2].navigateTo() |
| 68 | + |
| 69 | + runs -> |
| 70 | + editor = atom.workspace.getActiveEditor() |
| 71 | + |
| 72 | + it 'shows the current frame and its index', -> |
| 73 | + expect(view.find('.current-frame .function').text()).toBe('topfunc') |
| 74 | + expect(view.find('.current-frame .index').text()).toBe('3') |
| 75 | + expect(view.find('.current-frame .total').text()).toBe('4') |
| 76 | + |
| 77 | + it "navigates to the caller's frame", -> |
| 78 | + waitsForPromise -> view.navigateToCaller() |
| 79 | + |
| 80 | + runs -> |
| 81 | + expect(view.frame).toBe(trace.frames[3]) |
| 82 | + |
| 83 | + it 'navigates to the called frame', -> |
| 84 | + waitsForPromise -> view.navigateToCalled() |
| 85 | + |
| 86 | + runs -> |
| 87 | + expect(view.frame).toBe(trace.frames[1]) |
| 88 | + |
| 89 | + it 'navigates back to the last active frame', -> |
| 90 | + editor.setCursorBufferPosition [5, 0] |
| 91 | + expect(view.find '.current-frame.unfocused').toHaveLength 1 |
| 92 | + |
| 93 | + waitsForPromise -> view.navigateToLastActive() |
| 94 | + |
| 95 | + runs -> |
| 96 | + expect(view.find '.current-frame.unfocused').toHaveLength 0 |
| 97 | + expect(editor.getCursorBufferPosition().row).toBe 36 |
| 98 | + |
| 99 | + describe 'on an editor with multiple frames', -> |
| 100 | + [editor] = [] |
| 101 | + |
| 102 | + beforeEach -> |
| 103 | + waitsForPromise -> trace.frames[1].navigateTo() |
| 104 | + |
| 105 | + runs -> |
| 106 | + editor = atom.workspace.getActiveEditor() |
| 107 | + |
| 108 | + it 'notices if you manually navigate to a different frame', -> |
| 109 | + expect(view.find('.current-frame .function').text()).toEqual 'midfunc' |
| 110 | + |
| 111 | + editor.setCursorBufferPosition [4, 1] |
| 112 | + |
| 113 | + expect(view.frame).toBe(trace.frames[3]) |
| 114 | + expect(view.find('.current-frame .function').text()).toEqual 'otherfunc' |
0 commit comments