|
1 |
| -{WorkspaceView} = require 'atom' |
2 | 1 | MarkdownPdf = require '../lib/markdown-pdf'
|
| 2 | +temp = require('temp').track() |
| 3 | +path = require 'path' |
| 4 | +fs = require 'fs' |
3 | 5 |
|
4 | 6 | # Use the command `window:run-package-specs` (cmd-alt-ctrl-p) to run specs.
|
5 | 7 | #
|
6 | 8 | # To run a specific `it` or `describe` block add an `f` to the front (e.g. `fit`
|
7 | 9 | # or `fdescribe`). Remove the `f` to unfocus the block.
|
8 | 10 |
|
9 | 11 | describe "MarkdownPdf", ->
|
10 |
| - activationPromise = null |
| 12 | + [workspaceElement, tempDIRPath, activationPromise] = [] |
11 | 13 |
|
12 | 14 | 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 | + |
14 | 26 | activationPromise = atom.packages.activatePackage('markdown-pdf')
|
15 | 27 |
|
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() |
19 | 55 |
|
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' |
23 | 67 |
|
24 | 68 | waitsForPromise ->
|
25 | 69 | activationPromise
|
26 | 70 |
|
| 71 | + waitsFor "PDF to have been created", -> |
| 72 | + fs.readdirSync(tempDIRPath).length is 2 |
| 73 | + |
27 | 74 | 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() |
0 commit comments