1 {WorkspaceView} = require 'atom'
3 describe "pretty json", ->
4 [editor, editorView] = []
6 prettify = (callback) ->
7 editorView.trigger "pretty-json:prettify"
10 minify = (callback) ->
11 editorView.trigger "pretty-json:minify"
14 sortedPrettify = (callback) ->
15 editorView.trigger "pretty-json:sort-and-prettify"
19 waitsForPromise -> atom.packages.activatePackage('pretty-json')
20 waitsForPromise -> atom.packages.activatePackage('language-json')
22 atom.workspaceView = new WorkspaceView
23 atom.workspaceView.openSync()
25 editorView = atom.workspaceView.getActiveView()
26 editor = editorView.getEditor()
28 describe "when no text is selected", ->
29 it "doesn't change anything", ->
32 { "a": "b", "c": "d" }
37 expect(editor.getText()).toBe """
39 { "a": "b", "c": "d" }
43 describe "when a valid json text is selected", ->
44 it "formats it correctly", ->
47 { "a": "b", "c": "d" }
50 editor.setSelectedBufferRange([[1,0], [1, 22]])
53 expect(editor.getText()).toBe """
62 describe "when an invalid json text is selected", ->
63 it "doesn't change anything", ->
69 editor.setSelectedBufferRange([[1,0], [1, 2]])
72 expect(editor.getText()).toBe """
78 describe "JSON file", ->
80 editor.setGrammar(atom.syntax.selectGrammar('test.json'))
82 describe "with invalid JSON", ->
83 it "doesn't change anything", ->
89 expect(editor.getText()).toBe """
93 describe "with valid JSON", ->
94 it "formats the whole file correctly", ->
96 { "a": "b", "c": "d" }
100 expect(editor.getText()).toBe """
107 describe "Sort and prettify", ->
109 editor.setGrammar(atom.syntax.selectGrammar('test.json'))
111 describe "with invalid JSON", ->
112 it "doesn't change anything", ->
118 expect(editor.getText()).toBe """
122 describe "with valid JSON", ->
123 it "formats the whole file correctly", ->
125 { "c": "d", "a": "b" }
129 expect(editor.getText()).toBe """
136 describe "Minify JSON file", ->
138 editor.setGrammar(atom.syntax.selectGrammar('test.json'))
140 it "Returns same string from invalid JSON", ->
148 expect(editor.getText()).toBe """
154 it "Minifies valid JSON", ->
164 expect(editor.getText()).toBe """
165 {"a":"b","c":"d","num":123}
168 describe "Minify selected JSON", ->
169 it "Minifies JSON data", ->
179 editor.setSelectedBufferRange([[1,0], [5, 1]])
182 expect(editor.getText()).toBe """
184 {"a":"b","c":"d","num":123}