mirror of
https://github.com/BoostIo/Boostnote
synced 2025-12-13 01:36:22 +00:00
Merge branch 'master' into migrate-to-jest
# Conflicts: # tests/lib/snapshots/markdown-test.js.md # tests/lib/snapshots/markdown-test.js.snap
This commit is contained in:
@@ -578,6 +578,72 @@ it('should test that deleteAttachmentsNotPresentInNote does nothing if noteKey,
|
||||
expect(fs.unlink).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('should test that getAttachmentsPathAndStatus return null if noteKey, storageKey or noteContent was undefined', function () {
|
||||
const noteKey = undefined
|
||||
const storageKey = undefined
|
||||
const markdownContent = ''
|
||||
|
||||
const result = systemUnderTest.getAttachmentsPathAndStatus(markdownContent, storageKey, noteKey)
|
||||
expect(result).toBeNull()
|
||||
})
|
||||
|
||||
it('should test that getAttachmentsPathAndStatus return null if noteKey, storageKey or noteContent was null', function () {
|
||||
const noteKey = null
|
||||
const storageKey = null
|
||||
const markdownContent = ''
|
||||
|
||||
const result = systemUnderTest.getAttachmentsPathAndStatus(markdownContent, storageKey, noteKey)
|
||||
expect(result).toBeNull()
|
||||
})
|
||||
|
||||
it('should test that getAttachmentsPathAndStatus return the correct path and status for attachments', async function () {
|
||||
const dummyStorage = {path: 'dummyStoragePath'}
|
||||
const noteKey = 'noteKey'
|
||||
const storageKey = 'storageKey'
|
||||
const markdownContent =
|
||||
'Test input' +
|
||||
' \n'
|
||||
const dummyFilesInFolder = ['file1.txt', 'file2.pdf', 'file3.jpg']
|
||||
|
||||
findStorage.findStorage = jest.fn(() => dummyStorage)
|
||||
fs.existsSync = jest.fn(() => true)
|
||||
fs.readdir = jest.fn((paht, callback) => callback(undefined, dummyFilesInFolder))
|
||||
fs.unlink = jest.fn()
|
||||
|
||||
const targetStorage = findStorage.findStorage(storageKey)
|
||||
|
||||
const attachments = await systemUnderTest.getAttachmentsPathAndStatus(markdownContent, storageKey, noteKey)
|
||||
expect(attachments.length).toBe(3)
|
||||
expect(attachments[0].isInUse).toBe(false)
|
||||
expect(attachments[1].isInUse).toBe(true)
|
||||
expect(attachments[2].isInUse).toBe(false)
|
||||
|
||||
expect(attachments[0].path).toBe(
|
||||
path.join(
|
||||
targetStorage.path,
|
||||
systemUnderTest.DESTINATION_FOLDER,
|
||||
noteKey,
|
||||
dummyFilesInFolder[0]
|
||||
)
|
||||
)
|
||||
expect(attachments[1].path).toBe(
|
||||
path.join(
|
||||
targetStorage.path,
|
||||
systemUnderTest.DESTINATION_FOLDER,
|
||||
noteKey,
|
||||
dummyFilesInFolder[1]
|
||||
)
|
||||
)
|
||||
expect(attachments[2].path).toBe(
|
||||
path.join(
|
||||
targetStorage.path,
|
||||
systemUnderTest.DESTINATION_FOLDER,
|
||||
noteKey,
|
||||
dummyFilesInFolder[2]
|
||||
)
|
||||
)
|
||||
})
|
||||
|
||||
it('should test that moveAttachments moves attachments only if the source folder existed', function () {
|
||||
fse.existsSync = jest.fn(() => false)
|
||||
fse.moveSync = jest.fn()
|
||||
|
||||
43
tests/dataApi/createNoteFromUrl-test.js
Normal file
43
tests/dataApi/createNoteFromUrl-test.js
Normal file
@@ -0,0 +1,43 @@
|
||||
const test = require('ava')
|
||||
const createNoteFromUrl = require('browser/main/lib/dataApi/createNoteFromUrl')
|
||||
|
||||
global.document = require('jsdom').jsdom('<body></body>')
|
||||
global.window = document.defaultView
|
||||
global.navigator = window.navigator
|
||||
|
||||
const Storage = require('dom-storage')
|
||||
const localStorage = window.localStorage = global.localStorage = new Storage(null, { strict: true })
|
||||
const path = require('path')
|
||||
const TestDummy = require('../fixtures/TestDummy')
|
||||
const sander = require('sander')
|
||||
const os = require('os')
|
||||
const CSON = require('@rokt33r/season')
|
||||
|
||||
const storagePath = path.join(os.tmpdir(), 'test/create-note-from-url')
|
||||
|
||||
test.beforeEach((t) => {
|
||||
t.context.storage = TestDummy.dummyStorage(storagePath)
|
||||
localStorage.setItem('storages', JSON.stringify([t.context.storage.cache]))
|
||||
})
|
||||
|
||||
test.serial('Create a note from URL', (t) => {
|
||||
const storageKey = t.context.storage.cache.key
|
||||
const folderKey = t.context.storage.json.folders[0].key
|
||||
|
||||
const url = 'https://shapeshed.com/writing-cross-platform-node/'
|
||||
|
||||
return createNoteFromUrl(url, storageKey, folderKey)
|
||||
.then(function assert ({ note }) {
|
||||
t.is(storageKey, note.storage)
|
||||
const jsonData = CSON.readFileSync(path.join(storagePath, 'notes', note.key + '.cson'))
|
||||
|
||||
// Test if saved content is matching the created in memory note
|
||||
t.is(note.content, jsonData.content)
|
||||
t.is(note.tags.length, jsonData.tags.length)
|
||||
})
|
||||
})
|
||||
|
||||
test.after(function after () {
|
||||
localStorage.clear()
|
||||
sander.rimrafSync(storagePath)
|
||||
})
|
||||
77
tests/fixtures/markdowns.js
vendored
77
tests/fixtures/markdowns.js
vendored
@@ -109,6 +109,76 @@ const footnote = `
|
||||
hello-world: https://github.com/BoostIO/Boostnote/
|
||||
`
|
||||
|
||||
const plantUmlMindMap = `
|
||||
@startmindmap
|
||||
* Debian
|
||||
** Ubuntu
|
||||
*** Linux Mint
|
||||
*** Kubuntu
|
||||
*** Lubuntu
|
||||
*** KDE Neon
|
||||
** LMDE
|
||||
** SolydXK
|
||||
** SteamOS
|
||||
** Raspbian with a very long name
|
||||
*** <s>Raspmbc</s> => OSMC
|
||||
*** <s>Raspyfi</s> => Volumio
|
||||
@endmindmap
|
||||
`
|
||||
|
||||
const plantUmlGantt = `
|
||||
@startgantt
|
||||
[Prototype design] lasts 15 days
|
||||
[Test prototype] lasts 10 days
|
||||
[Test prototype] starts at [Prototype design]'s end
|
||||
@endgantt
|
||||
`
|
||||
|
||||
const plantUmlWbs = `
|
||||
@startwbs
|
||||
* Business Process Modelling WBS
|
||||
** Launch the project
|
||||
*** Complete Stakeholder Research
|
||||
*** Initial Implementation Plan
|
||||
** Design phase
|
||||
*** Model of AsIs Processes Completed
|
||||
**** Model of AsIs Processes Completed1
|
||||
**** Model of AsIs Processes Completed2
|
||||
*** Measure AsIs performance metrics
|
||||
*** Identify Quick Wins
|
||||
** Complete innovate phase
|
||||
@endwbs
|
||||
`
|
||||
|
||||
const plantUmlUml = `
|
||||
@startuml
|
||||
left to right direction
|
||||
skinparam packageStyle rectangle
|
||||
actor customer
|
||||
actor clerk
|
||||
rectangle checkout {
|
||||
customer -- (checkout)
|
||||
(checkout) .> (payment) : include
|
||||
(help) .> (checkout) : extends
|
||||
(checkout) -- clerk
|
||||
}
|
||||
@enduml
|
||||
`
|
||||
|
||||
const plantUmlDitaa = `
|
||||
@startditaa
|
||||
+--------+ +-------+ +-------+
|
||||
| +---+ ditaa +--> | |
|
||||
| Text | +-------+ |Diagram|
|
||||
|Dokument| |!Magie!| | |
|
||||
| {d}| | | | |
|
||||
+---+----+ +-------+ +-------+
|
||||
: ^
|
||||
| Ein Haufen Arbeit |
|
||||
+-------------------------+
|
||||
@endditaa
|
||||
`
|
||||
|
||||
export default {
|
||||
basic,
|
||||
codeblock,
|
||||
@@ -121,5 +191,10 @@ export default {
|
||||
supTexts,
|
||||
deflists,
|
||||
shortcuts,
|
||||
footnote
|
||||
footnote,
|
||||
plantUmlMindMap,
|
||||
plantUmlGantt,
|
||||
plantUmlWbs,
|
||||
plantUmlDitaa,
|
||||
plantUmlUml
|
||||
}
|
||||
|
||||
@@ -1,5 +1,30 @@
|
||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`Markdown.render() should render PlantUML Ditaa correctly 1`] = `
|
||||
"<img src=\\"http://www.plantuml.com/plantuml/png/SoWkIImgISaiIKpaqjQ50cq51GLj93Q2mrMZ00NQO3cmHX3RJW4cKmDI4v9QKQ805a8nfyObCp6zA34NgCObFxiqDpMl1AIcHj4tCJqpLH5i18evG52TKbk3B8og1kmC0cvMKB1Im0NYkA2ckMRcANWabgQbvYau5YMbPfP0p4UOWmcqkHnIyrB0GG00\\" alt=\\"uml diagram\\" />
|
||||
"
|
||||
`;
|
||||
|
||||
exports[`Markdown.render() should render PlantUML Gantt correctly 1`] = `
|
||||
"<img src=\\"http://www.plantuml.com/plantuml/svg/SoWkIImgIK_CAodXYWueoY_9BwaiI5L8IItEJC-BLSX9B2ufLZ0qLKX9h2pcYWv9BIvHA82fWaiRu906crsia5YYW6cqUh52QbuAbmEG0DiE0000\\" alt=\\"uml diagram\\" />
|
||||
"
|
||||
`;
|
||||
|
||||
exports[`Markdown.render() should render PlantUML MindMaps correctly 1`] = `
|
||||
"<img src=\\"http://www.plantuml.com/plantuml/svg/JOzD3e8m44Rtd6BMtNW192IM5I29HEDsAbKdeLD2MvNRIsjCMCsRlFd9LpgFipV4Wy4f4o2r8kHC23Yhm3wi9A0X3XzeYNrgwx1H6wvb1KTjqtRJoYhMtexBSAqJUescwoEUq4tn3xp9Fm7XfUS5HiiFO3Gw7SjT4QUCkkKxLy2-WAvl3rkrtEclBdOCXcnMwZN7ByiN\\" alt=\\"uml diagram\\" />
|
||||
"
|
||||
`;
|
||||
|
||||
exports[`Markdown.render() should render PlantUML Umls correctly 1`] = `
|
||||
"<img src=\\"http://www.plantuml.com/plantuml/svg/LOzD2eCm44RtESMtj0jx01V5E_G4Gvngo2_912gbTsz4LBfylCV7p5Y4ibJlbEENG2AocHV1P39hCJ6eOar8bCaZaROqyrDMnzWqXTcn8YqnGzSYqNC-q76sweoW5zOsLi57uMpHz-WESslY0jmVw1AjdaE30IPeLoVUceLTslrL3-2tS9ZA_qZRtm_vgh7PzkOF\\" alt=\\"uml diagram\\" />
|
||||
"
|
||||
`;
|
||||
|
||||
exports[`Markdown.render() should render PlantUML WBS correctly 1`] = `
|
||||
"<img src=\\"http://www.plantuml.com/plantuml/svg/ZP2_JiD03CRtFeNdRF04fR140gdGeREv-z8plVYYimFYxSabKbaxsR9-ylTdRyxLVpvjrz5XDb6OqR6MqEPRYSXPz4BdmsdNTVJAiuP4da1JBLy8lbmxUYxZbE6Wa_CLgUI8IXymS0rf9NeL5yxKDt24EhiKfMDcRNzVO79HcX8RLdvLfZBGa_KtFx2RKcpK7TZ3dTpZfWgskMAZ9jIXr94rW4PubM1RbBZOb-6NtcS9LpgBjlj_1w9QldbPjZHxQ5pg_GC0\\" alt=\\"uml diagram\\" />
|
||||
"
|
||||
`;
|
||||
|
||||
exports[`Markdown.render() should render footnote correctly 1`] = `
|
||||
"<p data-line=\\"1\\"><sup class=\\"footnote-ref\\"><a href=\\"#fn1\\" id=\\"fnref1\\">[1]</a></sup><br />
|
||||
hello-world: <a href=\\"https://github.com/BoostIO/Boostnote/\\">https://github.com/BoostIO/Boostnote/</a></p>
|
||||
|
||||
@@ -72,3 +72,28 @@ test('Markdown.render() should render footnote correctly', () => {
|
||||
const rendered = md.render(markdownFixtures.footnote)
|
||||
expect(rendered).toMatchSnapshot()
|
||||
})
|
||||
|
||||
test('Markdown.render() should render PlantUML MindMaps correctly', t => {
|
||||
const rendered = md.render(markdownFixtures.plantUmlMindMap)
|
||||
expect(rendered).toMatchSnapshot()
|
||||
})
|
||||
|
||||
test('Markdown.render() should render PlantUML Gantt correctly', t => {
|
||||
const rendered = md.render(markdownFixtures.plantUmlGantt)
|
||||
expect(rendered).toMatchSnapshot()
|
||||
})
|
||||
|
||||
test('Markdown.render() should render PlantUML WBS correctly', t => {
|
||||
const rendered = md.render(markdownFixtures.plantUmlWbs)
|
||||
expect(rendered).toMatchSnapshot()
|
||||
})
|
||||
|
||||
test('Markdown.render() should render PlantUML Umls correctly', t => {
|
||||
const rendered = md.render(markdownFixtures.plantUmlUml)
|
||||
expect(rendered).toMatchSnapshot()
|
||||
})
|
||||
|
||||
test('Markdown.render() should render PlantUML Ditaa correctly', t => {
|
||||
const rendered = md.render(markdownFixtures.plantUmlDitaa)
|
||||
expect(rendered).toMatchSnapshot()
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user