forked from atom/atom
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgutter-spec.js
82 lines (72 loc) · 2.41 KB
/
gutter-spec.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
const Gutter = require('../src/gutter')
describe('Gutter', () => {
const fakeGutterContainer = {
scheduleComponentUpdate () {}
}
const name = 'name'
describe('::hide', () =>
it('hides the gutter if it is visible.', () => {
const options = {
name,
visible: true
}
const gutter = new Gutter(fakeGutterContainer, options)
const events = []
gutter.onDidChangeVisible(gutter => events.push(gutter.isVisible()))
expect(gutter.isVisible()).toBe(true)
gutter.hide()
expect(gutter.isVisible()).toBe(false)
expect(events).toEqual([false])
gutter.hide()
expect(gutter.isVisible()).toBe(false)
// An event should only be emitted when the visibility changes.
expect(events.length).toBe(1)
}))
describe('::show', () =>
it('shows the gutter if it is hidden.', () => {
const options = {
name,
visible: false
}
const gutter = new Gutter(fakeGutterContainer, options)
const events = []
gutter.onDidChangeVisible(gutter => events.push(gutter.isVisible()))
expect(gutter.isVisible()).toBe(false)
gutter.show()
expect(gutter.isVisible()).toBe(true)
expect(events).toEqual([true])
gutter.show()
expect(gutter.isVisible()).toBe(true)
// An event should only be emitted when the visibility changes.
expect(events.length).toBe(1)
}))
describe('::destroy', () => {
let mockGutterContainer, mockGutterContainerRemovedGutters
beforeEach(() => {
mockGutterContainerRemovedGutters = []
mockGutterContainer = {
removeGutter (destroyedGutter) {
mockGutterContainerRemovedGutters.push(destroyedGutter)
}
}
})
it('removes the gutter from its container.', () => {
const gutter = new Gutter(mockGutterContainer, { name })
gutter.destroy()
expect(mockGutterContainerRemovedGutters).toEqual([gutter])
})
it('calls all callbacks registered on ::onDidDestroy.', () => {
const gutter = new Gutter(mockGutterContainer, { name })
let didDestroy = false
gutter.onDidDestroy(() => {
didDestroy = true
})
gutter.destroy()
expect(didDestroy).toBe(true)
})
it('does not allow destroying the line-number gutter', () => {
const gutter = new Gutter(mockGutterContainer, { name: 'line-number' })
expect(gutter.destroy).toThrow()
})
})
})