This repository was archived by the owner on Aug 14, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 42
/
Copy pathopener-registry-spec.js
84 lines (66 loc) · 2.77 KB
/
opener-registry-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
83
84
/** @babel */
// eslint-disable-next-line no-unused-vars
import { afterEach, beforeEach, it, fit } from './async-spec-helpers'
import { activatePackages } from './spec-helpers'
describe('OpenerRegistry', () => {
const filePath = 'wibble.pdf'
// The various viewers
let cannotOpen, canOpen, canOpenInBackground, canOpenWithSynctex
beforeEach(async () => {
await activatePackages()
})
function createOpener (name, canOpen, hasSynctex, canOpenInBackground) {
const opener = jasmine.createSpyObj(name, [
'open',
'canOpen',
'hasSynctex',
'canOpenInBackground'
])
opener.open.andCallFake(() => Promise.resolve())
opener.canOpen.andReturn(canOpen)
opener.hasSynctex.andReturn(hasSynctex)
opener.canOpenInBackground.andReturn(canOpenInBackground)
latex.opener.openers.set(name, opener)
return opener
}
beforeEach(() => {
latex.opener.openers.clear()
// The opener names have to conform to latex.opener schema
cannotOpen = createOpener('skim', false, true, true)
canOpen = createOpener('xdg-open', true, false, false)
canOpenInBackground = createOpener('okular', true, false, true)
canOpenWithSynctex = createOpener('evince', true, true, false)
})
describe('open', () => {
it('opens using preferred viewer even if it does not have requested features', async () => {
atom.config.set('latex.enableSynctex', true)
atom.config.set('latex.openResultInBackground', true)
atom.config.set('latex.opener', 'xdg-open')
await latex.opener.open(filePath)
expect(cannotOpen.open).not.toHaveBeenCalled()
expect(canOpen.open).toHaveBeenCalled()
expect(canOpenInBackground.open).not.toHaveBeenCalled()
expect(canOpenWithSynctex.open).not.toHaveBeenCalled()
})
it('opens viewer that supports SyncTeX when enabled', async () => {
atom.config.set('latex.enableSynctex', true)
atom.config.set('latex.openResultInBackground', true)
atom.config.set('latex.opener', 'automatic')
await latex.opener.open(filePath)
expect(cannotOpen.open).not.toHaveBeenCalled()
expect(canOpen.open).not.toHaveBeenCalled()
expect(canOpenInBackground.open).not.toHaveBeenCalled()
expect(canOpenWithSynctex.open).toHaveBeenCalled()
})
it('opens viewer that supports background opening when enabled', async () => {
atom.config.set('latex.enableSynctex', false)
atom.config.set('latex.openResultInBackground', true)
atom.config.set('latex.opener', 'automatic')
await latex.opener.open(filePath)
expect(cannotOpen.open).not.toHaveBeenCalled()
expect(canOpen.open).not.toHaveBeenCalled()
expect(canOpenInBackground.open).toHaveBeenCalled()
expect(canOpenWithSynctex.open).not.toHaveBeenCalled()
})
})
})