aboutsummaryrefslogtreecommitdiff
path: root/atom/packages/pretty-json/spec
diff options
context:
space:
mode:
authorBen Beltran <ben@nsovocal.com>2017-03-02 13:13:31 -0600
committerBen Beltran <ben@nsovocal.com>2017-03-02 13:13:31 -0600
commit06a3d6866e4f545abddd6654e490e50b623330a9 (patch)
treee0e6a7d72eeaf647d03a44ed5c12733796fb8b87 /atom/packages/pretty-json/spec
parent49c52987b6c6be6392351b6a7b227efc7341a414 (diff)
Update atoms
Diffstat (limited to 'atom/packages/pretty-json/spec')
-rw-r--r--atom/packages/pretty-json/spec/index-spec.coffee186
1 files changed, 186 insertions, 0 deletions
diff --git a/atom/packages/pretty-json/spec/index-spec.coffee b/atom/packages/pretty-json/spec/index-spec.coffee
new file mode 100644
index 0000000..2f95fcd
--- /dev/null
+++ b/atom/packages/pretty-json/spec/index-spec.coffee
@@ -0,0 +1,186 @@
+{WorkspaceView} = require 'atom'
+
+describe "pretty json", ->
+ [editor, editorView] = []
+
+ prettify = (callback) ->
+ editorView.trigger "pretty-json:prettify"
+ runs(callback)
+
+ minify = (callback) ->
+ editorView.trigger "pretty-json:minify"
+ runs(callback)
+
+ sortedPrettify = (callback) ->
+ editorView.trigger "pretty-json:sort-and-prettify"
+ runs(callback)
+
+ beforeEach ->
+ waitsForPromise -> atom.packages.activatePackage('pretty-json')
+ waitsForPromise -> atom.packages.activatePackage('language-json')
+
+ atom.workspaceView = new WorkspaceView
+ atom.workspaceView.openSync()
+
+ editorView = atom.workspaceView.getActiveView()
+ editor = editorView.getEditor()
+
+ describe "when no text is selected", ->
+ it "doesn't change anything", ->
+ editor.setText """
+ Start
+ { "a": "b", "c": "d" }
+ End
+ """
+
+ prettify ->
+ expect(editor.getText()).toBe """
+ Start
+ { "a": "b", "c": "d" }
+ End
+ """
+
+ describe "when a valid json text is selected", ->
+ it "formats it correctly", ->
+ editor.setText """
+ Start
+ { "a": "b", "c": "d" }
+ End
+ """
+ editor.setSelectedBufferRange([[1,0], [1, 22]])
+
+ prettify ->
+ expect(editor.getText()).toBe """
+ Start
+ {
+ "a": "b",
+ "c": "d"
+ }
+ End
+ """
+
+ describe "when an invalid json text is selected", ->
+ it "doesn't change anything", ->
+ editor.setText """
+ Start
+ {]
+ End
+ """
+ editor.setSelectedBufferRange([[1,0], [1, 2]])
+
+ prettify ->
+ expect(editor.getText()).toBe """
+ Start
+ {]
+ End
+ """
+
+ describe "JSON file", ->
+ beforeEach ->
+ editor.setGrammar(atom.syntax.selectGrammar('test.json'))
+
+ describe "with invalid JSON", ->
+ it "doesn't change anything", ->
+ editor.setText """
+ {]
+ """
+
+ prettify ->
+ expect(editor.getText()).toBe """
+ {]
+ """
+
+ describe "with valid JSON", ->
+ it "formats the whole file correctly", ->
+ editor.setText """
+ { "a": "b", "c": "d" }
+ """
+
+ prettify ->
+ expect(editor.getText()).toBe """
+ {
+ "a": "b",
+ "c": "d"
+ }
+ """
+
+ describe "Sort and prettify", ->
+ beforeEach ->
+ editor.setGrammar(atom.syntax.selectGrammar('test.json'))
+
+ describe "with invalid JSON", ->
+ it "doesn't change anything", ->
+ editor.setText """
+ {]
+ """
+
+ sortedPrettify ->
+ expect(editor.getText()).toBe """
+ {]
+ """
+
+ describe "with valid JSON", ->
+ it "formats the whole file correctly", ->
+ editor.setText """
+ { "c": "d", "a": "b" }
+ """
+
+ sortedPrettify ->
+ expect(editor.getText()).toBe """
+ {
+ "a": "b",
+ "c": "d"
+ }
+ """
+
+ describe "Minify JSON file", ->
+ beforeEach ->
+ editor.setGrammar(atom.syntax.selectGrammar('test.json'))
+
+ it "Returns same string from invalid JSON", ->
+ editor.setText """
+ {
+ [
+ }
+ """
+
+ minify ->
+ expect(editor.getText()).toBe """
+ {
+ [
+ }
+ """
+
+ it "Minifies valid JSON", ->
+ editor.setText """
+ {
+ "a": "b",
+ "c": "d",
+ "num": 123
+ }
+ """
+
+ minify ->
+ expect(editor.getText()).toBe """
+ {"a":"b","c":"d","num":123}
+ """
+
+ describe "Minify selected JSON", ->
+ it "Minifies JSON data", ->
+ editor.setText """
+ Start
+ {
+ "a": "b",
+ "c": "d",
+ "num": 123
+ }
+ End
+ """
+ editor.setSelectedBufferRange([[1,0], [5, 1]])
+
+ minify ->
+ expect(editor.getText()).toBe """
+ Start
+ {"a":"b","c":"d","num":123}
+ End
+ """