mirror of
https://github.com/BoostIo/Boostnote
synced 2025-12-15 10:46:32 +00:00
fixed eslint error & integrated with prettier as well as formatted the whole codebase (#3450)
This commit is contained in:
@@ -1,18 +1,32 @@
|
||||
let menuBuilderParameter
|
||||
jest.mock('electron', () => {
|
||||
return {remote: {require: jest.fn(() => { return {Menu: {buildFromTemplate: jest.fn((param) => { menuBuilderParameter = param })}} })}}
|
||||
return {
|
||||
remote: {
|
||||
require: jest.fn(() => {
|
||||
return {
|
||||
Menu: {
|
||||
buildFromTemplate: jest.fn(param => {
|
||||
menuBuilderParameter = param
|
||||
})
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
const spellcheck = require('browser/lib/spellcheck')
|
||||
const buildEditorContextMenu = require('browser/lib/contextMenuBuilder').buildEditorContextMenu
|
||||
const buildMarkdownPreviewContextMenu = require('browser/lib/contextMenuBuilder').buildMarkdownPreviewContextMenu
|
||||
const buildEditorContextMenu = require('browser/lib/contextMenuBuilder')
|
||||
.buildEditorContextMenu
|
||||
const buildMarkdownPreviewContextMenu = require('browser/lib/contextMenuBuilder')
|
||||
.buildMarkdownPreviewContextMenu
|
||||
|
||||
beforeEach(() => {
|
||||
menuBuilderParameter = null
|
||||
})
|
||||
|
||||
// Editor Context Menu
|
||||
it('should make sure that no context menu is build if the passed editor instance was null', function () {
|
||||
it('should make sure that no context menu is build if the passed editor instance was null', function() {
|
||||
const event = {
|
||||
pageX: 12,
|
||||
pageY: 12
|
||||
@@ -21,89 +35,96 @@ it('should make sure that no context menu is build if the passed editor instance
|
||||
expect(menuBuilderParameter).toEqual(null)
|
||||
})
|
||||
|
||||
it('should make sure that word suggestions are only requested if the word contained a typo', function () {
|
||||
it('should make sure that word suggestions are only requested if the word contained a typo', function() {
|
||||
spellcheck.getSpellingSuggestion = jest.fn()
|
||||
const editor = jest.fn()
|
||||
editor.coordsChar = jest.fn()
|
||||
editor.findWordAt = jest.fn(() => { return {anchor: {}, head: {}} })
|
||||
editor.findWordAt = jest.fn(() => {
|
||||
return { anchor: {}, head: {} }
|
||||
})
|
||||
editor.getRange = jest.fn()
|
||||
editor.findMarks = jest.fn(() => [])
|
||||
const event = {
|
||||
pageX: 12,
|
||||
pageY: 12
|
||||
}
|
||||
const expectedMenuParameter = [ { role: 'cut' },
|
||||
const expectedMenuParameter = [
|
||||
{ role: 'cut' },
|
||||
{ role: 'copy' },
|
||||
{ role: 'paste' },
|
||||
{ role: 'selectall' } ]
|
||||
{ role: 'selectall' }
|
||||
]
|
||||
buildEditorContextMenu(editor, event)
|
||||
expect(menuBuilderParameter).toEqual(expectedMenuParameter)
|
||||
expect(spellcheck.getSpellingSuggestion).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('should make sure that word suggestions are only requested if the word contained a typo and no other mark', function () {
|
||||
it('should make sure that word suggestions are only requested if the word contained a typo and no other mark', function() {
|
||||
spellcheck.getSpellingSuggestion = jest.fn()
|
||||
spellcheck.getCSSClassName = jest.fn(() => 'dummyErrorClassName')
|
||||
const editor = jest.fn()
|
||||
editor.coordsChar = jest.fn()
|
||||
editor.findWordAt = jest.fn(() => { return {anchor: {}, head: {}} })
|
||||
editor.findWordAt = jest.fn(() => {
|
||||
return { anchor: {}, head: {} }
|
||||
})
|
||||
editor.getRange = jest.fn()
|
||||
const dummyMarks = [
|
||||
{className: 'someStupidClassName'}
|
||||
]
|
||||
const dummyMarks = [{ className: 'someStupidClassName' }]
|
||||
editor.findMarks = jest.fn(() => dummyMarks)
|
||||
const event = {
|
||||
pageX: 12,
|
||||
pageY: 12
|
||||
}
|
||||
const expectedMenuParameter = [ { role: 'cut' },
|
||||
const expectedMenuParameter = [
|
||||
{ role: 'cut' },
|
||||
{ role: 'copy' },
|
||||
{ role: 'paste' },
|
||||
{ role: 'selectall' } ]
|
||||
{ role: 'selectall' }
|
||||
]
|
||||
buildEditorContextMenu(editor, event)
|
||||
expect(menuBuilderParameter).toEqual(expectedMenuParameter)
|
||||
expect(spellcheck.getSpellingSuggestion).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('should make sure that word suggestions calls the right editor functions', function () {
|
||||
it('should make sure that word suggestions calls the right editor functions', function() {
|
||||
spellcheck.getSpellingSuggestion = jest.fn()
|
||||
spellcheck.getCSSClassName = jest.fn(() => 'dummyErrorClassName')
|
||||
const dummyCursor = {dummy: 'dummy'}
|
||||
const dummyRange = {anchor: {test: 'test'}, head: {test2: 'test2'}}
|
||||
const dummyCursor = { dummy: 'dummy' }
|
||||
const dummyRange = { anchor: { test: 'test' }, head: { test2: 'test2' } }
|
||||
const editor = jest.fn()
|
||||
editor.coordsChar = jest.fn(() => dummyCursor)
|
||||
editor.findWordAt = jest.fn(() => dummyRange)
|
||||
editor.getRange = jest.fn()
|
||||
const dummyMarks = [
|
||||
{className: 'someStupidClassName'}
|
||||
]
|
||||
const dummyMarks = [{ className: 'someStupidClassName' }]
|
||||
editor.findMarks = jest.fn(() => dummyMarks)
|
||||
const event = {
|
||||
pageX: 12,
|
||||
pageY: 21
|
||||
}
|
||||
|
||||
const expectedCoordsCharCall = {left: event.pageX, top: event.pageY}
|
||||
const expectedCoordsCharCall = { left: event.pageX, top: event.pageY }
|
||||
|
||||
buildEditorContextMenu(editor, event)
|
||||
|
||||
expect(editor.coordsChar).toHaveBeenCalledWith(expectedCoordsCharCall)
|
||||
expect(editor.findWordAt).toHaveBeenCalledWith(dummyCursor)
|
||||
expect(editor.getRange).toHaveBeenCalledWith(dummyRange.anchor, dummyRange.head)
|
||||
expect(editor.getRange).toHaveBeenCalledWith(
|
||||
dummyRange.anchor,
|
||||
dummyRange.head
|
||||
)
|
||||
})
|
||||
|
||||
it('should make sure that word suggestions creates a correct menu if there was an error', function () {
|
||||
it('should make sure that word suggestions creates a correct menu if there was an error', function() {
|
||||
const suggestions = ['test1', 'test2', 'Pustekuchen']
|
||||
const errorClassName = 'errorCSS'
|
||||
const wordToCorrect = 'pustekuchen'
|
||||
const dummyMarks = [
|
||||
{className: errorClassName}
|
||||
]
|
||||
const dummyMarks = [{ className: errorClassName }]
|
||||
spellcheck.getSpellingSuggestion = jest.fn(() => suggestions)
|
||||
spellcheck.getCSSClassName = jest.fn(() => errorClassName)
|
||||
const editor = jest.fn()
|
||||
editor.coordsChar = jest.fn()
|
||||
editor.findWordAt = jest.fn(() => { return {anchor: {}, head: {}} })
|
||||
editor.findWordAt = jest.fn(() => {
|
||||
return { anchor: {}, head: {} }
|
||||
})
|
||||
editor.getRange = jest.fn(() => wordToCorrect)
|
||||
editor.findMarks = jest.fn(() => [])
|
||||
|
||||
@@ -128,7 +149,7 @@ it('should make sure that word suggestions creates a correct menu if there was a
|
||||
})
|
||||
|
||||
// Markdown Preview Context Menu
|
||||
it('should make sure that no context menu is built if the Markdown Preview instance was null', function () {
|
||||
it('should make sure that no context menu is built if the Markdown Preview instance was null', function() {
|
||||
const event = {
|
||||
pageX: 12,
|
||||
pageY: 12
|
||||
|
||||
Reference in New Issue
Block a user