Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
194 changes: 100 additions & 94 deletions dbludeau.TodoistNoteplanSync/__tests__/NPPluginMain.NOTACTIVE.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,23 @@
// Jest testing docs: https://jestjs.io/docs/using-matchers
/* eslint-disable */

import * as f from '../src/sortTasks'
import { CustomConsole, LogType, LogMessage } from '@jest/console' // see note below
import { Calendar, Clipboard, CommandBar, DataStore, Editor, NotePlan, simpleFormatter /* Note, mockWasCalledWithString, Paragraph */ } from '@mocks/index'
// import * as f from '../src/sortTasks'
// import { CustomConsole, LogType, LogMessage } from '@jest/console' // see note below
// import { Calendar, Clipboard, CommandBar, DataStore, Editor, NotePlan, simpleFormatter /* Note, mockWasCalledWithString, Paragraph */ } from '@mocks/index'

const PLUGIN_NAME = `{{pluginID}}`
const FILENAME = `NPPluginMain`
// const PLUGIN_NAME = `{{pluginID}}`
// const FILENAME = `NPPluginMain`

beforeAll(() => {
global.Calendar = Calendar
global.Clipboard = Clipboard
global.CommandBar = CommandBar
global.DataStore = DataStore
global.Editor = Editor
global.NotePlan = NotePlan
global.console = new CustomConsole(process.stdout, process.stderr, simpleFormatter) // minimize log footprint
DataStore.settings['_logLevel'] = 'DEBUG' //change this to DEBUG to get more logging (or 'none' for none)
})
// beforeAll(() => {
// global.Calendar = Calendar
// global.Clipboard = Clipboard
// global.CommandBar = CommandBar
// global.DataStore = DataStore
// global.Editor = Editor
// global.NotePlan = NotePlan
// global.console = new CustomConsole(process.stdout, process.stderr, simpleFormatter) // minimize log footprint
// DataStore.settings['_logLevel'] = 'DEBUG' //change this to DEBUG to get more logging (or 'none' for none)
// })

/* Samples:
expect(result).toMatch(/someString/)
Expand All @@ -41,84 +41,90 @@ import { mockWasCalledWith } from '@mocks/mockHelpers'
})
*/

describe('dbludeau.TodoistNoteplanSync' /* pluginID */, () => {
describe('NPPluginMain' /* file */, () => {
describe('sayHello' /* function */, () => {
test('should insert text if called with a string param', async () => {
// tests start with "should" to describe the expected behavior
const spy = jest.spyOn(Editor, 'insertTextAtCursor')
const result = await mainFile.sayHello('Testing...')
expect(spy).toHaveBeenCalled()
expect(spy).toHaveBeenNthCalledWith(
1,
`***You clicked the link!*** The message at the end of the link is "Testing...". Now the rest of the plugin will run just as before...\n\n`,
)
spy.mockRestore()
})
test('should write result to console', async () => {
// tests start with "should" to describe the expected behavior
const spy = jest.spyOn(console, 'log')
const result = await mainFile.sayHello()
expect(spy).toHaveBeenCalled()
expect(spy).toHaveBeenNthCalledWith(1, expect.stringMatching(/The plugin says: HELLO WORLD FROM TEST PLUGIN!/))
spy.mockRestore()
})
test('should call DataStore.settings', async () => {
// tests start with "should" to describe the expected behavior
const oldValue = DataStore.settings
DataStore.settings = { settingsString: 'settingTest' }
const spy = jest.spyOn(Editor, 'insertTextAtCursor')
const _ = await mainFile.sayHello()
expect(spy).toHaveBeenCalled()
expect(spy).toHaveBeenNthCalledWith(1, expect.stringMatching(/settingTest/))
DataStore.settings = oldValue
spy.mockRestore()
})
test('should call DataStore.settings if no value set', async () => {
// tests start with "should" to describe the expected behavior
const oldValue = DataStore.settings
DataStore.settings = { settingsString: undefined }
const spy = jest.spyOn(Editor, 'insertTextAtCursor')
const _ = await mainFile.sayHello()
expect(spy).toHaveBeenCalled()
expect(spy).toHaveBeenNthCalledWith(1, expect.stringMatching(/\*\*\"\"\*\*/))
DataStore.settings = oldValue
spy.mockRestore()
})
test('should CLO write note.paragraphs to console', async () => {
// tests start with "should" to describe the expected behavior
const prevEditorNoteValue = copyObject(Editor.note || {})
Editor.note = new Note({ filename: 'testingFile' })
Editor.note.paragraphs = [new Paragraph({ content: 'testingParagraph' })]
const spy = jest.spyOn(console, 'log')
const result = await mainFile.sayHello()
expect(spy).toHaveBeenCalled()
expect(spy).toHaveBeenNthCalledWith(2, expect.stringMatching(/\"content\": \"testingParagraph\"/))
Editor.note = prevEditorNoteValue
spy.mockRestore()
})
test('should insert a link if not called with a string param', async () => {
// tests start with "should" to describe the expected behavior
const spy = jest.spyOn(Editor, 'insertTextAtCursor')
const result = await mainFile.sayHello('')
expect(spy).toHaveBeenCalled()
expect(spy).toHaveBeenLastCalledWith(expect.stringMatching(/noteplan:\/\/x-callback-url\/runPlugin/))
spy.mockRestore()
})
test('should write an error to console on throw', async () => {
// tests start with "should" to describe the expected behavior
const spy = jest.spyOn(console, 'log')
const oldValue = Editor.insertTextAtCursor
delete Editor.insertTextAtCursor
try {
const result = await mainFile.sayHello()
} catch (e) {
expect(e.message).stringMatching(/ERROR/)
}
expect(spy).toHaveBeenCalledWith(expect.stringMatching(/ERROR/))
Editor.insertTextAtCursor = oldValue
spy.mockRestore()
})
})
describe('Placeholder', () => {
test('Placeholder', async () => {
expect(true).toBe(true)
})
})

// describe.skip('dbludeau.TodoistNoteplanSync' /* pluginID */, () => {
// describe('NPPluginMain' /* file */, () => {
// describe('sayHello' /* function */, () => {
// test('should insert text if called with a string param', async () => {
// // tests start with "should" to describe the expected behavior
// const spy = jest.spyOn(Editor, 'insertTextAtCursor')
// const result = await mainFile.sayHello('Testing...')
// expect(spy).toHaveBeenCalled()
// expect(spy).toHaveBeenNthCalledWith(
// 1,
// `***You clicked the link!*** The message at the end of the link is "Testing...". Now the rest of the plugin will run just as before...\n\n`,
// )
// spy.mockRestore()
// })
// test('should write result to console', async () => {
// // tests start with "should" to describe the expected behavior
// const spy = jest.spyOn(console, 'log')
// const result = await mainFile.sayHello()
// expect(spy).toHaveBeenCalled()
// expect(spy).toHaveBeenNthCalledWith(1, expect.stringMatching(/The plugin says: HELLO WORLD FROM TEST PLUGIN!/))
// spy.mockRestore()
// })
// test('should call DataStore.settings', async () => {
// // tests start with "should" to describe the expected behavior
// const oldValue = DataStore.settings
// DataStore.settings = { settingsString: 'settingTest' }
// const spy = jest.spyOn(Editor, 'insertTextAtCursor')
// const _ = await mainFile.sayHello()
// expect(spy).toHaveBeenCalled()
// expect(spy).toHaveBeenNthCalledWith(1, expect.stringMatching(/settingTest/))
// DataStore.settings = oldValue
// spy.mockRestore()
// })
// test('should call DataStore.settings if no value set', async () => {
// // tests start with "should" to describe the expected behavior
// const oldValue = DataStore.settings
// DataStore.settings = { settingsString: undefined }
// const spy = jest.spyOn(Editor, 'insertTextAtCursor')
// const _ = await mainFile.sayHello()
// expect(spy).toHaveBeenCalled()
// expect(spy).toHaveBeenNthCalledWith(1, expect.stringMatching(/\*\*\"\"\*\*/))
// DataStore.settings = oldValue
// spy.mockRestore()
// })
// test('should CLO write note.paragraphs to console', async () => {
// // tests start with "should" to describe the expected behavior
// const prevEditorNoteValue = copyObject(Editor.note || {})
// Editor.note = new Note({ filename: 'testingFile' })
// Editor.note.paragraphs = [new Paragraph({ content: 'testingParagraph' })]
// const spy = jest.spyOn(console, 'log')
// const result = await mainFile.sayHello()
// expect(spy).toHaveBeenCalled()
// expect(spy).toHaveBeenNthCalledWith(2, expect.stringMatching(/\"content\": \"testingParagraph\"/))
// Editor.note = prevEditorNoteValue
// spy.mockRestore()
// })
// test('should insert a link if not called with a string param', async () => {
// // tests start with "should" to describe the expected behavior
// const spy = jest.spyOn(Editor, 'insertTextAtCursor')
// const result = await mainFile.sayHello('')
// expect(spy).toHaveBeenCalled()
// expect(spy).toHaveBeenLastCalledWith(expect.stringMatching(/noteplan:\/\/x-callback-url\/runPlugin/))
// spy.mockRestore()
// })
// test('should write an error to console on throw', async () => {
// // tests start with "should" to describe the expected behavior
// const spy = jest.spyOn(console, 'log')
// const oldValue = Editor.insertTextAtCursor
// delete Editor.insertTextAtCursor
// try {
// const result = await mainFile.sayHello()
// } catch (e) {
// expect(e.message).stringMatching(/ERROR/)
// }
// expect(spy).toHaveBeenCalledWith(expect.stringMatching(/ERROR/))
// Editor.insertTextAtCursor = oldValue
// spy.mockRestore()
// })
// })
// })
// })
1 change: 1 addition & 0 deletions jgclark.tests/plugin.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"plugin.id": "jgclark.tests",
"plugin.name": "❓API Tests",
"plugin.description": "(Unpublished) API Tests by JGC",
"plugin.hidden": true,
"plugin.icon": "",
"plugin.author": "jgclark",
"plugin.url": "",
Expand Down
6 changes: 6 additions & 0 deletions np.Templating/__tests__/setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,9 @@ global.console = {
log: jest.fn(),
debug: jest.fn(),
}

describe('Placeholder', () => {
test('Placeholder', async () => {
expect(true).toBe(true)
})
})
6 changes: 6 additions & 0 deletions np.Templating/__tests__/testUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,9 @@ export async function factory(factoryName = '') {
}
return 'FACTORY_NOT_FOUND'
}

describe('Placeholder', () => {
test('Placeholder', async () => {
expect(true).toBe(true)
})
})
Loading