From 06a3d6866e4f545abddd6654e490e50b623330a9 Mon Sep 17 00:00:00 2001 From: Ben Beltran Date: Thu, 2 Mar 2017 13:13:31 -0600 Subject: Update atoms --- atom/packages/pretty-json/spec/index-spec.coffee | 186 +++++++++++++++++++++++ 1 file changed, 186 insertions(+) create mode 100644 atom/packages/pretty-json/spec/index-spec.coffee (limited to 'atom/packages/pretty-json/spec') 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 + """ -- cgit