2016-03-15 06:34:16 +08:00
|
|
|
import {NylasSyncStatusStore} from 'nylas-exports'
|
|
|
|
|
|
|
|
const store = NylasSyncStatusStore
|
|
|
|
|
2016-05-05 05:03:15 +08:00
|
|
|
describe('NylasSyncStatusStore', function nylasSyncStatusStore() {
|
2016-05-06 13:30:34 +08:00
|
|
|
beforeEach(() => {
|
2016-03-15 06:34:16 +08:00
|
|
|
store._statesByAccount = {}
|
|
|
|
});
|
|
|
|
|
2016-05-06 13:30:34 +08:00
|
|
|
describe('isSyncCompleteForAccount', () => {
|
|
|
|
describe('when model (collection) provided', () => {
|
|
|
|
it('returns true if syncing for the given model and account is complete', () => {
|
2016-03-15 06:34:16 +08:00
|
|
|
store._statesByAccount = {
|
|
|
|
a1: {
|
|
|
|
labels: {complete: true},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
expect(store.isSyncCompleteForAccount('a1', 'labels')).toBe(true)
|
|
|
|
});
|
|
|
|
|
2016-05-06 13:30:34 +08:00
|
|
|
it('returns false otherwise', () => {
|
2016-03-15 06:34:16 +08:00
|
|
|
const states = [
|
|
|
|
{ a1: { labels: {complete: false} } },
|
|
|
|
{ a1: {} },
|
|
|
|
{},
|
|
|
|
]
|
2016-05-06 13:30:34 +08:00
|
|
|
states.forEach((state) => {
|
2016-03-15 06:34:16 +08:00
|
|
|
store._statesByAccount = state
|
|
|
|
expect(store.isSyncCompleteForAccount('a1', 'labels')).toBe(false)
|
|
|
|
})
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2016-05-06 13:30:34 +08:00
|
|
|
describe('when model not provided', () => {
|
|
|
|
it('returns true if sync is complete for all models for the given account', () => {
|
2016-03-15 06:34:16 +08:00
|
|
|
store._statesByAccount = {
|
|
|
|
a1: {
|
|
|
|
labels: {complete: true},
|
|
|
|
threads: {complete: true},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
expect(store.isSyncCompleteForAccount('a1')).toBe(true)
|
|
|
|
});
|
|
|
|
|
2016-05-06 13:30:34 +08:00
|
|
|
it('returns false otherwise', () => {
|
2016-03-15 06:34:16 +08:00
|
|
|
store._statesByAccount = {
|
|
|
|
a1: {
|
|
|
|
labels: {complete: true},
|
|
|
|
threads: {complete: false},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
expect(store.isSyncCompleteForAccount('a1')).toBe(false)
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2016-05-06 13:30:34 +08:00
|
|
|
describe('isSyncComplete', () => {
|
|
|
|
it('returns true if sync is complete for all accounts', () => {
|
2016-03-15 06:34:16 +08:00
|
|
|
spyOn(store, 'isSyncCompleteForAccount').andReturn(true)
|
|
|
|
store._statesByAccount = {
|
|
|
|
a1: {},
|
|
|
|
a2: {},
|
|
|
|
}
|
|
|
|
expect(store.isSyncComplete('a1')).toBe(true)
|
|
|
|
});
|
|
|
|
|
2016-05-06 13:30:34 +08:00
|
|
|
it('returns false otherwise', () => {
|
2016-05-07 05:10:28 +08:00
|
|
|
spyOn(store, 'isSyncCompleteForAccount').andCallFake(acctId => acctId === 'a1')
|
2016-03-15 06:34:16 +08:00
|
|
|
store._statesByAccount = {
|
|
|
|
a1: {},
|
|
|
|
a2: {},
|
|
|
|
}
|
|
|
|
expect(store.isSyncComplete('a1')).toBe(false)
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|