mirror of
https://github.com/Foundry376/Mailspring.git
synced 2024-11-13 21:24:58 +08:00
812b64edec
Summary: - Was not properly updating the references to snoozed categories when accounts were added or removed - Update whenCategoriesReady to make sure we listen until category syncing has concluded (Move inside CategoryStore) - #1676, #1658 Test Plan: - TODO Reviewers: evan, drew, bengotow Reviewed By: bengotow Differential Revision: https://phab.nylas.com/D2723
61 lines
2.1 KiB
JavaScript
61 lines
2.1 KiB
JavaScript
import {
|
|
Rx,
|
|
AccountStore,
|
|
CategoryStore,
|
|
NylasSyncStatusStore,
|
|
} from 'nylas-exports';
|
|
|
|
describe('CategoryStore', ()=> {
|
|
beforeEach(()=> {
|
|
spyOn(AccountStore, 'accountForId').andReturn({categoryCollection: ()=> 'labels'})
|
|
});
|
|
|
|
describe('whenCategoriesReady', ()=> {
|
|
it('resolves immediately if sync is done and cache is populated', ()=> {
|
|
spyOn(NylasSyncStatusStore, 'isSyncCompleteForAccount').andReturn(true)
|
|
spyOn(CategoryStore, 'categories').andReturn([{name: 'inbox'}])
|
|
spyOn(Rx.Observable, 'fromStore')
|
|
waitsForPromise(()=> {
|
|
const promise = CategoryStore.whenCategoriesReady('a1')
|
|
expect(promise.isResolved()).toBe(true)
|
|
return promise.then(()=> {
|
|
expect(Rx.Observable.fromStore).not.toHaveBeenCalled()
|
|
})
|
|
})
|
|
});
|
|
|
|
it('resolves only when sync is done even if cache is already populated', ()=> {
|
|
spyOn(NylasSyncStatusStore, 'isSyncCompleteForAccount').andReturn(false)
|
|
spyOn(CategoryStore, 'categories').andReturn([{name: 'inbox'}])
|
|
waitsForPromise(()=> {
|
|
const promise = CategoryStore.whenCategoriesReady('a1')
|
|
expect(promise.isResolved()).toBe(false)
|
|
|
|
jasmine.unspy(NylasSyncStatusStore, 'isSyncCompleteForAccount')
|
|
spyOn(NylasSyncStatusStore, 'isSyncCompleteForAccount').andReturn(true)
|
|
NylasSyncStatusStore.trigger()
|
|
|
|
return promise.then(()=> {
|
|
expect(promise.isResolved()).toBe(true)
|
|
})
|
|
})
|
|
});
|
|
|
|
it('resolves only when cache is populated even if sync is done', ()=> {
|
|
spyOn(NylasSyncStatusStore, 'isSyncCompleteForAccount').andReturn(true)
|
|
spyOn(CategoryStore, 'categories').andReturn([])
|
|
waitsForPromise(()=> {
|
|
const promise = CategoryStore.whenCategoriesReady('a1')
|
|
expect(promise.isResolved()).toBe(false)
|
|
|
|
jasmine.unspy(CategoryStore, 'categories')
|
|
spyOn(CategoryStore, 'categories').andReturn([{name: 'inbox'}])
|
|
CategoryStore.trigger()
|
|
|
|
return promise.then(()=> {
|
|
expect(promise.isResolved()).toBe(true)
|
|
})
|
|
})
|
|
});
|
|
});
|
|
});
|