Skip to content

Commit 84ff1ee

Browse files
committed
Add specs testing different md preview packages
1 parent aab66ec commit 84ff1ee

File tree

4 files changed

+65
-17
lines changed

4 files changed

+65
-17
lines changed

package.json

+3
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,8 @@
1515
"dependencies": {
1616
"html-pdf": "0.3.x",
1717
"less": "^1.7.0"
18+
},
19+
"devDependencies": {
20+
"temp": "^0.8.3"
1821
}
1922
}

spec/fixtures/simple.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
*italic*
2+
3+
**bold**
4+
5+
> quote

spec/markdown-pdf-spec.coffee

+57-12
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,75 @@
1-
{WorkspaceView} = require 'atom'
21
MarkdownPdf = require '../lib/markdown-pdf'
2+
temp = require('temp').track()
3+
path = require 'path'
4+
fs = require 'fs'
35

46
# Use the command `window:run-package-specs` (cmd-alt-ctrl-p) to run specs.
57
#
68
# To run a specific `it` or `describe` block add an `f` to the front (e.g. `fit`
79
# or `fdescribe`). Remove the `f` to unfocus the block.
810

911
describe "MarkdownPdf", ->
10-
activationPromise = null
12+
[workspaceElement, tempDIRPath, activationPromise] = []
1113

1214
beforeEach ->
13-
atom.workspaceView = new WorkspaceView
15+
tempDIRPath = temp.mkdirSync 'atom-temp-dir-'
16+
tempFixturePath = path.join tempDIRPath, 'simple.md'
17+
18+
fixturePath = path.join __dirname, 'fixtures/simple.md'
19+
fixtureFile = fs.readFileSync fixturePath, 'utf8'
20+
21+
fs.writeFileSync tempFixturePath, fixtureFile
22+
23+
workspaceElement = atom.views.getView(atom.workspace)
24+
jasmine.attachToDOM(workspaceElement)
25+
1426
activationPromise = atom.packages.activatePackage('markdown-pdf')
1527

16-
describe "when the markdown-pdf:toggle event is triggered", ->
17-
it "attaches and then detaches the view", ->
18-
expect(atom.workspaceView.find('.markdown-pdf')).not.toExist()
28+
waitsForPromise ->
29+
atom.themes.activateThemes()
30+
31+
waitsForPromise ->
32+
atom.workspace.open(tempFixturePath)
33+
34+
afterEach ->
35+
atom.themes.deactivateThemes()
36+
37+
describe "when markdown-preview is enabled", ->
38+
it "makes a pdf from clipboard data after calling markdown-preview::copyHtml()", ->
39+
spyOn(atom.clipboard, 'write').andCallThrough()
40+
41+
waitsForPromise ->
42+
atom.packages.activatePackage('markdown-preview')
43+
44+
runs ->
45+
atom.commands.dispatch workspaceElement, 'markdown-pdf:convert'
46+
47+
waitsForPromise ->
48+
activationPromise
49+
50+
waitsFor "PDF to have been created", ->
51+
fs.readdirSync(tempDIRPath).length is 2
52+
53+
runs ->
54+
expect(atom.clipboard.write).toHaveBeenCalled()
1955

20-
# This is an activation event, triggering it will cause the package to be
21-
# activated.
22-
atom.workspaceView.trigger 'markdown-pdf:toggle'
56+
describe "when markdown-preview-plus is enabled and markdown-preview disabled", ->
57+
it "makes a pdf from callback parameter data after calling markdown-preview-plus::copyHtml()", ->
58+
mpp = null
59+
60+
waitsForPromise ->
61+
atom.packages.activatePackage('markdown-preview-plus')
62+
63+
runs ->
64+
mpp = atom.packages.getActivePackage('markdown-preview-plus')
65+
spyOn(mpp.mainModule, "copyHtml").andCallThrough()
66+
atom.commands.dispatch workspaceElement, 'markdown-pdf:convert'
2367

2468
waitsForPromise ->
2569
activationPromise
2670

71+
waitsFor "PDF to have been created", ->
72+
fs.readdirSync(tempDIRPath).length is 2
73+
2774
runs ->
28-
expect(atom.workspaceView.find('.markdown-pdf')).toExist()
29-
atom.workspaceView.trigger 'markdown-pdf:toggle'
30-
expect(atom.workspaceView.find('.markdown-pdf')).not.toExist()
75+
expect(mpp.mainModule.copyHtml).toHaveBeenCalled()

spec/markdown-pdf-view-spec.coffee

-5
This file was deleted.

0 commit comments

Comments
 (0)