Mailspring/spec/stores/nylas-sync-status-store-spec.es6
Juan Tejada d92506d8f1 fix(sync-status): Change old per model status, in favor of per folder
Summary:
Addresses T7275
Previously, we kept track of the sync status of each API model, and the progress
we'd made syncing all available models (e.g. all threads, messages, events, etc)

Given K2's set up, we are now keeping track of sync status per folder, i.e. what
percent of the folder's messages we've synced. This status is now reported from K2
to N1 via folder object deltas, and this commit rewrites the
NylasSyncStatusStore (in ES6) to reflect that.

The new Store keeps the sync state per account, which is the merged state of
per folder sync state, and delta connections state.
We also got rid of `CategoryStore.whenCategoriesReady` in favor of
`whenCategoryListSynced`, which is derived from the fact hat as long as we've
started syncing one folder, we've already synced the entire list of of folders/labels.

There are a couple of TODOs to be addressed in upcoming diffs:
- T7329 Restore the sidebar component to show sync progress, which was previously removed
- T7330 Figure out how to report sync progress per label, specifically, we are interested in knowing how much of the inbox we've synced, which is a label in Gmail. (This might be a non-issue if we sync the inbox very fast, first)

Depends on D3514

Test Plan: Manual

Reviewers: mark, evan

Reviewed By: evan

Differential Revision: https://phab.nylas.com/D3515
2016-12-15 11:17:20 -08:00

76 lines
2.1 KiB
JavaScript

import {NylasSyncStatusStore} from 'nylas-exports'
const store = NylasSyncStatusStore
xdescribe('NylasSyncStatusStore', function nylasSyncStatusStore() {
beforeEach(() => {
store._statesByAccount = {}
});
describe('isSyncCompleteForAccount', () => {
describe('when model (collection) provided', () => {
it('returns true if syncing for the given model and account is complete', () => {
store._statesByAccount = {
a1: {
labels: {complete: true},
},
}
expect(store.isSyncCompleteForAccount('a1', 'labels')).toBe(true)
});
it('returns false otherwise', () => {
const states = [
{ a1: { labels: {complete: false} } },
{ a1: {} },
{},
]
states.forEach((state) => {
store._statesByAccount = state
expect(store.isSyncCompleteForAccount('a1', 'labels')).toBe(false)
})
});
});
describe('when model not provided', () => {
it('returns true if sync is complete for all models for the given account', () => {
store._statesByAccount = {
a1: {
labels: {complete: true},
threads: {complete: true},
},
}
expect(store.isSyncCompleteForAccount('a1')).toBe(true)
});
it('returns false otherwise', () => {
store._statesByAccount = {
a1: {
labels: {complete: true},
threads: {complete: false},
},
}
expect(store.isSyncCompleteForAccount('a1')).toBe(false)
});
});
});
describe('isSyncComplete', () => {
it('returns true if sync is complete for all accounts', () => {
spyOn(store, 'isSyncCompleteForAccount').andReturn(true)
store._statesByAccount = {
a1: {},
a2: {},
}
expect(store.isSyncComplete('a1')).toBe(true)
});
it('returns false otherwise', () => {
spyOn(store, 'isSyncCompleteForAccount').andCallFake(acctId => acctId === 'a1')
store._statesByAccount = {
a1: {},
a2: {},
}
expect(store.isSyncComplete('a1')).toBe(false)
});
});
});