From 731ffd4a22d7549c609ff86f7ed69f34459741f9 Mon Sep 17 00:00:00 2001 From: asmsuechan Date: Sat, 12 Aug 2017 09:07:58 +0900 Subject: [PATCH 1/6] Add spec for getTodoStatus --- tests/lib/get-todo-status-test.js | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 tests/lib/get-todo-status-test.js diff --git a/tests/lib/get-todo-status-test.js b/tests/lib/get-todo-status-test.js new file mode 100644 index 00000000..55f951f5 --- /dev/null +++ b/tests/lib/get-todo-status-test.js @@ -0,0 +1,23 @@ +const test = require('ava') +const { getTodoStatus } = require('browser/lib/getTodoStatus') + +// Unit test +test('getTodoStatus should return a correct hash object', t => { + // [input, expected] + const testCases = [ + ['', { total: 0, completed: 0 }], + ['* [ ] a\n', { total: 1, completed: 0 }], + ['* [ ] a\n* [x] a\n', { total: 2, completed: 1 }], + ['- [ ] a\n', { total: 1, completed: 0 }], + ['- [ ] a\n- [x] a\n', { total: 2, completed: 1 }], + ['+ [ ] a\n', { total: 1, completed: 0 }], + ['+ [ ] a\n+ [x] a\n', { total: 2, completed: 1 }] + ] + + testCases.forEach(testCase => { + const [input, expected] = testCase + t.is(getTodoStatus(input).total, expected.total, `Test for getTodoStatus() input: ${input} expected: ${expected.total}`) + t.is(getTodoStatus(input).completed, expected.completed, `Test for getTodoStatus() input: ${input} expected: ${expected.completed}`) + }) +}) + From f05e256afcabbf6ddb4065b9961d8e814956be9d Mon Sep 17 00:00:00 2001 From: asmsuechan Date: Sat, 12 Aug 2017 09:08:42 +0900 Subject: [PATCH 2/6] Fix .boostnoterc.sample --- .boostnoterc.sample | 1 + 1 file changed, 1 insertion(+) diff --git a/.boostnoterc.sample b/.boostnoterc.sample index 25b7e64f..2caa2c1a 100644 --- a/.boostnoterc.sample +++ b/.boostnoterc.sample @@ -1,4 +1,5 @@ { + "amaEnabled": true, "editor": { "fontFamily": "Monaco, Consolas", "fontSize": "14", From 9405b95825ce40b5d9b3f88519e28b2a903605e6 Mon Sep 17 00:00:00 2001 From: asmsuechan Date: Sat, 12 Aug 2017 09:11:22 +0900 Subject: [PATCH 3/6] Change RcParser testable --- browser/main/lib/RcParser.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/browser/main/lib/RcParser.js b/browser/main/lib/RcParser.js index fa78df2b..00e52241 100644 --- a/browser/main/lib/RcParser.js +++ b/browser/main/lib/RcParser.js @@ -1,11 +1,11 @@ import path from 'path' import sander from 'sander' -function parse () { - const BOOSTNOTERC = '.boostnoterc' - const homePath = global.process.env.HOME || global.process.env.USERPROFILE - const boostnotercPath = path.join(homePath, BOOSTNOTERC) +const BOOSTNOTERC = '.boostnoterc' +const homePath = global.process.env.HOME || global.process.env.USERPROFILE +const _boostnotercPath = path.join(homePath, BOOSTNOTERC) +function parse (boostnotercPath = _boostnotercPath) { if (!sander.existsSync(boostnotercPath)) return {} try { return JSON.parse(sander.readFileSync(boostnotercPath).toString()) From 1e202db50f9938035f967d6d124a5febc224ed40 Mon Sep 17 00:00:00 2001 From: asmsuechan Date: Sat, 12 Aug 2017 09:36:30 +0900 Subject: [PATCH 4/6] Change the directory of RcParser --- browser/{main => }/lib/RcParser.js | 2 +- browser/main/lib/ConfigManager.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) rename browser/{main => }/lib/RcParser.js (89%) diff --git a/browser/main/lib/RcParser.js b/browser/lib/RcParser.js similarity index 89% rename from browser/main/lib/RcParser.js rename to browser/lib/RcParser.js index 00e52241..0df59476 100644 --- a/browser/main/lib/RcParser.js +++ b/browser/lib/RcParser.js @@ -5,7 +5,7 @@ const BOOSTNOTERC = '.boostnoterc' const homePath = global.process.env.HOME || global.process.env.USERPROFILE const _boostnotercPath = path.join(homePath, BOOSTNOTERC) -function parse (boostnotercPath = _boostnotercPath) { +export function parse (boostnotercPath = _boostnotercPath) { if (!sander.existsSync(boostnotercPath)) return {} try { return JSON.parse(sander.readFileSync(boostnotercPath).toString()) diff --git a/browser/main/lib/ConfigManager.js b/browser/main/lib/ConfigManager.js index 62730463..543c7e5b 100644 --- a/browser/main/lib/ConfigManager.js +++ b/browser/main/lib/ConfigManager.js @@ -1,5 +1,5 @@ import _ from 'lodash' -import RcParser from 'browser/main/lib/RcParser' +import RcParser from 'browser/lib/RcParser' const OSX = global.process.platform === 'darwin' const win = global.process.platform === 'win32' From fcaa5e21cf9050eb45c2f5e8d49651251d3e3b25 Mon Sep 17 00:00:00 2001 From: asmsuechan Date: Sat, 12 Aug 2017 09:36:39 +0900 Subject: [PATCH 5/6] Add tests for RcParser --- tests/lib/boostnoterc/.boostnoterc.all | 33 ++++++++++++++++++++++ tests/lib/boostnoterc/.boostnoterc.invalid | 12 ++++++++ tests/lib/boostnoterc/.boostnoterc.valid | 12 ++++++++ tests/lib/rc-parser-test.js | 33 ++++++++++++++++++++++ 4 files changed, 90 insertions(+) create mode 100644 tests/lib/boostnoterc/.boostnoterc.all create mode 100644 tests/lib/boostnoterc/.boostnoterc.invalid create mode 100644 tests/lib/boostnoterc/.boostnoterc.valid create mode 100644 tests/lib/rc-parser-test.js diff --git a/tests/lib/boostnoterc/.boostnoterc.all b/tests/lib/boostnoterc/.boostnoterc.all new file mode 100644 index 00000000..2caa2c1a --- /dev/null +++ b/tests/lib/boostnoterc/.boostnoterc.all @@ -0,0 +1,33 @@ +{ + "amaEnabled": true, + "editor": { + "fontFamily": "Monaco, Consolas", + "fontSize": "14", + "indentSize": "2", + "indentType": "space", + "keyMap": "vim", + "switchPreview": "BLUR", + "theme": "monokai" + }, + "hotkey": { + "toggleFinder": "Cmd + Alt + S", + "toggleMain": "Cmd + Alt + L" + }, + "isSideNavFolded": false, + "listStyle": "DEFAULT", + "listWidth": 174, + "navWidth": 200, + "preview": { + "codeBlockTheme": "dracula", + "fontFamily": "Lato", + "fontSize": "14", + "lineNumber": true + }, + "sortBy": "UPDATED_AT", + "ui": { + "defaultNote": "ALWAYS_ASK", + "disableDirectWrite": false, + "theme": "default" + }, + "zoom": 1 +} diff --git a/tests/lib/boostnoterc/.boostnoterc.invalid b/tests/lib/boostnoterc/.boostnoterc.invalid new file mode 100644 index 00000000..500327cb --- /dev/null +++ b/tests/lib/boostnoterc/.boostnoterc.invalid @@ -0,0 +1,12 @@ +{ + "editor": { + "keyMap": "vim", + "switchPreview": "BLUR", + "theme": "monokai", + }, + "hotkey": { + "toggleMain": "Control + L" + }, + "listWidth": 135, + "navWidth": 135 +} diff --git a/tests/lib/boostnoterc/.boostnoterc.valid b/tests/lib/boostnoterc/.boostnoterc.valid new file mode 100644 index 00000000..23f50f15 --- /dev/null +++ b/tests/lib/boostnoterc/.boostnoterc.valid @@ -0,0 +1,12 @@ +{ + "editor": { + "keyMap": "vim", + "switchPreview": "BLUR", + "theme": "monokai" + }, + "hotkey": { + "toggleMain": "Control + L" + }, + "listWidth": 135, + "navWidth": 135 +} diff --git a/tests/lib/rc-parser-test.js b/tests/lib/rc-parser-test.js new file mode 100644 index 00000000..29d0cdd2 --- /dev/null +++ b/tests/lib/rc-parser-test.js @@ -0,0 +1,33 @@ +const test = require('ava') +const path = require('path') +const { parse } = require('browser/lib/RcParser') + +// Unit test +test('RcParser should return a json object', t => { + const validJson = { "editor": { "keyMap": "vim", "switchPreview": "BLUR", "theme": "monokai" }, "hotkey": { "toggleMain": "Control + L" }, "listWidth": 135, "navWidth": 135 } + const allJson = { "amaEnabled": true, "editor": { "fontFamily": "Monaco, Consolas", "fontSize": "14", "indentSize": "2", "indentType": "space", "keyMap": "vim", "switchPreview": "BLUR", "theme": "monokai" }, "hotkey": { "toggleFinder": "Cmd + Alt + S", "toggleMain": "Cmd + Alt + L" }, "isSideNavFolded": false, "listStyle": "DEFAULT", "listWidth": 174, "navWidth": 200, "preview": { "codeBlockTheme": "dracula", "fontFamily": "Lato", "fontSize": "14", "lineNumber": true }, "sortBy": "UPDATED_AT", "ui": { "defaultNote": "ALWAYS_ASK", "disableDirectWrite": false, "theme": "default" }, "zoom": 1 } + + // [input, expected] + const validTestCases = [ + ['.boostnoterc.valid', validJson], + ['.boostnoterc.all', allJson] + ] + + const invalidTestCases = [ + ['.boostnoterc.invalid', {}] + ] + + validTestCases.forEach(validTestCase => { + const [input, expected] = validTestCase + t.is(parse(filePath(input)).editor.keyMap, expected.editor.keyMap, `Test for getTodoStatus() input: ${input} expected: ${expected.keyMap}`) + }) + + invalidTestCases.forEach(invalidTestCase => { + const [input, expected] = invalidTestCase + t.is(parse(filePath(input)).editor, expected.editor, `Test for getTodoStatus() input: ${input} expected: ${expected.editor}`) + }) +}) + +function filePath (filename) { + return path.join('boostnoterc', filename) +} From 46f7dfdfebacd40011b163c270b685cfe62bcadd Mon Sep 17 00:00:00 2001 From: asmsuechan Date: Sat, 12 Aug 2017 09:50:16 +0900 Subject: [PATCH 6/6] Change " to ' --- tests/lib/rc-parser-test.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/lib/rc-parser-test.js b/tests/lib/rc-parser-test.js index 29d0cdd2..a0f6d2a8 100644 --- a/tests/lib/rc-parser-test.js +++ b/tests/lib/rc-parser-test.js @@ -4,8 +4,8 @@ const { parse } = require('browser/lib/RcParser') // Unit test test('RcParser should return a json object', t => { - const validJson = { "editor": { "keyMap": "vim", "switchPreview": "BLUR", "theme": "monokai" }, "hotkey": { "toggleMain": "Control + L" }, "listWidth": 135, "navWidth": 135 } - const allJson = { "amaEnabled": true, "editor": { "fontFamily": "Monaco, Consolas", "fontSize": "14", "indentSize": "2", "indentType": "space", "keyMap": "vim", "switchPreview": "BLUR", "theme": "monokai" }, "hotkey": { "toggleFinder": "Cmd + Alt + S", "toggleMain": "Cmd + Alt + L" }, "isSideNavFolded": false, "listStyle": "DEFAULT", "listWidth": 174, "navWidth": 200, "preview": { "codeBlockTheme": "dracula", "fontFamily": "Lato", "fontSize": "14", "lineNumber": true }, "sortBy": "UPDATED_AT", "ui": { "defaultNote": "ALWAYS_ASK", "disableDirectWrite": false, "theme": "default" }, "zoom": 1 } + const validJson = { 'editor': { 'keyMap': 'vim', 'switchPreview': 'BLUR', 'theme': 'monokai' }, 'hotkey': { 'toggleMain': 'Control + L' }, 'listWidth': 135, 'navWidth': 135 } + const allJson = { 'amaEnabled': true, 'editor': { 'fontFamily': 'Monaco, Consolas', 'fontSize': '14', 'indentSize': '2', 'indentType': 'space', 'keyMap': 'vim', 'switchPreview': 'BLUR', 'theme': 'monokai' }, 'hotkey': { 'toggleFinder': 'Cmd + Alt + S', 'toggleMain': 'Cmd + Alt + L' }, 'isSideNavFolded': false, 'listStyle': 'DEFAULT', 'listWidth': 174, 'navWidth': 200, 'preview': { 'codeBlockTheme': 'dracula', 'fontFamily': 'Lato', 'fontSize': '14', 'lineNumber': true }, 'sortBy': 'UPDATED_AT', 'ui': { 'defaultNote': 'ALWAYS_ASK', 'disableDirectWrite': false, 'theme': 'default' }, 'zoom': 1 } // [input, expected] const validTestCases = [