-
-
Notifications
You must be signed in to change notification settings - Fork 5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
208 additions
and
4 deletions.
There are no files selected for viewing
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
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,123 @@ | ||
/* eslint-disable no-unused-vars */ | ||
require('app-module-path').addPath(__dirname); | ||
const { setupDatabaseAndSynchronizer, switchClient, asyncTest } = require('test-utils.js'); | ||
const Setting = require('lib/models/Setting.js'); | ||
const Folder = require('lib/models/Folder.js'); | ||
const Note = require('lib/models/Note.js'); | ||
const Tag = require('lib/models/Tag.js'); | ||
const { BaseApplication } = require('lib/BaseApplication.js'); | ||
const { time } = require('lib/time-utils.js'); | ||
const { ALL_NOTES_FILTER_ID } = require('lib/reserved-ids.js'); | ||
|
||
// | ||
// The integration tests are to test the integration of the core system, comprising the | ||
// base application with middleware, reducer and models in response to dispatched events. | ||
// | ||
// The general strategy for each integration test is: | ||
// - create a starting application state, | ||
// - inject the event to be tested | ||
// - check the resulting application state | ||
// | ||
// In particular, this file contains integration tests for smart filter features. | ||
// | ||
|
||
async function createNTestFolders(n) { | ||
let folders = []; | ||
for (let i = 0; i < n; i++) { | ||
let folder = await Folder.save({ title: 'folder' }); | ||
folders.push(folder); | ||
} | ||
return folders; | ||
} | ||
|
||
async function createNTestNotes(n, folder) { | ||
let notes = []; | ||
for (let i = 0; i < n; i++) { | ||
let note = await Note.save({ title: 'note', parent_id: folder.id, is_conflict: 0 }); | ||
notes.push(note); | ||
} | ||
return notes; | ||
} | ||
|
||
async function createNTestTags(n) { | ||
let tags = []; | ||
for (let i = 0; i < n; i++) { | ||
let tag = await Tag.save({ title: 'tag' }); | ||
tags.push(tag); | ||
} | ||
return tags; | ||
} | ||
|
||
// use this until Javascript arr.flat() function works in Travis | ||
function flatten(arr) { | ||
return (arr.reduce((acc, val) => acc.concat(val), [])); | ||
} | ||
|
||
let baseApplication = null; | ||
|
||
describe('integration_SmartFilters', function() { | ||
|
||
beforeEach(async (done) => { | ||
await setupDatabaseAndSynchronizer(1); | ||
await switchClient(1); | ||
|
||
baseApplication = new BaseApplication(); | ||
baseApplication.initRedux(); | ||
Setting.dispatchUpdateAll(); | ||
done(); | ||
}); | ||
|
||
afterEach(async (done) => { | ||
baseApplication.deinitRedux(); | ||
baseApplication.destroy(); | ||
baseApplication = null; | ||
done(); | ||
}); | ||
|
||
it('should show notes in a folder', asyncTest(async () => { | ||
let folders = await createNTestFolders(2); | ||
let notes = []; | ||
for (let i = 0; i < folders.length; i++) { | ||
notes.push(await createNTestNotes(3, folders[i])); | ||
} | ||
|
||
baseApplication.dispatch({ | ||
type: 'FOLDER_SELECT', | ||
id: folders[1].id, | ||
}); | ||
await time.msleep(100); | ||
|
||
let state = baseApplication.store().getState(); | ||
|
||
expect(state.notesParentType).toEqual('Folder'); | ||
expect(state.selectedFolderId).toEqual(folders[1].id); | ||
|
||
let expectedNoteIds = notes[1].map(n => n.id).sort(); | ||
let noteIds = state.notes.map(n => n.id).sort(); | ||
expect(noteIds).toEqual(expectedNoteIds); | ||
})); | ||
|
||
it('should show all notes', asyncTest(async () => { | ||
let folders = await createNTestFolders(2); | ||
let notes = []; | ||
for (let i = 0; i < folders.length; i++) { | ||
notes.push(await createNTestNotes(3, folders[i])); | ||
} | ||
|
||
baseApplication.dispatch({ | ||
type: 'SMART_FILTER_SELECT', | ||
id: ALL_NOTES_FILTER_ID, | ||
}); | ||
await time.msleep(100); | ||
|
||
let state = baseApplication.store().getState(); | ||
|
||
expect(state.notesParentType).toEqual('SmartFilter'); | ||
expect(state.selectedSmartFilterId).toEqual(ALL_NOTES_FILTER_ID); | ||
|
||
// let expectedNoteIds = notes.map(n => n.map(o => o.id)).flat().sort(); | ||
let expectedNoteIds = flatten(notes.map(n => n.map(o => o.id))).sort(); | ||
let noteIds = state.notes.map(n => n.id).sort(); | ||
expect(noteIds).toEqual(expectedNoteIds); | ||
})); | ||
}); |
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
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
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
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
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
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
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,13 @@ | ||
const BaseModel = require('lib/BaseModel.js'); | ||
|
||
class SmartFilter extends BaseModel { | ||
static tableName() { | ||
throw new Error('Not using database'); | ||
} | ||
|
||
static modelType() { | ||
return BaseModel.TYPE_SMART_FILTER; | ||
} | ||
} | ||
|
||
module.exports = SmartFilter; |
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
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,6 @@ | ||
|
||
module.exports = Object.freeze({ | ||
|
||
ALL_NOTES_FILTER_ID: 'c3176726992c11e9ac940492261af972', | ||
|
||
}); |