New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Desktop: Resolves #6167 : Move to notebook cannot distinguish notebooks with the same name #6400
Closed
Closed
Changes from all commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
eedd9ec
Update CodeMirror.tsx
bishoy-magdy dc9c9b8
Update CodeMirror.tsx
bishoy-magdy d10252b
Update CodeMirror.tsx
bishoy-magdy c19a66c
Update CodeMirror.tsx
bishoy-magdy 63683e9
Update CodeMirror.tsx
bishoy-magdy d2c88d1
Merge branch 'laurent22:dev' into dev
bishoy-magdy 1105eea
Merge branch 'laurent22:dev' into dev
bishoy-magdy c9dd7ec
Merge branch 'laurent22:dev' into dev
bishoy-magdy 03f3187
Merge branch 'laurent22:dev' into dev
bishoy-magdy a301f30
Update moveToFolder.ts
bishoy-magdy 1c1e535
Update PromptDialog.jsx
bishoy-magdy af62fb3
Create moveToFolder.test.js
bishoy-magdy 7802a97
Merge branch 'dev' into dev
laurent22 ff2ab91
Update PromptDialog.jsx
bishoy-magdy a055611
Update moveToFolder.ts
bishoy-magdy 9c7e580
Update moveToFolder.test.js
bishoy-magdy 7d86145
Update moveToFolder.ts
bishoy-magdy 6079bc9
Update moveToFolder.test.js
bishoy-magdy 24e3c80
Update PromptDialog.jsx
bishoy-magdy ce8fa6a
Update PromptDialog.jsx
bishoy-magdy df71ce5
Update moveToFolder.test.js
bishoy-magdy f1f90a0
Update moveToFolder.ts
bishoy-magdy File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
106 changes: 106 additions & 0 deletions
106
packages/app-desktop/gui/MainScreen/commands/moveToFolder.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
const moveToFolder = require('./moveToFolder'); | ||
|
||
|
||
describe('AddOptions: Test The Path of Folders', () => { | ||
|
||
const options = new moveToFolder.AddOptions(); | ||
|
||
beforeEach(() => { | ||
options.startFolders = []; | ||
}); | ||
|
||
it('Empty Folder Title', () => { | ||
const testCases = [{ | ||
id: 1, title: '', | ||
children: [{ | ||
id: 2, title: '', | ||
}], | ||
}]; | ||
|
||
options.addOptions(testCases, 0, ''); | ||
const data = options.startFolders; | ||
expect(data[0].path).toEqual(''); | ||
}); | ||
|
||
it('Different Paths', () => { | ||
const testCases = [ | ||
{ id: 8, title: 'my Note' }, | ||
{ | ||
id: 2, title: 'first', | ||
children: [{ | ||
id: 3, title: 'second', | ||
children: [{ | ||
id: 4, title: 'third', | ||
children: [{ id: 5, title: 'fourth' }], | ||
}, { id: 6, title: 'fourth' }], | ||
}, { id: 7, title: 'fourth' }], | ||
}]; | ||
|
||
const answers = ['my Note', 'first', 'first/second', 'first/second/third', 'first/second/third/fourth', 'first/second/fourth', 'first/fourth']; | ||
|
||
options.addOptions(testCases, 0, ''); | ||
const data = options.startFolders; | ||
for (let i = 0; i < data.length; i++) { | ||
expect(data[i].path).toEqual(answers[i]); | ||
} | ||
|
||
}); | ||
|
||
it('Long Path', () => { | ||
const testCases = [{ | ||
id: 1, title: '1', | ||
children: [{ | ||
id: 2, title: '2', | ||
children: [{ | ||
id: 3, title: '3', | ||
children: [{ | ||
id: 4, title: '4', | ||
children: [{ | ||
id: 5, title: '5', | ||
children: [{ | ||
id: 6, title: '6', | ||
children: [{ | ||
id: 7, title: '7', | ||
children: [{ | ||
id: 8, title: '8', | ||
children: [{ | ||
id: 9, title: '9', | ||
children: [{ | ||
id: 10, title: '10', | ||
children: [{ | ||
id: 11, title: '11', | ||
children: [{ | ||
id: 12, title: '12', | ||
children: [{ | ||
id: 13, title: '13', | ||
children: [{ | ||
id: 14, title: '14', | ||
children: [{ id: 15, title: '15' }], | ||
}], | ||
}], | ||
}], | ||
}], | ||
}], | ||
}], | ||
}], | ||
}], | ||
}], | ||
}], | ||
}], | ||
}], | ||
}, { id: 16, title: '16' }], | ||
}]; | ||
|
||
options.addOptions(testCases, 0, ''); | ||
const data = options.startFolders; | ||
let answer = ''; | ||
for (let i = 1; i <= data.length - 1; i++) { | ||
answer += i; | ||
expect(data[i - 1].path).toEqual(answer); | ||
answer += '/'; | ||
} | ||
expect(data[data.length - 1].path).toEqual('1/16'); | ||
|
||
}); | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,31 +8,36 @@ export const declaration: CommandDeclaration = { | |
label: () => _('Move to notebook'), | ||
}; | ||
|
||
export class AddOptions { | ||
|
||
private maxDepth = 15; | ||
public startFolders: any[] = []; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. FolderEntity. No "any" of you can avoid it |
||
|
||
public addOptions(folders: any[], depth: number, path: string) { | ||
for (let i = 0; i < folders.length; i++) { | ||
const folder = folders[i]; | ||
const newPath = path + folder.title; | ||
this.startFolders.push({ key: folder.id, value: folder.id, label: folder.title, title: folder.title, path: newPath, indentDepth: depth, _indentDepth: depth }); | ||
if (folder.children) this.addOptions(folder.children, (depth + 1) < this.maxDepth ? depth + 1 : this.maxDepth, `${newPath}/`); | ||
} | ||
} | ||
} | ||
|
||
export const runtime = (comp: any): CommandRuntime => { | ||
return { | ||
execute: async (context: CommandContext, noteIds: string[] = null) => { | ||
noteIds = noteIds || context.state.selectedNoteIds; | ||
|
||
const folders: any[] = await Folder.sortFolderTree(); | ||
const startFolders: any[] = []; | ||
const maxDepth = 15; | ||
|
||
const addOptions = (folders: any[], depth: number) => { | ||
for (let i = 0; i < folders.length; i++) { | ||
const folder = folders[i]; | ||
startFolders.push({ key: folder.id, value: folder.id, label: folder.title, indentDepth: depth }); | ||
if (folder.children) addOptions(folder.children, (depth + 1) < maxDepth ? depth + 1 : maxDepth); | ||
} | ||
}; | ||
|
||
addOptions(folders, 0); | ||
const options = new AddOptions(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the naming is not good. Those are not options. |
||
options.addOptions(folders, 0, ''); | ||
|
||
comp.setState({ | ||
promptOptions: { | ||
label: _('Move to notebook:'), | ||
inputType: 'dropdown', | ||
value: '', | ||
autocomplete: startFolders, | ||
autocomplete: options.startFolders, | ||
onClose: async (answer: any) => { | ||
if (answer) { | ||
for (let i = 0; i < noteIds.length; i++) { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All new files should be TypeScript
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also unfortunately I have no idea what these test units do. Have a look at what other test units do. For example the title is often
it('should do this or that')
. What does your code do? Explain it clearly in the test title.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It tests the
AddOptions
function that returns paths of folders with different scenarios.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, I will try to refactor the code and convert the unit test to TS.