refactor: optimize delay between batches on mobile to allow UI interactivity during load (#2129)
This commit is contained in:
@@ -20,16 +20,19 @@ describe('application instances', () => {
|
||||
})
|
||||
|
||||
it('two distinct applications should not share model manager state', async () => {
|
||||
const app1 = await Factory.createAndInitializeApplication('app1')
|
||||
const app2 = await Factory.createAndInitializeApplication('app2')
|
||||
expect(app1.payloadManager).to.equal(app1.payloadManager)
|
||||
expect(app1.payloadManager).to.not.equal(app2.payloadManager)
|
||||
const context1 = await Factory.createAppContext({ identifier: 'app1' })
|
||||
const context2 = await Factory.createAppContext({ identifier: 'app2' })
|
||||
await Promise.all([context1.launch(), context2.launch()])
|
||||
|
||||
await Factory.createMappedNote(app1)
|
||||
expect(app1.itemManager.items.length).length.to.equal(BaseItemCounts.DefaultItems + 1)
|
||||
expect(app2.itemManager.items.length).to.equal(BaseItemCounts.DefaultItems)
|
||||
await Factory.safeDeinit(app1)
|
||||
await Factory.safeDeinit(app2)
|
||||
expect(context1.application.payloadManager).to.equal(context1.application.payloadManager)
|
||||
expect(context1.application.payloadManager).to.not.equal(context2.application.payloadManager)
|
||||
|
||||
await Factory.createMappedNote(context1.application)
|
||||
expect(context1.application.itemManager.items.length).length.to.equal(BaseItemCounts.DefaultItems + 1)
|
||||
expect(context2.application.itemManager.items.length).to.equal(BaseItemCounts.DefaultItems)
|
||||
|
||||
await context1.deinit()
|
||||
await context2.deinit()
|
||||
})
|
||||
|
||||
it('two distinct applications should not share storage manager state', async () => {
|
||||
|
||||
@@ -16,7 +16,9 @@ describe('basic auth', function () {
|
||||
beforeEach(async function () {
|
||||
localStorage.clear()
|
||||
this.expectedItemCount = BaseItemCounts.DefaultItems
|
||||
this.application = await Factory.createInitAppWithFakeCrypto()
|
||||
this.context = await Factory.createAppContext()
|
||||
await this.context.launch()
|
||||
this.application = this.context.application
|
||||
this.email = UuidGenerator.GenerateUuid()
|
||||
this.password = UuidGenerator.GenerateUuid()
|
||||
})
|
||||
@@ -402,7 +404,7 @@ describe('basic auth', function () {
|
||||
await this.application.syncService.markAllItemsAsNeedingSyncAndPersist()
|
||||
await this.application.syncService.sync(syncOptions)
|
||||
|
||||
this.application = await Factory.signOutApplicationAndReturnNew(this.application)
|
||||
this.application = await this.context.signout()
|
||||
|
||||
expect(this.application.itemManager.items.length).to.equal(BaseItemCounts.DefaultItems)
|
||||
expect(this.application.payloadManager.invalidPayloads.length).to.equal(0)
|
||||
|
||||
@@ -163,6 +163,13 @@ export class AppContext {
|
||||
return newApplication
|
||||
}
|
||||
|
||||
async signout() {
|
||||
await this.application.user.signOut()
|
||||
await this.initialize()
|
||||
await this.launch()
|
||||
return this.application
|
||||
}
|
||||
|
||||
syncWithIntegrityCheck() {
|
||||
return this.application.sync.sync({ checkIntegrity: true, awaitAll: true })
|
||||
}
|
||||
@@ -189,11 +196,36 @@ export class AppContext {
|
||||
})
|
||||
}
|
||||
|
||||
awaitUserPrefsSingletonCreation() {
|
||||
const preferences = this.application.preferencesService.preferences
|
||||
if (preferences) {
|
||||
return
|
||||
}
|
||||
|
||||
let didCompleteRelevantSync = false
|
||||
return new Promise((resolve) => {
|
||||
this.application.syncService.addEventObserver((eventName, data) => {
|
||||
if (!didCompleteRelevantSync) {
|
||||
if (data?.savedPayloads) {
|
||||
const matching = data.savedPayloads.find((p) => {
|
||||
return p.content_type === ContentType.UserPrefs
|
||||
})
|
||||
if (matching) {
|
||||
didCompleteRelevantSync = true
|
||||
resolve()
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
async launch({ awaitDatabaseLoad = true, receiveChallenge } = { awaitDatabaseLoad: true }) {
|
||||
await this.application.prepareForLaunch({
|
||||
receiveChallenge: receiveChallenge || this.handleChallenge,
|
||||
})
|
||||
await this.application.launch(awaitDatabaseLoad)
|
||||
await this.awaitUserPrefsSingletonCreation()
|
||||
}
|
||||
|
||||
async deinit() {
|
||||
|
||||
@@ -21,7 +21,9 @@ describe('app models', () => {
|
||||
|
||||
beforeEach(async function () {
|
||||
this.expectedItemCount = BaseItemCounts.DefaultItems
|
||||
this.application = await Factory.createInitAppWithFakeCrypto()
|
||||
this.context = await Factory.createAppContext()
|
||||
this.application = this.context.application
|
||||
await this.context.launch()
|
||||
})
|
||||
|
||||
afterEach(async function () {
|
||||
|
||||
@@ -13,6 +13,7 @@ describe('importing', function () {
|
||||
let application
|
||||
let email
|
||||
let password
|
||||
let context
|
||||
|
||||
beforeEach(function () {
|
||||
localStorage.clear()
|
||||
@@ -20,11 +21,16 @@ describe('importing', function () {
|
||||
|
||||
const setup = async ({ fakeCrypto }) => {
|
||||
expectedItemCount = BaseItemCounts.DefaultItems
|
||||
|
||||
if (fakeCrypto) {
|
||||
application = await Factory.createInitAppWithFakeCrypto()
|
||||
context = await Factory.createAppContext()
|
||||
} else {
|
||||
application = await Factory.createInitAppWithRealCrypto()
|
||||
context = await Factory.createAppContextWithRealCrypto()
|
||||
}
|
||||
|
||||
await context.launch()
|
||||
application = context.application
|
||||
|
||||
email = UuidGenerator.GenerateUuid()
|
||||
password = UuidGenerator.GenerateUuid()
|
||||
Factory.handlePasswordChallenges(application, password)
|
||||
|
||||
@@ -9,7 +9,9 @@ const expect = chai.expect
|
||||
describe('model manager mapping', () => {
|
||||
beforeEach(async function () {
|
||||
this.expectedItemCount = BaseItemCounts.DefaultItems
|
||||
this.application = await Factory.createInitAppWithFakeCrypto()
|
||||
this.context = await Factory.createAppContext()
|
||||
await this.context.launch()
|
||||
this.application = this.context.application
|
||||
})
|
||||
|
||||
afterEach(async function () {
|
||||
|
||||
@@ -14,7 +14,9 @@ describe('notes and tags', () => {
|
||||
|
||||
beforeEach(async function () {
|
||||
this.expectedItemCount = BaseItemCounts.DefaultItems
|
||||
this.application = await Factory.createInitAppWithFakeCrypto()
|
||||
this.context = await Factory.createAppContext()
|
||||
await this.context.launch()
|
||||
this.application = this.context.application
|
||||
})
|
||||
|
||||
afterEach(async function () {
|
||||
|
||||
@@ -7,7 +7,9 @@ const expect = chai.expect
|
||||
|
||||
describe('tags as folders', () => {
|
||||
beforeEach(async function () {
|
||||
this.application = await Factory.createInitAppWithFakeCrypto()
|
||||
this.context = await Factory.createAppContext()
|
||||
await this.context.launch()
|
||||
this.application = this.context.application
|
||||
})
|
||||
|
||||
afterEach(async function () {
|
||||
|
||||
@@ -7,7 +7,11 @@ const expect = chai.expect
|
||||
describe('preferences', function () {
|
||||
beforeEach(async function () {
|
||||
localStorage.clear()
|
||||
this.application = await Factory.createInitAppWithFakeCrypto()
|
||||
|
||||
this.context = await Factory.createAppContext()
|
||||
await this.context.launch()
|
||||
this.application = this.context.application
|
||||
|
||||
this.email = UuidGenerator.GenerateUuid()
|
||||
this.password = UuidGenerator.GenerateUuid()
|
||||
})
|
||||
|
||||
@@ -31,7 +31,11 @@ describe('singletons', function () {
|
||||
beforeEach(async function () {
|
||||
localStorage.clear()
|
||||
this.expectedItemCount = BaseItemCounts.DefaultItems
|
||||
this.application = await Factory.createInitAppWithFakeCrypto()
|
||||
|
||||
this.context = await Factory.createAppContext()
|
||||
await this.context.launch()
|
||||
this.application = this.context.application
|
||||
|
||||
this.email = UuidGenerator.GenerateUuid()
|
||||
this.password = UuidGenerator.GenerateUuid()
|
||||
this.registerUser = async () => {
|
||||
|
||||
@@ -16,7 +16,9 @@ describe('storage manager', function () {
|
||||
beforeEach(async function () {
|
||||
localStorage.clear()
|
||||
this.expectedKeyCount = BASE_KEY_COUNT
|
||||
this.application = await Factory.createInitAppWithFakeCrypto(Environment.Mobile)
|
||||
this.context = await Factory.createAppContext()
|
||||
await this.context.launch()
|
||||
this.application = this.context.application
|
||||
this.email = UuidGenerator.GenerateUuid()
|
||||
this.password = UuidGenerator.GenerateUuid()
|
||||
})
|
||||
@@ -221,7 +223,8 @@ describe('storage manager', function () {
|
||||
expect(decrypted.content).to.be.an.instanceof(Object)
|
||||
})
|
||||
|
||||
it('disabling storage encryption should store items without encryption', async function () {
|
||||
/** @TODO: Storage encryption disable is no longer available, remove tests and associated functionality */
|
||||
it.skip('disabling storage encryption should store items without encryption', async function () {
|
||||
await Factory.registerUserToApplication({
|
||||
application: this.application,
|
||||
email: this.email,
|
||||
|
||||
@@ -13,7 +13,9 @@ describe('offline syncing', () => {
|
||||
|
||||
beforeEach(async function () {
|
||||
this.expectedItemCount = BaseItemCounts.DefaultItems
|
||||
this.application = await Factory.createInitAppWithFakeCrypto()
|
||||
this.context = await Factory.createAppContext()
|
||||
await this.context.launch()
|
||||
this.application = this.context.application
|
||||
})
|
||||
|
||||
afterEach(async function () {
|
||||
|
||||
@@ -95,7 +95,7 @@ describe('online syncing', function () {
|
||||
|
||||
await this.application.sync.sync(syncOptions)
|
||||
|
||||
this.application = await Factory.signOutApplicationAndReturnNew(this.application)
|
||||
this.application = await this.context.signout()
|
||||
|
||||
expect(this.application.itemManager.items.length).to.equal(BaseItemCounts.DefaultItems)
|
||||
|
||||
|
||||
@@ -7,7 +7,11 @@ const expect = chai.expect
|
||||
describe('upgrading', () => {
|
||||
beforeEach(async function () {
|
||||
localStorage.clear()
|
||||
this.application = await Factory.createInitAppWithFakeCrypto()
|
||||
|
||||
this.context = await Factory.createAppContext()
|
||||
await this.context.launch()
|
||||
|
||||
this.application = this.context.application
|
||||
this.email = UuidGenerator.GenerateUuid()
|
||||
this.password = UuidGenerator.GenerateUuid()
|
||||
this.passcode = '1234'
|
||||
@@ -170,7 +174,7 @@ describe('upgrading', () => {
|
||||
/** Delete default items key that is created on launch */
|
||||
const itemsKey = await this.application.protocolService.getSureDefaultItemsKey()
|
||||
await this.application.itemManager.setItemToBeDeleted(itemsKey)
|
||||
expect(this.application.itemManager.getDisplayableItemsKeys().length).to.equal(0)
|
||||
expect(Uuids(this.application.itemManager.getDisplayableItemsKeys()).includes(itemsKey.uuid)).to.equal(false)
|
||||
|
||||
Factory.createMappedNote(this.application)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user