tests: fix memory leaks (#2389)

This commit is contained in:
Mo
2023-08-06 15:23:31 -05:00
committed by GitHub
parent d59e1befff
commit 8655bdb5dd
76 changed files with 3904 additions and 3840 deletions

View File

@@ -1,37 +1,26 @@
/* eslint-disable camelcase */
/* eslint-disable no-unused-expressions */
/* eslint-disable no-undef */
import { BaseItemCounts } from '../lib/BaseItemCounts.js'
import * as Factory from '../lib/factory.js'
chai.use(chaiAsPromised)
const expect = chai.expect
describe('app models', () => {
const sharedApplication = Factory.createApplicationWithFakeCrypto()
before(async function () {
localStorage.clear()
await Factory.initializeApplication(sharedApplication)
})
after(async function () {
localStorage.clear()
await Factory.safeDeinit(sharedApplication)
})
let application
let expectedItemCount
let context
beforeEach(async function () {
this.expectedItemCount = BaseItemCounts.DefaultItems
this.context = await Factory.createAppContext()
this.application = this.context.application
await this.context.launch()
localStorage.clear()
expectedItemCount = BaseItemCounts.DefaultItems
context = await Factory.createAppContext()
application = context.application
await context.launch()
})
afterEach(async function () {
await Factory.safeDeinit(this.application)
})
it('payloads should be defined', () => {
expect(sharedApplication.payloads).to.be.ok
await context.deinit()
localStorage.clear()
sinon.restore()
})
it('item should be defined', () => {
@@ -72,17 +61,17 @@ describe('app models', () => {
},
})
await this.application.mutator.emitItemsFromPayloads([mutated], PayloadEmitSource.LocalChanged)
await this.application.mutator.emitItemsFromPayloads([params2], PayloadEmitSource.LocalChanged)
await application.mutator.emitItemsFromPayloads([mutated], PayloadEmitSource.LocalChanged)
await application.mutator.emitItemsFromPayloads([params2], PayloadEmitSource.LocalChanged)
const item1 = this.application.items.findItem(params1.uuid)
const item2 = this.application.items.findItem(params2.uuid)
const item1 = application.items.findItem(params1.uuid)
const item2 = application.items.findItem(params2.uuid)
expect(item1.content.references.length).to.equal(1)
expect(item2.content.references.length).to.equal(0)
expect(this.application.items.itemsReferencingItem(item1).length).to.equal(0)
expect(this.application.items.itemsReferencingItem(item2).length).to.equal(1)
expect(application.items.itemsReferencingItem(item1).length).to.equal(0)
expect(application.items.itemsReferencingItem(item2).length).to.equal(1)
})
it('mapping an item twice shouldnt cause problems', async function () {
@@ -95,45 +84,45 @@ describe('app models', () => {
},
})
let items = await this.application.mutator.emitItemsFromPayloads([mutated], PayloadEmitSource.LocalChanged)
let items = await application.mutator.emitItemsFromPayloads([mutated], PayloadEmitSource.LocalChanged)
let item = items[0]
expect(item).to.be.ok
items = await this.application.mutator.emitItemsFromPayloads([mutated], PayloadEmitSource.LocalChanged)
items = await application.mutator.emitItemsFromPayloads([mutated], PayloadEmitSource.LocalChanged)
item = items[0]
expect(item.content.foo).to.equal('bar')
expect(this.application.items.getDisplayableNotes().length).to.equal(1)
expect(application.items.getDisplayableNotes().length).to.equal(1)
})
it('mapping item twice should preserve references', async function () {
const item1 = await Factory.createMappedNote(this.application)
const item2 = await Factory.createMappedNote(this.application)
const item1 = await Factory.createMappedNote(application)
const item2 = await Factory.createMappedNote(application)
await this.application.mutator.changeItem(item1, (mutator) => {
await application.mutator.changeItem(item1, (mutator) => {
mutator.e2ePendingRefactor_addItemAsRelationship(item2)
})
await this.application.mutator.changeItem(item2, (mutator) => {
await application.mutator.changeItem(item2, (mutator) => {
mutator.e2ePendingRefactor_addItemAsRelationship(item1)
})
const refreshedItem = this.application.items.findItem(item1.uuid)
const refreshedItem = application.items.findItem(item1.uuid)
expect(refreshedItem.content.references.length).to.equal(1)
})
it('fixes relationship integrity', async function () {
var item1 = await Factory.createMappedNote(this.application)
var item2 = await Factory.createMappedNote(this.application)
var item1 = await Factory.createMappedNote(application)
var item2 = await Factory.createMappedNote(application)
await this.application.mutator.changeItem(item1, (mutator) => {
await application.mutator.changeItem(item1, (mutator) => {
mutator.e2ePendingRefactor_addItemAsRelationship(item2)
})
await this.application.mutator.changeItem(item2, (mutator) => {
await application.mutator.changeItem(item2, (mutator) => {
mutator.e2ePendingRefactor_addItemAsRelationship(item1)
})
const refreshedItem1 = this.application.items.findItem(item1.uuid)
const refreshedItem2 = this.application.items.findItem(item2.uuid)
const refreshedItem1 = application.items.findItem(item1.uuid)
const refreshedItem2 = application.items.findItem(item2.uuid)
expect(refreshedItem1.content.references.length).to.equal(1)
expect(refreshedItem2.content.references.length).to.equal(1)
@@ -145,54 +134,54 @@ describe('app models', () => {
references: [],
},
})
await this.application.mutator.emitItemsFromPayloads([damagedPayload], PayloadEmitSource.LocalChanged)
await application.mutator.emitItemsFromPayloads([damagedPayload], PayloadEmitSource.LocalChanged)
const refreshedItem1_2 = this.application.items.findItem(item1.uuid)
const refreshedItem2_2 = this.application.items.findItem(item2.uuid)
const refreshedItem1_2 = application.items.findItem(item1.uuid)
const refreshedItem2_2 = application.items.findItem(item2.uuid)
expect(refreshedItem1_2.content.references.length).to.equal(0)
expect(refreshedItem2_2.content.references.length).to.equal(1)
})
it('creating and removing relationships between two items should have valid references', async function () {
var item1 = await Factory.createMappedNote(this.application)
var item2 = await Factory.createMappedNote(this.application)
await this.application.mutator.changeItem(item1, (mutator) => {
var item1 = await Factory.createMappedNote(application)
var item2 = await Factory.createMappedNote(application)
await application.mutator.changeItem(item1, (mutator) => {
mutator.e2ePendingRefactor_addItemAsRelationship(item2)
})
await this.application.mutator.changeItem(item2, (mutator) => {
await application.mutator.changeItem(item2, (mutator) => {
mutator.e2ePendingRefactor_addItemAsRelationship(item1)
})
const refreshedItem1 = this.application.items.findItem(item1.uuid)
const refreshedItem2 = this.application.items.findItem(item2.uuid)
const refreshedItem1 = application.items.findItem(item1.uuid)
const refreshedItem2 = application.items.findItem(item2.uuid)
expect(refreshedItem1.content.references.length).to.equal(1)
expect(refreshedItem2.content.references.length).to.equal(1)
expect(this.application.items.itemsReferencingItem(item1)).to.include(refreshedItem2)
expect(this.application.items.itemsReferencingItem(item2)).to.include(refreshedItem1)
expect(application.items.itemsReferencingItem(item1)).to.include(refreshedItem2)
expect(application.items.itemsReferencingItem(item2)).to.include(refreshedItem1)
await this.application.mutator.changeItem(item1, (mutator) => {
await application.mutator.changeItem(item1, (mutator) => {
mutator.removeItemAsRelationship(item2)
})
await this.application.mutator.changeItem(item2, (mutator) => {
await application.mutator.changeItem(item2, (mutator) => {
mutator.removeItemAsRelationship(item1)
})
const refreshedItem1_2 = this.application.items.findItem(item1.uuid)
const refreshedItem2_2 = this.application.items.findItem(item2.uuid)
const refreshedItem1_2 = application.items.findItem(item1.uuid)
const refreshedItem2_2 = application.items.findItem(item2.uuid)
expect(refreshedItem1_2.content.references.length).to.equal(0)
expect(refreshedItem2_2.content.references.length).to.equal(0)
expect(this.application.items.itemsReferencingItem(item1).length).to.equal(0)
expect(this.application.items.itemsReferencingItem(item2).length).to.equal(0)
expect(application.items.itemsReferencingItem(item1).length).to.equal(0)
expect(application.items.itemsReferencingItem(item2).length).to.equal(0)
})
it('properly duplicates item with no relationships', async function () {
const item = await Factory.createMappedNote(this.application)
const duplicate = await this.application.mutator.duplicateItem(item)
const item = await Factory.createMappedNote(application)
const duplicate = await application.mutator.duplicateItem(item)
expect(duplicate.uuid).to.not.equal(item.uuid)
expect(item.isItemContentEqualWith(duplicate)).to.equal(true)
expect(item.created_at.toISOString()).to.equal(duplicate.created_at.toISOString())
@@ -200,36 +189,36 @@ describe('app models', () => {
})
it('properly duplicates item with relationships', async function () {
const item1 = await Factory.createMappedNote(this.application)
const item2 = await Factory.createMappedNote(this.application)
const item1 = await Factory.createMappedNote(application)
const item2 = await Factory.createMappedNote(application)
const refreshedItem1 = await this.application.mutator.changeItem(item1, (mutator) => {
const refreshedItem1 = await application.mutator.changeItem(item1, (mutator) => {
mutator.e2ePendingRefactor_addItemAsRelationship(item2)
})
expect(refreshedItem1.content.references.length).to.equal(1)
const duplicate = await this.application.mutator.duplicateItem(item1)
const duplicate = await application.mutator.duplicateItem(item1)
expect(duplicate.uuid).to.not.equal(item1.uuid)
expect(duplicate.content.references.length).to.equal(1)
expect(this.application.items.itemsReferencingItem(item1).length).to.equal(0)
expect(this.application.items.itemsReferencingItem(item2).length).to.equal(2)
expect(application.items.itemsReferencingItem(item1).length).to.equal(0)
expect(application.items.itemsReferencingItem(item2).length).to.equal(2)
const refreshedItem1_2 = this.application.items.findItem(item1.uuid)
const refreshedItem1_2 = application.items.findItem(item1.uuid)
expect(refreshedItem1_2.isItemContentEqualWith(duplicate)).to.equal(true)
expect(refreshedItem1_2.created_at.toISOString()).to.equal(duplicate.created_at.toISOString())
expect(refreshedItem1_2.content_type).to.equal(duplicate.content_type)
})
it('removing references should update cross-refs', async function () {
const item1 = await Factory.createMappedNote(this.application)
const item2 = await Factory.createMappedNote(this.application)
const refreshedItem1 = await this.application.mutator.changeItem(item1, (mutator) => {
const item1 = await Factory.createMappedNote(application)
const item2 = await Factory.createMappedNote(application)
const refreshedItem1 = await application.mutator.changeItem(item1, (mutator) => {
mutator.e2ePendingRefactor_addItemAsRelationship(item2)
})
const refreshedItem1_2 = await this.application.mutator.emitItemFromPayload(
const refreshedItem1_2 = await application.mutator.emitItemFromPayload(
refreshedItem1.payloadRepresentation({
deleted: true,
content: {
@@ -240,49 +229,49 @@ describe('app models', () => {
PayloadEmitSource.LocalChanged,
)
expect(this.application.items.itemsReferencingItem(item2).length).to.equal(0)
expect(this.application.items.itemsReferencingItem(item1).length).to.equal(0)
expect(application.items.itemsReferencingItem(item2).length).to.equal(0)
expect(application.items.itemsReferencingItem(item1).length).to.equal(0)
expect(refreshedItem1_2.content.references.length).to.equal(0)
})
it('properly handles single item uuid alternation', async function () {
const item1 = await Factory.createMappedNote(this.application)
const item2 = await Factory.createMappedNote(this.application)
const item1 = await Factory.createMappedNote(application)
const item2 = await Factory.createMappedNote(application)
const refreshedItem1 = await this.application.mutator.changeItem(item1, (mutator) => {
const refreshedItem1 = await application.mutator.changeItem(item1, (mutator) => {
mutator.e2ePendingRefactor_addItemAsRelationship(item2)
})
expect(refreshedItem1.content.references.length).to.equal(1)
expect(this.application.items.itemsReferencingItem(item2).length).to.equal(1)
expect(application.items.itemsReferencingItem(item2).length).to.equal(1)
const alternatedItem = await Factory.alternateUuidForItem(this.application, item1.uuid)
const refreshedItem1_2 = this.application.items.findItem(item1.uuid)
const alternatedItem = await Factory.alternateUuidForItem(application, item1.uuid)
const refreshedItem1_2 = application.items.findItem(item1.uuid)
expect(refreshedItem1_2).to.not.be.ok
expect(this.application.items.getDisplayableNotes().length).to.equal(2)
expect(application.items.getDisplayableNotes().length).to.equal(2)
expect(alternatedItem.content.references.length).to.equal(1)
expect(this.application.items.itemsReferencingItem(alternatedItem.uuid).length).to.equal(0)
expect(application.items.itemsReferencingItem(alternatedItem.uuid).length).to.equal(0)
expect(this.application.items.itemsReferencingItem(item2).length).to.equal(1)
expect(application.items.itemsReferencingItem(item2).length).to.equal(1)
expect(alternatedItem.isReferencingItem(item2)).to.equal(true)
expect(alternatedItem.dirty).to.equal(true)
})
it('alterating uuid of item should fill its duplicateOf value', async function () {
const item1 = await Factory.createMappedNote(this.application)
const alternatedItem = await Factory.alternateUuidForItem(this.application, item1.uuid)
const item1 = await Factory.createMappedNote(application)
const alternatedItem = await Factory.alternateUuidForItem(application, item1.uuid)
expect(alternatedItem.duplicateOf).to.equal(item1.uuid)
})
it('alterating itemskey uuid should update errored items encrypted with that key', async function () {
const item1 = await Factory.createMappedNote(this.application)
const itemsKey = this.application.items.getDisplayableItemsKeys()[0]
const item1 = await Factory.createMappedNote(application)
const itemsKey = application.items.getDisplayableItemsKeys()[0]
/** Encrypt item1 and emit as errored so it persists with items_key_id */
const encrypted = await this.application.encryption.encryptSplitSingle({
const encrypted = await application.encryption.encryptSplitSingle({
usesItemsKeyWithKeyLookup: {
items: [item1.payload],
},
@@ -292,46 +281,46 @@ describe('app models', () => {
waitingForKey: true,
})
await this.application.payloads.emitPayload(errored)
await application.payloads.emitPayload(errored)
expect(this.application.payloads.findOne(item1.uuid).errorDecrypting).to.equal(true)
expect(this.application.payloads.findOne(item1.uuid).items_key_id).to.equal(itemsKey.uuid)
expect(application.payloads.findOne(item1.uuid).errorDecrypting).to.equal(true)
expect(application.payloads.findOne(item1.uuid).items_key_id).to.equal(itemsKey.uuid)
sinon.stub(this.application.encryption.itemsEncryption, 'decryptErroredItemPayloads').callsFake(() => {
sinon.stub(application.encryption.itemsEncryption, 'decryptErroredItemPayloads').callsFake(() => {
// prevent auto decryption
})
const alternatedKey = await Factory.alternateUuidForItem(this.application, itemsKey.uuid)
const updatedPayload = this.application.payloads.findOne(item1.uuid)
const alternatedKey = await Factory.alternateUuidForItem(application, itemsKey.uuid)
const updatedPayload = application.payloads.findOne(item1.uuid)
expect(updatedPayload.items_key_id).to.equal(alternatedKey.uuid)
})
it('properly handles mutli item uuid alternation', async function () {
const item1 = await Factory.createMappedNote(this.application)
const item2 = await Factory.createMappedNote(this.application)
this.expectedItemCount += 2
const item1 = await Factory.createMappedNote(application)
const item2 = await Factory.createMappedNote(application)
expectedItemCount += 2
await this.application.mutator.changeItem(item1, (mutator) => {
await application.mutator.changeItem(item1, (mutator) => {
mutator.e2ePendingRefactor_addItemAsRelationship(item2)
})
expect(this.application.items.itemsReferencingItem(item2).length).to.equal(1)
expect(application.items.itemsReferencingItem(item2).length).to.equal(1)
const alternatedItem1 = await Factory.alternateUuidForItem(this.application, item1.uuid)
const alternatedItem2 = await Factory.alternateUuidForItem(this.application, item2.uuid)
const alternatedItem1 = await Factory.alternateUuidForItem(application, item1.uuid)
const alternatedItem2 = await Factory.alternateUuidForItem(application, item2.uuid)
expect(this.application.items.items.length).to.equal(this.expectedItemCount)
expect(application.items.items.length).to.equal(expectedItemCount)
expect(item1.uuid).to.not.equal(alternatedItem1.uuid)
expect(item2.uuid).to.not.equal(alternatedItem2.uuid)
const refreshedAltItem1 = this.application.items.findItem(alternatedItem1.uuid)
const refreshedAltItem1 = application.items.findItem(alternatedItem1.uuid)
expect(refreshedAltItem1.content.references.length).to.equal(1)
expect(refreshedAltItem1.content.references[0].uuid).to.equal(alternatedItem2.uuid)
expect(alternatedItem2.content.references.length).to.equal(0)
expect(this.application.items.itemsReferencingItem(alternatedItem2).length).to.equal(1)
expect(application.items.itemsReferencingItem(alternatedItem2).length).to.equal(1)
expect(refreshedAltItem1.isReferencingItem(alternatedItem2)).to.equal(true)
expect(alternatedItem2.isReferencingItem(refreshedAltItem1)).to.equal(false)
@@ -339,39 +328,39 @@ describe('app models', () => {
})
it('maintains referencing relationships when duplicating', async function () {
const tag = await Factory.createMappedTag(this.application)
const note = await Factory.createMappedNote(this.application)
const refreshedTag = await this.application.mutator.changeItem(tag, (mutator) => {
const tag = await Factory.createMappedTag(application)
const note = await Factory.createMappedNote(application)
const refreshedTag = await application.mutator.changeItem(tag, (mutator) => {
mutator.e2ePendingRefactor_addItemAsRelationship(note)
})
expect(refreshedTag.content.references.length).to.equal(1)
const noteCopy = await this.application.mutator.duplicateItem(note)
const noteCopy = await application.mutator.duplicateItem(note)
expect(note.uuid).to.not.equal(noteCopy.uuid)
expect(this.application.items.getDisplayableNotes().length).to.equal(2)
expect(this.application.items.getDisplayableTags().length).to.equal(1)
expect(application.items.getDisplayableNotes().length).to.equal(2)
expect(application.items.getDisplayableTags().length).to.equal(1)
expect(note.content.references.length).to.equal(0)
expect(noteCopy.content.references.length).to.equal(0)
const refreshedTag_2 = this.application.items.findItem(tag.uuid)
const refreshedTag_2 = application.items.findItem(tag.uuid)
expect(refreshedTag_2.content.references.length).to.equal(2)
})
it('maintains editor reference when duplicating note', async function () {
const component = await this.application.mutator.createItem(
const component = await application.mutator.createItem(
ContentType.TYPES.Component,
{ area: ComponentArea.Editor, package_info: { identifier: 'foo-editor' } },
true,
)
const note = await Factory.insertItemWithOverride(this.application, ContentType.TYPES.Note, {
const note = await Factory.insertItemWithOverride(application, ContentType.TYPES.Note, {
editorIdentifier: 'foo-editor',
})
expect(this.application.componentManager.editorForNote(note).uniqueIdentifier.value).to.equal(component.uuid)
expect(application.componentManager.editorForNote(note).uniqueIdentifier.value).to.equal(component.uuid)
const duplicate = await this.application.mutator.duplicateItem(note, true)
expect(this.application.componentManager.editorForNote(duplicate).uniqueIdentifier.value).to.equal(component.uuid)
const duplicate = await application.mutator.duplicateItem(note, true)
expect(application.componentManager.editorForNote(duplicate).uniqueIdentifier.value).to.equal(component.uuid)
})
})

File diff suppressed because it is too large Load Diff

View File

@@ -1,7 +1,6 @@
/* eslint-disable no-unused-expressions */
/* eslint-disable no-undef */
import { BaseItemCounts } from '../lib/BaseItemCounts.js'
import * as Factory from '../lib/factory.js'
chai.use(chaiAsPromised)
const expect = chai.expect
@@ -11,47 +10,52 @@ describe('items', () => {
awaitAll: true,
}
let application
let expectedItemCount
beforeEach(async function () {
this.expectedItemCount = BaseItemCounts.DefaultItems
this.application = await Factory.createInitAppWithFakeCrypto()
localStorage.clear()
expectedItemCount = BaseItemCounts.DefaultItems
application = await Factory.createInitAppWithFakeCrypto()
})
afterEach(async function () {
await Factory.safeDeinit(this.application)
await Factory.safeDeinit(application)
localStorage.clear()
})
it('setting an item as dirty should update its client updated at', async function () {
const params = Factory.createNotePayload()
await this.application.mutator.emitItemsFromPayloads([params], PayloadEmitSource.LocalChanged)
const item = this.application.items.items[0]
await application.mutator.emitItemsFromPayloads([params], PayloadEmitSource.LocalChanged)
const item = application.items.items[0]
const prevDate = item.userModifiedDate.getTime()
await Factory.sleep(0.1)
await this.application.mutator.setItemDirty(item, true)
const refreshedItem = this.application.items.findItem(item.uuid)
await application.mutator.setItemDirty(item, true)
const refreshedItem = application.items.findItem(item.uuid)
const newDate = refreshedItem.userModifiedDate.getTime()
expect(prevDate).to.not.equal(newDate)
})
it('setting an item as dirty with option to skip client updated at', async function () {
const params = Factory.createNotePayload()
await this.application.mutator.emitItemsFromPayloads([params], PayloadEmitSource.LocalChanged)
const item = this.application.items.items[0]
await application.mutator.emitItemsFromPayloads([params], PayloadEmitSource.LocalChanged)
const item = application.items.items[0]
const prevDate = item.userModifiedDate.getTime()
await Factory.sleep(0.1)
await this.application.mutator.setItemDirty(item)
await application.mutator.setItemDirty(item)
const newDate = item.userModifiedDate.getTime()
expect(prevDate).to.equal(newDate)
})
it('properly pins, archives, and locks', async function () {
const params = Factory.createNotePayload()
await this.application.mutator.emitItemsFromPayloads([params], PayloadEmitSource.LocalChanged)
await application.mutator.emitItemsFromPayloads([params], PayloadEmitSource.LocalChanged)
const item = this.application.items.items[0]
const item = application.items.items[0]
expect(item.pinned).to.not.be.ok
const refreshedItem = (
await this.application.changeAndSaveItem.execute(
await application.changeAndSaveItem.execute(
item,
(mutator) => {
mutator.pinned = true
@@ -71,16 +75,16 @@ describe('items', () => {
it('properly compares item equality', async function () {
const params1 = Factory.createNotePayload()
const params2 = Factory.createNotePayload()
await this.application.mutator.emitItemsFromPayloads([params1, params2], PayloadEmitSource.LocalChanged)
await application.mutator.emitItemsFromPayloads([params1, params2], PayloadEmitSource.LocalChanged)
let item1 = this.application.items.getDisplayableNotes()[0]
let item2 = this.application.items.getDisplayableNotes()[1]
let item1 = application.items.getDisplayableNotes()[0]
let item2 = application.items.getDisplayableNotes()[1]
expect(item1.isItemContentEqualWith(item2)).to.equal(true)
// items should ignore this field when checking for equality
item1 = (
await this.application.changeAndSaveItem.execute(
await application.changeAndSaveItem.execute(
item1,
(mutator) => {
mutator.userModifiedDate = new Date()
@@ -91,7 +95,7 @@ describe('items', () => {
)
).getValue()
item2 = (
await this.application.changeAndSaveItem.execute(
await application.changeAndSaveItem.execute(
item2,
(mutator) => {
mutator.userModifiedDate = undefined
@@ -105,7 +109,7 @@ describe('items', () => {
expect(item1.isItemContentEqualWith(item2)).to.equal(true)
item1 = (
await this.application.changeAndSaveItem.execute(
await application.changeAndSaveItem.execute(
item1,
(mutator) => {
mutator.mutableContent.foo = 'bar'
@@ -119,7 +123,7 @@ describe('items', () => {
expect(item1.isItemContentEqualWith(item2)).to.equal(false)
item2 = (
await this.application.changeAndSaveItem.execute(
await application.changeAndSaveItem.execute(
item2,
(mutator) => {
mutator.mutableContent.foo = 'bar'
@@ -134,7 +138,7 @@ describe('items', () => {
expect(item2.isItemContentEqualWith(item1)).to.equal(true)
item1 = (
await this.application.changeAndSaveItem.execute(
await application.changeAndSaveItem.execute(
item1,
(mutator) => {
mutator.e2ePendingRefactor_addItemAsRelationship(item2)
@@ -145,7 +149,7 @@ describe('items', () => {
)
).getValue()
item2 = (
await this.application.changeAndSaveItem.execute(
await application.changeAndSaveItem.execute(
item2,
(mutator) => {
mutator.e2ePendingRefactor_addItemAsRelationship(item1)
@@ -162,7 +166,7 @@ describe('items', () => {
expect(item1.isItemContentEqualWith(item2)).to.equal(false)
item1 = (
await this.application.changeAndSaveItem.execute(
await application.changeAndSaveItem.execute(
item1,
(mutator) => {
mutator.removeItemAsRelationship(item2)
@@ -173,7 +177,7 @@ describe('items', () => {
)
).getValue()
item2 = (
await this.application.changeAndSaveItem.execute(
await application.changeAndSaveItem.execute(
item2,
(mutator) => {
mutator.removeItemAsRelationship(item1)
@@ -192,13 +196,13 @@ describe('items', () => {
it('content equality should not have side effects', async function () {
const params1 = Factory.createNotePayload()
const params2 = Factory.createNotePayload()
await this.application.mutator.emitItemsFromPayloads([params1, params2], PayloadEmitSource.LocalChanged)
await application.mutator.emitItemsFromPayloads([params1, params2], PayloadEmitSource.LocalChanged)
let item1 = this.application.items.getDisplayableNotes()[0]
const item2 = this.application.items.getDisplayableNotes()[1]
let item1 = application.items.getDisplayableNotes()[0]
const item2 = application.items.getDisplayableNotes()[1]
item1 = (
await this.application.changeAndSaveItem.execute(
await application.changeAndSaveItem.execute(
item1,
(mutator) => {
mutator.mutableContent.foo = 'bar'
@@ -223,7 +227,7 @@ describe('items', () => {
// There was an issue where calling that function would modify values directly to omit keys
// in contentKeysToIgnoreWhenCheckingEquality.
await this.application.mutator.setItemsDirty([item1, item2])
await application.mutator.setItemsDirty([item1, item2])
expect(item1.userModifiedDate).to.be.ok
expect(item2.userModifiedDate).to.be.ok

View File

@@ -1,28 +1,35 @@
/* eslint-disable no-unused-expressions */
/* eslint-disable no-undef */
import { BaseItemCounts } from '../lib/BaseItemCounts.js'
import * as Factory from '../lib/factory.js'
import { createNoteParams } from '../lib/Items.js'
chai.use(chaiAsPromised)
const expect = chai.expect
describe('model manager mapping', () => {
let application
let expectedItemCount
let context
beforeEach(async function () {
this.expectedItemCount = BaseItemCounts.DefaultItems
this.context = await Factory.createAppContext()
await this.context.launch()
this.application = this.context.application
localStorage.clear()
expectedItemCount = BaseItemCounts.DefaultItems
context = await Factory.createAppContext()
await context.launch()
application = context.application
})
afterEach(async function () {
await Factory.safeDeinit(this.application)
await Factory.safeDeinit(application)
application = undefined
context = undefined
localStorage.clear()
})
it('mapping nonexistent item creates it', async function () {
const payload = Factory.createNotePayload()
await this.application.mutator.emitItemsFromPayloads([payload], PayloadEmitSource.LocalChanged)
this.expectedItemCount++
expect(this.application.items.items.length).to.equal(this.expectedItemCount)
await application.mutator.emitItemsFromPayloads([payload], PayloadEmitSource.LocalChanged)
expectedItemCount++
expect(application.items.items.length).to.equal(expectedItemCount)
})
it('mapping nonexistent deleted item doesnt create it', async function () {
@@ -31,17 +38,17 @@ describe('model manager mapping', () => {
dirty: false,
deleted: true,
})
await this.application.payloads.emitPayload(payload, PayloadEmitSource.LocalChanged)
expect(this.application.items.items.length).to.equal(this.expectedItemCount)
await application.payloads.emitPayload(payload, PayloadEmitSource.LocalChanged)
expect(application.items.items.length).to.equal(expectedItemCount)
})
it('mapping and deleting nonexistent item creates and deletes it', async function () {
const payload = Factory.createNotePayload()
await this.application.mutator.emitItemsFromPayloads([payload], PayloadEmitSource.LocalChanged)
await application.mutator.emitItemsFromPayloads([payload], PayloadEmitSource.LocalChanged)
this.expectedItemCount++
expectedItemCount++
expect(this.application.items.items.length).to.equal(this.expectedItemCount)
expect(application.items.items.length).to.equal(expectedItemCount)
const changedParams = new DeletedPayload({
...payload,
@@ -49,32 +56,32 @@ describe('model manager mapping', () => {
deleted: true,
})
this.expectedItemCount--
expectedItemCount--
await this.application.mutator.emitItemsFromPayloads([changedParams], PayloadEmitSource.LocalChanged)
await application.mutator.emitItemsFromPayloads([changedParams], PayloadEmitSource.LocalChanged)
expect(this.application.items.items.length).to.equal(this.expectedItemCount)
expect(application.items.items.length).to.equal(expectedItemCount)
})
it('mapping deleted but dirty item should not delete it', async function () {
const payload = Factory.createNotePayload()
const [item] = await this.application.mutator.emitItemsFromPayloads([payload], PayloadEmitSource.LocalChanged)
const [item] = await application.mutator.emitItemsFromPayloads([payload], PayloadEmitSource.LocalChanged)
this.expectedItemCount++
expectedItemCount++
await this.application.payloads.emitPayload(new DeleteItemMutator(item).getDeletedResult())
await application.payloads.emitPayload(new DeleteItemMutator(item).getDeletedResult())
const payload2 = new DeletedPayload(this.application.payloads.findOne(payload.uuid).ejected())
const payload2 = new DeletedPayload(application.payloads.findOne(payload.uuid).ejected())
await this.application.payloads.emitPayloads([payload2], PayloadEmitSource.LocalChanged)
await application.payloads.emitPayloads([payload2], PayloadEmitSource.LocalChanged)
expect(this.application.payloads.collection.all().length).to.equal(this.expectedItemCount)
expect(application.payloads.collection.all().length).to.equal(expectedItemCount)
})
it('mapping existing item updates its properties', async function () {
const payload = Factory.createNotePayload()
await this.application.mutator.emitItemsFromPayloads([payload], PayloadEmitSource.LocalChanged)
await application.mutator.emitItemsFromPayloads([payload], PayloadEmitSource.LocalChanged)
const newTitle = 'updated title'
const mutated = new DecryptedPayload({
@@ -84,45 +91,45 @@ describe('model manager mapping', () => {
title: newTitle,
},
})
await this.application.mutator.emitItemsFromPayloads([mutated], PayloadEmitSource.LocalChanged)
const item = this.application.items.getDisplayableNotes()[0]
await application.mutator.emitItemsFromPayloads([mutated], PayloadEmitSource.LocalChanged)
const item = application.items.getDisplayableNotes()[0]
expect(item.content.title).to.equal(newTitle)
})
it('setting an item dirty should retrieve it in dirty items', async function () {
const payload = Factory.createNotePayload()
await this.application.mutator.emitItemsFromPayloads([payload], PayloadEmitSource.LocalChanged)
const note = this.application.items.getDisplayableNotes()[0]
await this.application.mutator.setItemDirty(note)
const dirtyItems = this.application.items.getDirtyItems()
await application.mutator.emitItemsFromPayloads([payload], PayloadEmitSource.LocalChanged)
const note = application.items.getDisplayableNotes()[0]
await application.mutator.setItemDirty(note)
const dirtyItems = application.items.getDirtyItems()
expect(Uuids(dirtyItems).includes(note.uuid))
})
it('set all items dirty', async function () {
const count = 10
this.expectedItemCount += count
expectedItemCount += count
const payloads = []
for (let i = 0; i < count; i++) {
payloads.push(Factory.createNotePayload())
}
await this.application.mutator.emitItemsFromPayloads(payloads, PayloadEmitSource.LocalChanged)
await this.application.sync.markAllItemsAsNeedingSyncAndPersist()
await application.mutator.emitItemsFromPayloads(payloads, PayloadEmitSource.LocalChanged)
await application.sync.markAllItemsAsNeedingSyncAndPersist()
const dirtyItems = this.application.items.getDirtyItems()
expect(dirtyItems.length).to.equal(this.expectedItemCount)
const dirtyItems = application.items.getDirtyItems()
expect(dirtyItems.length).to.equal(expectedItemCount)
})
it('sync observers should be notified of changes', async function () {
const payload = Factory.createNotePayload()
await this.application.mutator.emitItemsFromPayloads([payload], PayloadEmitSource.LocalChanged)
const item = this.application.items.items[0]
await application.mutator.emitItemsFromPayloads([payload], PayloadEmitSource.LocalChanged)
const item = application.items.items[0]
return new Promise((resolve) => {
this.application.items.addObserver(ContentType.TYPES.Any, ({ changed }) => {
application.items.addObserver(ContentType.TYPES.Any, ({ changed }) => {
expect(changed[0].uuid === item.uuid)
resolve()
})
this.application.mutator.emitItemsFromPayloads([payload], PayloadEmitSource.LocalChanged)
application.mutator.emitItemsFromPayloads([payload], PayloadEmitSource.LocalChanged)
})
})
})

View File

@@ -1,5 +1,3 @@
/* eslint-disable no-unused-expressions */
/* eslint-disable no-undef */
import * as Factory from '../lib/factory.js'
chai.use(chaiAsPromised)
@@ -26,48 +24,53 @@ const titles = (items) => {
}
describe('notes and smart views', () => {
let application
beforeEach(async function () {
this.application = await Factory.createInitAppWithFakeCrypto()
localStorage.clear()
application = await Factory.createInitAppWithFakeCrypto()
})
afterEach(async function () {
await Factory.safeDeinit(this.application)
await Factory.safeDeinit(application)
localStorage.clear()
application = undefined
})
it('lets me create a smart view and use it', async function () {
// ## The user creates 3 notes
const [note_1, note_2, note_3] = await Promise.all([
Factory.createMappedNote(this.application, 'long & pinned', generateLongString()),
Factory.createMappedNote(this.application, 'long & !pinned', generateLongString()),
Factory.createMappedNote(this.application, 'pinned', 'this is a pinned note'),
Factory.createMappedNote(application, 'long & pinned', generateLongString()),
Factory.createMappedNote(application, 'long & !pinned', generateLongString()),
Factory.createMappedNote(application, 'pinned', 'this is a pinned note'),
])
// The user pin 2 notes
await Promise.all([Factory.pinNote(this.application, note_1), Factory.pinNote(this.application, note_3)])
await Promise.all([Factory.pinNote(application, note_1), Factory.pinNote(application, note_3)])
// ## The user creates smart views (long & pinned)
const not_pinned = '!["Not Pinned", "pinned", "=", false]'
const long = '!["Long", "text.length", ">", 500]'
const tag_not_pinned = await this.application.mutator.createTagOrSmartView(not_pinned)
const tag_long = await this.application.mutator.createTagOrSmartView(long)
const tag_not_pinned = await application.mutator.createTagOrSmartView(not_pinned)
const tag_long = await application.mutator.createTagOrSmartView(long)
// ## The user can filter and see the pinned notes
const notes_not_pinned = getFilteredNotes(this.application, {
const notes_not_pinned = getFilteredNotes(application, {
views: [tag_not_pinned],
})
expect(titles(notes_not_pinned)).to.eql(['long & !pinned'])
// ## The user can filter and see the long notes
const notes_long = getFilteredNotes(this.application, { views: [tag_long] })
const notes_long = getFilteredNotes(application, { views: [tag_long] })
expect(titles(notes_long)).to.eql(['long & !pinned', 'long & pinned'])
// ## The user creates a new long note
await Factory.createMappedNote(this.application, 'new long', generateLongString())
await Factory.createMappedNote(application, 'new long', generateLongString())
// ## The user can filter and see the new long note
const notes_long2 = getFilteredNotes(this.application, {
const notes_long2 = getFilteredNotes(application, {
views: [tag_long],
})
expect(titles(notes_long2)).to.eql(['long & !pinned', 'long & pinned', 'new long'])

View File

@@ -1,39 +1,44 @@
/* eslint-disable no-undef */
import * as Factory from '../lib/factory.js'
import * as Utils from '../lib/Utils.js'
import { createRelatedNoteTagPairPayload } from '../lib/Items.js'
import { BaseItemCounts } from '../lib/BaseItemCounts.js'
chai.use(chaiAsPromised)
const expect = chai.expect
describe('notes and tags', () => {
let application
let context
const syncOptions = {
checkIntegrity: true,
awaitAll: true,
}
beforeEach(async function () {
this.expectedItemCount = BaseItemCounts.DefaultItems
this.context = await Factory.createAppContext()
await this.context.launch()
this.application = this.context.application
localStorage.clear()
context = await Factory.createAppContext()
await context.launch()
application = context.application
})
afterEach(async function () {
await Factory.safeDeinit(this.application)
await Factory.safeDeinit(application)
localStorage.clear()
application = undefined
context = undefined
})
it('uses proper class for note', async function () {
const payload = Factory.createNotePayload()
await this.application.mutator.emitItemFromPayload(payload, PayloadEmitSource.LocalChanged)
const note = this.application.items.getItems([ContentType.TYPES.Note])[0]
await application.mutator.emitItemFromPayload(payload, PayloadEmitSource.LocalChanged)
const note = application.items.getItems([ContentType.TYPES.Note])[0]
expect(note.constructor === SNNote).to.equal(true)
})
it('properly constructs syncing params', async function () {
const title = 'Foo'
const text = 'Bar'
const note = await this.application.items.createTemplateItem(ContentType.TYPES.Note, {
const note = await application.items.createTemplateItem(ContentType.TYPES.Note, {
title,
text,
})
@@ -41,7 +46,7 @@ describe('notes and tags', () => {
expect(note.content.title).to.equal(title)
expect(note.content.text).to.equal(text)
const tag = await this.application.items.createTemplateItem(ContentType.TYPES.Tag, {
const tag = await application.items.createTemplateItem(ContentType.TYPES.Tag, {
title,
})
@@ -73,12 +78,12 @@ describe('notes and tags', () => {
},
})
await this.application.mutator.emitItemsFromPayloads([mutatedNote, mutatedTag], PayloadEmitSource.LocalChanged)
const note = this.application.items.getItems([ContentType.TYPES.Note])[0]
const tag = this.application.items.getItems([ContentType.TYPES.Tag])[0]
await application.mutator.emitItemsFromPayloads([mutatedNote, mutatedTag], PayloadEmitSource.LocalChanged)
const note = application.items.getItems([ContentType.TYPES.Note])[0]
const tag = application.items.getItems([ContentType.TYPES.Tag])[0]
expect(note.content.references.length).to.equal(1)
expect(this.application.items.itemsReferencingItem(tag).length).to.equal(1)
expect(application.items.itemsReferencingItem(tag).length).to.equal(1)
})
it('creates relationship between note and tag', async function () {
@@ -89,9 +94,9 @@ describe('notes and tags', () => {
expect(notePayload.content.references.length).to.equal(0)
expect(tagPayload.content.references.length).to.equal(1)
await this.application.mutator.emitItemsFromPayloads([notePayload, tagPayload], PayloadEmitSource.LocalChanged)
let note = this.application.items.getDisplayableNotes()[0]
let tag = this.application.items.getDisplayableTags()[0]
await application.mutator.emitItemsFromPayloads([notePayload, tagPayload], PayloadEmitSource.LocalChanged)
let note = application.items.getDisplayableNotes()[0]
let tag = application.items.getDisplayableTags()[0]
expect(note.dirty).to.not.be.ok
expect(tag.dirty).to.not.be.ok
@@ -102,26 +107,26 @@ describe('notes and tags', () => {
expect(note.isReferencingItem(tag)).to.equal(false)
expect(tag.isReferencingItem(note)).to.equal(true)
expect(this.application.items.itemsReferencingItem(note).length).to.equal(1)
expect(application.items.itemsReferencingItem(note).length).to.equal(1)
expect(note.payload.references.length).to.equal(0)
expect(tag.noteCount).to.equal(1)
await this.application.mutator.setItemToBeDeleted(note)
await application.mutator.setItemToBeDeleted(note)
tag = this.application.items.getDisplayableTags()[0]
tag = application.items.getDisplayableTags()[0]
const deletedNotePayload = this.application.payloads.findOne(note.uuid)
const deletedNotePayload = application.payloads.findOne(note.uuid)
expect(deletedNotePayload.dirty).to.be.true
expect(tag.dirty).to.be.true
await this.application.sync.sync(syncOptions)
await application.sync.sync(syncOptions)
expect(tag.content.references.length).to.equal(0)
expect(this.application.items.itemsReferencingItem(note).length).to.equal(0)
expect(application.items.itemsReferencingItem(note).length).to.equal(0)
expect(tag.noteCount).to.equal(0)
tag = this.application.items.getDisplayableTags()[0]
expect(this.application.items.getDisplayableNotes().length).to.equal(0)
tag = application.items.getDisplayableTags()[0]
expect(application.items.getDisplayableNotes().length).to.equal(0)
expect(tag.dirty).to.be.false
})
@@ -130,14 +135,14 @@ describe('notes and tags', () => {
const notePayload = pair[0]
const tagPayload = pair[1]
await this.application.mutator.emitItemsFromPayloads(pair, PayloadEmitSource.LocalChanged)
let note = this.application.items.getItems([ContentType.TYPES.Note])[0]
let tag = this.application.items.getItems([ContentType.TYPES.Tag])[0]
await application.mutator.emitItemsFromPayloads(pair, PayloadEmitSource.LocalChanged)
let note = application.items.getItems([ContentType.TYPES.Note])[0]
let tag = application.items.getItems([ContentType.TYPES.Tag])[0]
expect(note.content.references.length).to.equal(0)
expect(tag.content.references.length).to.equal(1)
await this.application.sync.sync(syncOptions)
await application.sync.sync(syncOptions)
const mutatedTag = new DecryptedPayload({
...tagPayload,
@@ -147,13 +152,13 @@ describe('notes and tags', () => {
references: [],
},
})
await this.application.mutator.emitItemsFromPayloads([mutatedTag], PayloadEmitSource.LocalChanged)
await application.mutator.emitItemsFromPayloads([mutatedTag], PayloadEmitSource.LocalChanged)
note = this.application.items.findItem(note.uuid)
tag = this.application.items.findItem(tag.uuid)
note = application.items.findItem(note.uuid)
tag = application.items.findItem(tag.uuid)
expect(tag.content.references.length).to.equal(0)
expect(this.application.items.itemsReferencingItem(note).length).to.equal(0)
expect(application.items.itemsReferencingItem(note).length).to.equal(0)
expect(tag.noteCount).to.equal(0)
// expect to be false
@@ -162,13 +167,13 @@ describe('notes and tags', () => {
})
it('creating basic note should have text set', async function () {
const note = await Factory.createMappedNote(this.application)
const note = await Factory.createMappedNote(application)
expect(note.title).to.be.ok
expect(note.text).to.be.ok
})
it('creating basic tag should have title', async function () {
const tag = await Factory.createMappedTag(this.application)
const tag = await Factory.createMappedTag(application)
expect(tag.title).to.be.ok
})
@@ -177,15 +182,15 @@ describe('notes and tags', () => {
const notePayload = pair[0]
const tagPayload = pair[1]
await this.application.mutator.emitItemsFromPayloads([notePayload, tagPayload], PayloadEmitSource.LocalChanged)
const note = this.application.items.getItems([ContentType.TYPES.Note])[0]
let tag = this.application.items.getItems([ContentType.TYPES.Tag])[0]
await application.mutator.emitItemsFromPayloads([notePayload, tagPayload], PayloadEmitSource.LocalChanged)
const note = application.items.getItems([ContentType.TYPES.Note])[0]
let tag = application.items.getItems([ContentType.TYPES.Tag])[0]
expect(note.content.references.length).to.equal(0)
expect(tag.content.references.length).to.equal(1)
tag = (
await this.application.changeAndSaveItem.execute(
await application.changeAndSaveItem.execute(
tag,
(mutator) => {
mutator.removeItemAsRelationship(note)
@@ -196,21 +201,21 @@ describe('notes and tags', () => {
)
).getValue()
expect(this.application.items.itemsReferencingItem(note).length).to.equal(0)
expect(application.items.itemsReferencingItem(note).length).to.equal(0)
expect(tag.noteCount).to.equal(0)
})
it('properly handles tag duplication', async function () {
const pair = createRelatedNoteTagPairPayload()
await this.application.mutator.emitItemsFromPayloads(pair, PayloadEmitSource.LocalChanged)
let note = this.application.items.getDisplayableNotes()[0]
let tag = this.application.items.getDisplayableTags()[0]
await application.mutator.emitItemsFromPayloads(pair, PayloadEmitSource.LocalChanged)
let note = application.items.getDisplayableNotes()[0]
let tag = application.items.getDisplayableTags()[0]
const duplicateTag = await this.application.mutator.duplicateItem(tag, true)
await this.application.sync.sync(syncOptions)
const duplicateTag = await application.mutator.duplicateItem(tag, true)
await application.sync.sync(syncOptions)
note = this.application.items.findItem(note.uuid)
tag = this.application.items.findItem(tag.uuid)
note = application.items.findItem(note.uuid)
tag = application.items.findItem(tag.uuid)
expect(tag.uuid).to.not.equal(duplicateTag.uuid)
expect(tag.content.references.length).to.equal(1)
@@ -218,7 +223,7 @@ describe('notes and tags', () => {
expect(duplicateTag.content.references.length).to.equal(1)
expect(duplicateTag.noteCount).to.equal(1)
const noteTags = this.application.items.itemsReferencingItem(note)
const noteTags = application.items.itemsReferencingItem(note)
expect(noteTags.length).to.equal(2)
const noteTag1 = noteTags[0]
@@ -234,13 +239,13 @@ describe('notes and tags', () => {
const pair = createRelatedNoteTagPairPayload()
const notePayload = pair[0]
const tagPayload = pair[1]
await this.application.mutator.emitItemsFromPayloads([notePayload, tagPayload], PayloadEmitSource.LocalChanged)
const note = this.application.items.getItems([ContentType.TYPES.Note])[0]
const duplicateNote = await this.application.mutator.duplicateItem(note, true)
await application.mutator.emitItemsFromPayloads([notePayload, tagPayload], PayloadEmitSource.LocalChanged)
const note = application.items.getItems([ContentType.TYPES.Note])[0]
const duplicateNote = await application.mutator.duplicateItem(note, true)
expect(note.uuid).to.not.equal(duplicateNote.uuid)
expect(this.application.items.itemsReferencingItem(duplicateNote).length).to.equal(
this.application.items.itemsReferencingItem(note).length,
expect(application.items.itemsReferencingItem(duplicateNote).length).to.equal(
application.items.itemsReferencingItem(note).length,
)
})
@@ -248,27 +253,27 @@ describe('notes and tags', () => {
const pair = createRelatedNoteTagPairPayload()
const notePayload = pair[0]
const tagPayload = pair[1]
await this.application.mutator.emitItemsFromPayloads([notePayload, tagPayload], PayloadEmitSource.LocalChanged)
const note = this.application.items.getItems([ContentType.TYPES.Note])[0]
let tag = this.application.items.getItems([ContentType.TYPES.Tag])[0]
await application.mutator.emitItemsFromPayloads([notePayload, tagPayload], PayloadEmitSource.LocalChanged)
const note = application.items.getItems([ContentType.TYPES.Note])[0]
let tag = application.items.getItems([ContentType.TYPES.Tag])[0]
expect(tag.content.references.length).to.equal(1)
expect(tag.noteCount).to.equal(1)
expect(note.content.references.length).to.equal(0)
expect(this.application.items.itemsReferencingItem(note).length).to.equal(1)
expect(application.items.itemsReferencingItem(note).length).to.equal(1)
await this.application.mutator.setItemToBeDeleted(tag)
tag = this.application.items.findItem(tag.uuid)
await application.mutator.setItemToBeDeleted(tag)
tag = application.items.findItem(tag.uuid)
expect(tag).to.not.be.ok
})
it('modifying item content should not modify payload content', async function () {
const notePayload = Factory.createNotePayload()
await this.application.mutator.emitItemsFromPayloads([notePayload], PayloadEmitSource.LocalChanged)
let note = this.application.items.getItems([ContentType.TYPES.Note])[0]
await application.mutator.emitItemsFromPayloads([notePayload], PayloadEmitSource.LocalChanged)
let note = application.items.getItems([ContentType.TYPES.Note])[0]
note = (
await this.application.changeAndSaveItem.execute(
await application.changeAndSaveItem.execute(
note,
(mutator) => {
mutator.mutableContent.title = Math.random()
@@ -289,15 +294,15 @@ describe('notes and tags', () => {
const notePayload = pair[0]
const tagPayload = pair[1]
await this.application.mutator.emitItemsFromPayloads([notePayload, tagPayload], PayloadEmitSource.LocalChanged)
let note = this.application.items.getItems([ContentType.TYPES.Note])[0]
let tag = this.application.items.getItems([ContentType.TYPES.Tag])[0]
await application.mutator.emitItemsFromPayloads([notePayload, tagPayload], PayloadEmitSource.LocalChanged)
let note = application.items.getItems([ContentType.TYPES.Note])[0]
let tag = application.items.getItems([ContentType.TYPES.Tag])[0]
await this.application.sync.sync(syncOptions)
await this.application.mutator.setItemToBeDeleted(tag)
await application.sync.sync(syncOptions)
await application.mutator.setItemToBeDeleted(tag)
note = this.application.items.findItem(note.uuid)
this.application.items.findItem(tag.uuid)
note = application.items.findItem(note.uuid)
application.items.findItem(tag.uuid)
expect(note.dirty).to.not.be.ok
})
@@ -305,26 +310,26 @@ describe('notes and tags', () => {
it('should sort notes', async function () {
await Promise.all(
['Y', 'Z', 'A', 'B'].map(async (title) => {
return this.application.mutator.insertItem(
await this.application.items.createTemplateItem(ContentType.TYPES.Note, { title }),
return application.mutator.insertItem(
await application.items.createTemplateItem(ContentType.TYPES.Note, { title }),
)
}),
)
this.application.items.setPrimaryItemDisplayOptions({
application.items.setPrimaryItemDisplayOptions({
sortBy: 'title',
sortDirection: 'dsc',
})
const titles = this.application.items.getDisplayableNotes().map((note) => note.title)
const titles = application.items.getDisplayableNotes().map((note) => note.title)
/** setPrimaryItemDisplayOptions inverses sort for title */
expect(titles).to.deep.equal(['A', 'B', 'Y', 'Z'])
})
it('setting a note dirty should collapse its properties into content', async function () {
let note = await this.application.items.createTemplateItem(ContentType.TYPES.Note, {
let note = await application.items.createTemplateItem(ContentType.TYPES.Note, {
title: 'Foo',
})
await this.application.mutator.insertItem(note)
note = this.application.items.findItem(note.uuid)
await application.mutator.insertItem(note)
note = application.items.findItem(note.uuid)
expect(note.content.title).to.equal('Foo')
})
@@ -332,49 +337,49 @@ describe('notes and tags', () => {
it('should sort tags in ascending alphabetical order by default', async function () {
const titles = ['1', 'A', 'b', '2']
const sortedTitles = titles.sort((a, b) => a.localeCompare(b))
await Promise.all(titles.map((title) => this.application.mutator.findOrCreateTag(title)))
expect(this.application.items.tagDisplayController.items().map((t) => t.title)).to.deep.equal(sortedTitles)
await Promise.all(titles.map((title) => application.mutator.findOrCreateTag(title)))
expect(application.items.tagDisplayController.items().map((t) => t.title)).to.deep.equal(sortedTitles)
})
it('should match a tag', async function () {
const taggedNote = await Factory.createMappedNote(this.application)
const tag = await this.application.mutator.findOrCreateTag('A')
await this.application.mutator.changeItem(tag, (mutator) => {
const taggedNote = await Factory.createMappedNote(application)
const tag = await application.mutator.findOrCreateTag('A')
await application.mutator.changeItem(tag, (mutator) => {
mutator.e2ePendingRefactor_addItemAsRelationship(taggedNote)
})
await this.application.mutator.insertItem(
await this.application.items.createTemplateItem(ContentType.TYPES.Note, {
await application.mutator.insertItem(
await application.items.createTemplateItem(ContentType.TYPES.Note, {
title: 'A',
}),
)
this.application.items.setPrimaryItemDisplayOptions({
application.items.setPrimaryItemDisplayOptions({
sortBy: 'title',
sortDirection: 'dsc',
tags: [tag],
})
const displayedNotes = this.application.items.getDisplayableNotes()
const displayedNotes = application.items.getDisplayableNotes()
expect(displayedNotes.length).to.equal(1)
expect(displayedNotes[0].uuid).to.equal(taggedNote.uuid)
})
it('should not show trashed notes when displaying a tag', async function () {
const taggedNote = await Factory.createMappedNote(this.application)
const trashedNote = await Factory.createMappedNote(this.application)
const tag = await this.application.mutator.findOrCreateTag('A')
await this.application.mutator.changeItem(tag, (mutator) => {
const taggedNote = await Factory.createMappedNote(application)
const trashedNote = await Factory.createMappedNote(application)
const tag = await application.mutator.findOrCreateTag('A')
await application.mutator.changeItem(tag, (mutator) => {
mutator.e2ePendingRefactor_addItemAsRelationship(taggedNote)
mutator.e2ePendingRefactor_addItemAsRelationship(trashedNote)
})
await this.application.mutator.changeItem(trashedNote, (mutator) => {
await application.mutator.changeItem(trashedNote, (mutator) => {
mutator.trashed = true
})
this.application.items.setPrimaryItemDisplayOptions({
application.items.setPrimaryItemDisplayOptions({
sortBy: 'title',
sortDirection: 'dsc',
tags: [tag],
includeTrashed: false,
})
const displayedNotes = this.application.items.getDisplayableNotes()
const displayedNotes = application.items.getDisplayableNotes()
expect(displayedNotes.length).to.equal(1)
expect(displayedNotes[0].uuid).to.equal(taggedNote.uuid)
})
@@ -382,31 +387,31 @@ describe('notes and tags', () => {
it('should sort notes when displaying tag', async function () {
await Promise.all(
['Y', 'Z', 'A', 'B'].map(async (title) => {
return this.application.mutator.insertItem(
await this.application.items.createTemplateItem(ContentType.TYPES.Note, {
return application.mutator.insertItem(
await application.items.createTemplateItem(ContentType.TYPES.Note, {
title,
}),
)
}),
)
const pinnedNote = this.application.items.getDisplayableNotes().find((note) => note.title === 'B')
await this.application.mutator.changeItem(pinnedNote, (mutator) => {
const pinnedNote = application.items.getDisplayableNotes().find((note) => note.title === 'B')
await application.mutator.changeItem(pinnedNote, (mutator) => {
mutator.pinned = true
})
const tag = await this.application.mutator.findOrCreateTag('A')
await this.application.mutator.changeItem(tag, (mutator) => {
for (const note of this.application.items.getDisplayableNotes()) {
const tag = await application.mutator.findOrCreateTag('A')
await application.mutator.changeItem(tag, (mutator) => {
for (const note of application.items.getDisplayableNotes()) {
mutator.e2ePendingRefactor_addItemAsRelationship(note)
}
})
this.application.items.setPrimaryItemDisplayOptions({
application.items.setPrimaryItemDisplayOptions({
sortBy: 'title',
sortDirection: 'dsc',
tags: [tag],
})
const displayedNotes = this.application.items.getDisplayableNotes()
const displayedNotes = application.items.getDisplayableNotes()
expect(displayedNotes).to.have.length(4)
/** setPrimaryItemDisplayOptions inverses sort for title */
expect(displayedNotes[0].title).to.equal('B')
@@ -416,18 +421,18 @@ describe('notes and tags', () => {
describe('Smart views', function () {
it('"title", "startsWith", "Foo"', async function () {
const note = await this.application.mutator.insertItem(
await this.application.items.createTemplateItem(ContentType.TYPES.Note, {
const note = await application.mutator.insertItem(
await application.items.createTemplateItem(ContentType.TYPES.Note, {
title: 'Foo 🎲',
}),
)
await this.application.mutator.insertItem(
await this.application.items.createTemplateItem(ContentType.TYPES.Note, {
await application.mutator.insertItem(
await application.items.createTemplateItem(ContentType.TYPES.Note, {
title: 'Not Foo 🎲',
}),
)
const view = await this.application.mutator.insertItem(
await this.application.items.createTemplateItem(ContentType.TYPES.SmartView, {
const view = await application.mutator.insertItem(
await application.items.createTemplateItem(ContentType.TYPES.SmartView, {
title: 'Foo Notes',
predicate: {
keypath: 'title',
@@ -436,36 +441,36 @@ describe('notes and tags', () => {
},
}),
)
const matches = this.application.items.notesMatchingSmartView(view)
this.application.items.setPrimaryItemDisplayOptions({
const matches = application.items.notesMatchingSmartView(view)
application.items.setPrimaryItemDisplayOptions({
sortBy: 'title',
sortDirection: 'asc',
views: [view],
})
const displayedNotes = this.application.items.getDisplayableNotes()
const displayedNotes = application.items.getDisplayableNotes()
expect(displayedNotes).to.deep.equal(matches)
expect(matches.length).to.equal(1)
expect(matches[0].uuid).to.equal(note.uuid)
})
it('"pinned", "=", true', async function () {
const note = await this.application.mutator.insertItem(
await this.application.items.createTemplateItem(ContentType.TYPES.Note, {
const note = await application.mutator.insertItem(
await application.items.createTemplateItem(ContentType.TYPES.Note, {
title: 'A',
}),
)
await this.application.mutator.changeItem(note, (mutator) => {
await application.mutator.changeItem(note, (mutator) => {
mutator.pinned = true
})
await this.application.mutator.insertItem(
await this.application.items.createTemplateItem(ContentType.TYPES.Note, {
await application.mutator.insertItem(
await application.items.createTemplateItem(ContentType.TYPES.Note, {
title: 'B',
pinned: false,
}),
)
const view = await this.application.mutator.insertItem(
await this.application.items.createTemplateItem(ContentType.TYPES.SmartView, {
const view = await application.mutator.insertItem(
await application.items.createTemplateItem(ContentType.TYPES.SmartView, {
title: 'Pinned',
predicate: {
keypath: 'pinned',
@@ -474,35 +479,35 @@ describe('notes and tags', () => {
},
}),
)
const matches = this.application.items.notesMatchingSmartView(view)
this.application.items.setPrimaryItemDisplayOptions({
const matches = application.items.notesMatchingSmartView(view)
application.items.setPrimaryItemDisplayOptions({
sortBy: 'title',
sortDirection: 'asc',
views: [view],
})
const displayedNotes = this.application.items.getDisplayableNotes()
const displayedNotes = application.items.getDisplayableNotes()
expect(displayedNotes).to.deep.equal(matches)
expect(matches.length).to.equal(1)
expect(matches[0].uuid).to.equal(note.uuid)
})
it('"pinned", "=", false', async function () {
const pinnedNote = await this.application.mutator.insertItem(
await this.application.items.createTemplateItem(ContentType.TYPES.Note, {
const pinnedNote = await application.mutator.insertItem(
await application.items.createTemplateItem(ContentType.TYPES.Note, {
title: 'A',
}),
)
await this.application.mutator.changeItem(pinnedNote, (mutator) => {
await application.mutator.changeItem(pinnedNote, (mutator) => {
mutator.pinned = true
})
const unpinnedNote = await this.application.mutator.insertItem(
await this.application.items.createTemplateItem(ContentType.TYPES.Note, {
const unpinnedNote = await application.mutator.insertItem(
await application.items.createTemplateItem(ContentType.TYPES.Note, {
title: 'B',
}),
)
const view = await this.application.mutator.insertItem(
await this.application.items.createTemplateItem(ContentType.TYPES.SmartView, {
const view = await application.mutator.insertItem(
await application.items.createTemplateItem(ContentType.TYPES.SmartView, {
title: 'Not pinned',
predicate: {
keypath: 'pinned',
@@ -511,34 +516,34 @@ describe('notes and tags', () => {
},
}),
)
const matches = this.application.items.notesMatchingSmartView(view)
this.application.items.setPrimaryItemDisplayOptions({
const matches = application.items.notesMatchingSmartView(view)
application.items.setPrimaryItemDisplayOptions({
sortBy: 'title',
sortDirection: 'asc',
views: [view],
})
const displayedNotes = this.application.items.getDisplayableNotes()
const displayedNotes = application.items.getDisplayableNotes()
expect(displayedNotes).to.deep.equal(matches)
expect(matches.length).to.equal(1)
expect(matches[0].uuid).to.equal(unpinnedNote.uuid)
})
it('"text.length", ">", 500', async function () {
const longNote = await this.application.mutator.insertItem(
await this.application.items.createTemplateItem(ContentType.TYPES.Note, {
const longNote = await application.mutator.insertItem(
await application.items.createTemplateItem(ContentType.TYPES.Note, {
title: 'A',
text: Array(501).fill(0).join(''),
}),
)
await this.application.mutator.insertItem(
await this.application.items.createTemplateItem(ContentType.TYPES.Note, {
await application.mutator.insertItem(
await application.items.createTemplateItem(ContentType.TYPES.Note, {
title: 'B',
text: 'b',
}),
)
const view = await this.application.mutator.insertItem(
await this.application.items.createTemplateItem(ContentType.TYPES.SmartView, {
const view = await application.mutator.insertItem(
await application.items.createTemplateItem(ContentType.TYPES.SmartView, {
title: 'Long',
predicate: {
keypath: 'text.length',
@@ -547,13 +552,13 @@ describe('notes and tags', () => {
},
}),
)
const matches = this.application.items.notesMatchingSmartView(view)
this.application.items.setPrimaryItemDisplayOptions({
const matches = application.items.notesMatchingSmartView(view)
application.items.setPrimaryItemDisplayOptions({
sortBy: 'title',
sortDirection: 'asc',
views: [view],
})
const displayedNotes = this.application.items.getDisplayableNotes()
const displayedNotes = application.items.getDisplayableNotes()
expect(displayedNotes).to.deep.equal(matches)
expect(matches.length).to.equal(1)
expect(matches[0].uuid).to.equal(longNote.uuid)
@@ -561,22 +566,22 @@ describe('notes and tags', () => {
it('"updated_at", ">", "1.days.ago"', async function () {
await Factory.registerUserToApplication({
application: this.application,
application: application,
email: Utils.generateUuid(),
password: Utils.generateUuid(),
})
const recentNote = await this.application.mutator.insertItem(
await this.application.items.createTemplateItem(ContentType.TYPES.Note, {
const recentNote = await application.mutator.insertItem(
await application.items.createTemplateItem(ContentType.TYPES.Note, {
title: 'A',
}),
true,
)
await this.application.sync.sync()
await application.sync.sync()
const olderNote = await this.application.mutator.insertItem(
await this.application.items.createTemplateItem(ContentType.TYPES.Note, {
const olderNote = await application.mutator.insertItem(
await application.items.createTemplateItem(ContentType.TYPES.Note, {
title: 'B',
text: 'b',
}),
@@ -584,17 +589,17 @@ describe('notes and tags', () => {
)
const threeDays = 3 * 24 * 60 * 60 * 1000
await Factory.changePayloadUpdatedAt(this.application, olderNote.payload, new Date(Date.now() - threeDays))
await Factory.changePayloadUpdatedAt(application, olderNote.payload, new Date(Date.now() - threeDays))
/** Create an unsynced note which shouldn't get an updated_at */
await this.application.mutator.insertItem(
await this.application.items.createTemplateItem(ContentType.TYPES.Note, {
await application.mutator.insertItem(
await application.items.createTemplateItem(ContentType.TYPES.Note, {
title: 'B',
text: 'b',
}),
)
const view = await this.application.mutator.insertItem(
await this.application.items.createTemplateItem(ContentType.TYPES.SmartView, {
const view = await application.mutator.insertItem(
await application.items.createTemplateItem(ContentType.TYPES.SmartView, {
title: 'One day ago',
predicate: {
keypath: 'serverUpdatedAt',
@@ -603,33 +608,33 @@ describe('notes and tags', () => {
},
}),
)
const matches = this.application.items.notesMatchingSmartView(view)
const matches = application.items.notesMatchingSmartView(view)
expect(matches.length).to.equal(1)
expect(matches[0].uuid).to.equal(recentNote.uuid)
this.application.items.setPrimaryItemDisplayOptions({
application.items.setPrimaryItemDisplayOptions({
sortBy: 'title',
sortDirection: 'asc',
views: [view],
})
const displayedNotes = this.application.items.getDisplayableNotes()
const displayedNotes = application.items.getDisplayableNotes()
expect(displayedNotes).to.deep.equal(matches)
})
it('"tags.length", "=", 0', async function () {
const untaggedNote = await this.application.mutator.insertItem(
await this.application.items.createTemplateItem(ContentType.TYPES.Note, {
const untaggedNote = await application.mutator.insertItem(
await application.items.createTemplateItem(ContentType.TYPES.Note, {
title: 'A',
}),
)
const taggedNote = await Factory.createMappedNote(this.application)
const tag = await this.application.mutator.findOrCreateTag('A')
await this.application.mutator.changeItem(tag, (mutator) => {
const taggedNote = await Factory.createMappedNote(application)
const tag = await application.mutator.findOrCreateTag('A')
await application.mutator.changeItem(tag, (mutator) => {
mutator.e2ePendingRefactor_addItemAsRelationship(taggedNote)
})
const view = await this.application.mutator.insertItem(
await this.application.items.createTemplateItem(ContentType.TYPES.SmartView, {
const view = await application.mutator.insertItem(
await application.items.createTemplateItem(ContentType.TYPES.SmartView, {
title: 'Untagged',
predicate: {
keypath: 'tags.length',
@@ -638,32 +643,32 @@ describe('notes and tags', () => {
},
}),
)
const matches = this.application.items.notesMatchingSmartView(view)
this.application.items.setPrimaryItemDisplayOptions({
const matches = application.items.notesMatchingSmartView(view)
application.items.setPrimaryItemDisplayOptions({
sortBy: 'title',
sortDirection: 'asc',
views: [view],
})
const displayedNotes = this.application.items.getDisplayableNotes()
const displayedNotes = application.items.getDisplayableNotes()
expect(displayedNotes).to.deep.equal(matches)
expect(matches.length).to.equal(1)
expect(matches[0].uuid).to.equal(untaggedNote.uuid)
})
it('"tags", "includes", ["title", "startsWith", "b"]', async function () {
const taggedNote = await Factory.createMappedNote(this.application)
const tag = await this.application.mutator.findOrCreateTag('B')
await this.application.mutator.changeItem(tag, (mutator) => {
const taggedNote = await Factory.createMappedNote(application)
const tag = await application.mutator.findOrCreateTag('B')
await application.mutator.changeItem(tag, (mutator) => {
mutator.e2ePendingRefactor_addItemAsRelationship(taggedNote)
})
await this.application.mutator.insertItem(
await this.application.items.createTemplateItem(ContentType.TYPES.Note, {
await application.mutator.insertItem(
await application.items.createTemplateItem(ContentType.TYPES.Note, {
title: 'A',
}),
)
const view = await this.application.mutator.insertItem(
await this.application.items.createTemplateItem(ContentType.TYPES.SmartView, {
const view = await application.mutator.insertItem(
await application.items.createTemplateItem(ContentType.TYPES.SmartView, {
title: 'B-tags',
predicate: {
keypath: 'tags',
@@ -672,45 +677,45 @@ describe('notes and tags', () => {
},
}),
)
const matches = this.application.items.notesMatchingSmartView(view)
this.application.items.setPrimaryItemDisplayOptions({
const matches = application.items.notesMatchingSmartView(view)
application.items.setPrimaryItemDisplayOptions({
sortBy: 'title',
sortDirection: 'asc',
views: [view],
})
const displayedNotes = this.application.items.getDisplayableNotes()
const displayedNotes = application.items.getDisplayableNotes()
expect(displayedNotes).to.deep.equal(matches)
expect(matches.length).to.equal(1)
expect(matches[0].uuid).to.equal(taggedNote.uuid)
})
it('"ignored", "and", [["pinned", "=", true], ["locked", "=", true]]', async function () {
const pinnedAndLockedNote = await Factory.createMappedNote(this.application)
await this.application.mutator.changeItem(pinnedAndLockedNote, (mutator) => {
const pinnedAndLockedNote = await Factory.createMappedNote(application)
await application.mutator.changeItem(pinnedAndLockedNote, (mutator) => {
mutator.pinned = true
mutator.locked = true
})
const pinnedNote = await this.application.mutator.insertItem(
await this.application.items.createTemplateItem(ContentType.TYPES.Note, {
const pinnedNote = await application.mutator.insertItem(
await application.items.createTemplateItem(ContentType.TYPES.Note, {
title: 'A',
}),
)
await this.application.mutator.changeItem(pinnedNote, (mutator) => {
await application.mutator.changeItem(pinnedNote, (mutator) => {
mutator.pinned = true
})
const lockedNote = await this.application.mutator.insertItem(
await this.application.items.createTemplateItem(ContentType.TYPES.Note, {
const lockedNote = await application.mutator.insertItem(
await application.items.createTemplateItem(ContentType.TYPES.Note, {
title: 'A',
}),
)
await this.application.mutator.changeItem(lockedNote, (mutator) => {
await application.mutator.changeItem(lockedNote, (mutator) => {
mutator.locked = true
})
const view = await this.application.mutator.insertItem(
await this.application.items.createTemplateItem(ContentType.TYPES.SmartView, {
const view = await application.mutator.insertItem(
await application.items.createTemplateItem(ContentType.TYPES.SmartView, {
title: 'Pinned & Locked',
predicate: {
operator: 'and',
@@ -721,51 +726,51 @@ describe('notes and tags', () => {
},
}),
)
const matches = this.application.items.notesMatchingSmartView(view)
this.application.items.setPrimaryItemDisplayOptions({
const matches = application.items.notesMatchingSmartView(view)
application.items.setPrimaryItemDisplayOptions({
sortBy: 'title',
sortDirection: 'asc',
views: [view],
})
const displayedNotes = this.application.items.getDisplayableNotes()
const displayedNotes = application.items.getDisplayableNotes()
expect(displayedNotes).to.deep.equal(matches)
expect(matches.length).to.equal(1)
expect(matches[0].uuid).to.equal(pinnedAndLockedNote.uuid)
})
it('"ignored", "or", [["content.protected", "=", true], ["pinned", "=", true]]', async function () {
const protectedNote = await Factory.createMappedNote(this.application)
await this.application.mutator.changeItem(protectedNote, (mutator) => {
const protectedNote = await Factory.createMappedNote(application)
await application.mutator.changeItem(protectedNote, (mutator) => {
mutator.protected = true
})
const pinnedNote = await this.application.mutator.insertItem(
await this.application.items.createTemplateItem(ContentType.TYPES.Note, {
const pinnedNote = await application.mutator.insertItem(
await application.items.createTemplateItem(ContentType.TYPES.Note, {
title: 'A',
}),
)
await this.application.mutator.changeItem(pinnedNote, (mutator) => {
await application.mutator.changeItem(pinnedNote, (mutator) => {
mutator.pinned = true
})
const pinnedAndProtectedNote = await this.application.mutator.insertItem(
await this.application.items.createTemplateItem(ContentType.TYPES.Note, {
const pinnedAndProtectedNote = await application.mutator.insertItem(
await application.items.createTemplateItem(ContentType.TYPES.Note, {
title: 'A',
}),
)
await this.application.mutator.changeItem(pinnedAndProtectedNote, (mutator) => {
await application.mutator.changeItem(pinnedAndProtectedNote, (mutator) => {
mutator.pinned = true
mutator.protected = true
})
await this.application.mutator.insertItem(
await this.application.items.createTemplateItem(ContentType.TYPES.Note, {
await application.mutator.insertItem(
await application.items.createTemplateItem(ContentType.TYPES.Note, {
title: 'A',
}),
)
const view = await this.application.mutator.insertItem(
await this.application.items.createTemplateItem(ContentType.TYPES.SmartView, {
const view = await application.mutator.insertItem(
await application.items.createTemplateItem(ContentType.TYPES.SmartView, {
title: 'Protected or Pinned',
predicate: {
operator: 'or',
@@ -776,13 +781,13 @@ describe('notes and tags', () => {
},
}),
)
const matches = this.application.items.notesMatchingSmartView(view)
this.application.items.setPrimaryItemDisplayOptions({
const matches = application.items.notesMatchingSmartView(view)
application.items.setPrimaryItemDisplayOptions({
sortBy: 'created_at',
sortDirection: 'asc',
views: [view],
})
const displayedNotes = this.application.items.getDisplayableNotes()
const displayedNotes = application.items.getDisplayableNotes()
expect(displayedNotes.length).to.equal(matches.length)
expect(matches.length).to.equal(3)
expect(matches.find((note) => note.uuid === protectedNote.uuid)).to.exist
@@ -801,12 +806,12 @@ describe('notes and tags', () => {
const notePayload3 = Factory.createNotePayload('Bar')
const notePayload4 = Factory.createNotePayload('Testing')
await this.application.mutator.emitItemsFromPayloads(
await application.mutator.emitItemsFromPayloads(
[notePayload1, notePayload2, notePayload3, notePayload4, tagPayload1],
PayloadEmitSource.LocalChanged,
)
this.application.items.setPrimaryItemDisplayOptions({
application.items.setPrimaryItemDisplayOptions({
sortBy: 'title',
sortDirection: 'dsc',
searchQuery: {
@@ -814,7 +819,7 @@ describe('notes and tags', () => {
},
})
const displayedNotes = this.application.items.getDisplayableNotes()
const displayedNotes = application.items.getDisplayableNotes()
expect(displayedNotes.length).to.equal(2)
/** setPrimaryItemDisplayOptions inverses sort for title */
expect(displayedNotes[0].uuid).to.equal(notePayload1.uuid)
@@ -831,12 +836,12 @@ describe('notes and tags', () => {
const notePayload3 = Factory.createNotePayload('Testing FOO (Bar)')
const notePayload4 = Factory.createNotePayload('This should not match')
await this.application.mutator.emitItemsFromPayloads(
await application.mutator.emitItemsFromPayloads(
[notePayload1, notePayload2, notePayload3, notePayload4, tagPayload1],
PayloadEmitSource.LocalChanged,
)
this.application.items.setPrimaryItemDisplayOptions({
application.items.setPrimaryItemDisplayOptions({
sortBy: 'title',
sortDirection: 'dsc',
searchQuery: {
@@ -844,7 +849,7 @@ describe('notes and tags', () => {
},
})
const displayedNotes = this.application.items.getDisplayableNotes()
const displayedNotes = application.items.getDisplayableNotes()
expect(displayedNotes.length).to.equal(3)
/** setPrimaryItemDisplayOptions inverses sort for title */
expect(displayedNotes[0].uuid).to.equal(notePayload1.uuid)

View File

@@ -1,86 +1,91 @@
/* eslint-disable no-unused-expressions */
/* eslint-disable no-undef */
import * as Factory from '../lib/factory.js'
chai.use(chaiAsPromised)
const expect = chai.expect
describe('tags as folders', () => {
let context
let application
beforeEach(async function () {
this.context = await Factory.createAppContext()
await this.context.launch()
this.application = this.context.application
localStorage.clear()
context = await Factory.createAppContext()
await context.launch()
application = context.application
})
afterEach(async function () {
await Factory.safeDeinit(this.application)
await Factory.safeDeinit(application)
context = undefined
application = undefined
localStorage.clear()
})
it('lets me create a tag, add relationships, move a note to a children, and query data all along', async function () {
// ## The user creates four tags
let tagChildren = await Factory.createMappedTag(this.application, {
let tagChildren = await Factory.createMappedTag(application, {
title: 'children',
})
let tagParent = await Factory.createMappedTag(this.application, {
let tagParent = await Factory.createMappedTag(application, {
title: 'parent',
})
let tagGrandParent = await Factory.createMappedTag(this.application, {
let tagGrandParent = await Factory.createMappedTag(application, {
title: 'grandparent',
})
let tagGrandParent2 = await Factory.createMappedTag(this.application, {
let tagGrandParent2 = await Factory.createMappedTag(application, {
title: 'grandparent2',
})
// ## Now the users moves the tag children into the parent
await this.application.mutator.setTagParent(tagParent, tagChildren)
await application.mutator.setTagParent(tagParent, tagChildren)
expect(this.application.items.getTagParent(tagChildren)).to.equal(tagParent)
expect(Uuids(this.application.items.getTagChildren(tagParent))).deep.to.equal(Uuids([tagChildren]))
expect(application.items.getTagParent(tagChildren)).to.equal(tagParent)
expect(Uuids(application.items.getTagChildren(tagParent))).deep.to.equal(Uuids([tagChildren]))
// ## Now the user moves the tag parent into the grand parent
await this.application.mutator.setTagParent(tagGrandParent, tagParent)
await application.mutator.setTagParent(tagGrandParent, tagParent)
expect(this.application.items.getTagParent(tagParent)).to.equal(tagGrandParent)
expect(Uuids(this.application.items.getTagChildren(tagGrandParent))).deep.to.equal(Uuids([tagParent]))
expect(application.items.getTagParent(tagParent)).to.equal(tagGrandParent)
expect(Uuids(application.items.getTagChildren(tagGrandParent))).deep.to.equal(Uuids([tagParent]))
// ## Now the user moves the tag parent into another grand parent
await this.application.mutator.setTagParent(tagGrandParent2, tagParent)
await application.mutator.setTagParent(tagGrandParent2, tagParent)
expect(this.application.items.getTagParent(tagParent)).to.equal(tagGrandParent2)
expect(this.application.items.getTagChildren(tagGrandParent)).deep.to.equal([])
expect(Uuids(this.application.items.getTagChildren(tagGrandParent2))).deep.to.equal(Uuids([tagParent]))
expect(application.items.getTagParent(tagParent)).to.equal(tagGrandParent2)
expect(application.items.getTagChildren(tagGrandParent)).deep.to.equal([])
expect(Uuids(application.items.getTagChildren(tagGrandParent2))).deep.to.equal(Uuids([tagParent]))
// ## Now the user tries to move the tag into one of its children
await expect(this.application.mutator.setTagParent(tagChildren, tagParent)).to.eventually.be.rejected
await expect(application.mutator.setTagParent(tagChildren, tagParent)).to.eventually.be.rejected
expect(this.application.items.getTagParent(tagParent)).to.equal(tagGrandParent2)
expect(this.application.items.getTagChildren(tagGrandParent)).deep.to.equal([])
expect(Uuids(this.application.items.getTagChildren(tagGrandParent2))).deep.to.equal(Uuids([tagParent]))
expect(application.items.getTagParent(tagParent)).to.equal(tagGrandParent2)
expect(application.items.getTagChildren(tagGrandParent)).deep.to.equal([])
expect(Uuids(application.items.getTagChildren(tagGrandParent2))).deep.to.equal(Uuids([tagParent]))
// ## Now the user move the tag outside any hierarchy
await this.application.mutator.unsetTagParent(tagParent)
await application.mutator.unsetTagParent(tagParent)
expect(this.application.items.getTagParent(tagParent)).to.equal(undefined)
expect(this.application.items.getTagChildren(tagGrandParent2)).deep.to.equals([])
expect(application.items.getTagParent(tagParent)).to.equal(undefined)
expect(application.items.getTagChildren(tagGrandParent2)).deep.to.equals([])
})
it('lets me add a note to a tag hierarchy', async function () {
// ## The user creates four tags hierarchy
const tags = await Factory.createTags(this.application, {
const tags = await Factory.createTags(application, {
grandparent: { parent: { child: true } },
another: true,
})
const note1 = await Factory.createMappedNote(this.application, 'my first note')
const note2 = await Factory.createMappedNote(this.application, 'my second note')
const note1 = await Factory.createMappedNote(application, 'my first note')
const note2 = await Factory.createMappedNote(application, 'my second note')
// ## The user add a note to the child tag
await this.application.mutator.addTagToNote(note1, tags.child, true)
await this.application.mutator.addTagToNote(note2, tags.another, true)
await application.mutator.addTagToNote(note1, tags.child, true)
await application.mutator.addTagToNote(note2, tags.another, true)
// ## The note has been added to other tags
const note1Tags = await this.application.items.getSortedTagsForItem(note1)
const note2Tags = await this.application.items.getSortedTagsForItem(note2)
const note1Tags = await application.items.getSortedTagsForItem(note1)
const note2Tags = await application.items.getSortedTagsForItem(note2)
expect(note1Tags.length).to.equal(3)
expect(note2Tags.length).to.equal(1)

View File

@@ -1,10 +1,17 @@
/* eslint-disable no-unused-expressions */
/* eslint-disable no-undef */
import * as Factory from '../lib/factory.js'
chai.use(chaiAsPromised)
const expect = chai.expect
describe('mapping performance', () => {
beforeEach(function () {
localStorage.clear()
})
afterEach(async function () {
localStorage.clear()
})
it('shouldnt take a long time', async () => {
/*
There was an issue with mapping where we were using arrays for everything instead of hashes (like items, missedReferences),