mirror of
https://github.com/Foundry376/Mailspring.git
synced 2025-03-03 11:36:08 +08:00
Summary: Add concept of "final" to Query, clean up internals Tiny bug fixes RxJs Observables! WIP Test Plan: Run tests Reviewers: evan, juan Reviewed By: juan Differential Revision: https://phab.nylas.com/D2319
36 lines
1.5 KiB
CoffeeScript
36 lines
1.5 KiB
CoffeeScript
QuerySubscriptionPool = require '../../src/flux/models/query-subscription-pool'
|
|
DatabaseStore = require '../../src/flux/stores/database-store'
|
|
Label = require '../../src/flux/models/label'
|
|
|
|
describe "QuerySubscriptionPool", ->
|
|
beforeEach ->
|
|
@query = DatabaseStore.findAll(Label)
|
|
QuerySubscriptionPool._subscriptions = []
|
|
|
|
describe "add", ->
|
|
it "should add a new subscription with the callback", ->
|
|
callback = jasmine.createSpy('callback')
|
|
QuerySubscriptionPool.add(@query, {}, callback)
|
|
expect(QuerySubscriptionPool._subscriptions.length).toBe(1)
|
|
subscription = QuerySubscriptionPool._subscriptions[0]
|
|
expect(subscription.hasCallback(callback)).toBe(true)
|
|
|
|
it "should yield database changes to the subscription", ->
|
|
callback = jasmine.createSpy('callback')
|
|
QuerySubscriptionPool.add(@query, {}, callback)
|
|
subscription = QuerySubscriptionPool._subscriptions[0]
|
|
spyOn(subscription, 'applyChangeRecord')
|
|
|
|
record = {objectType: 'whateves'}
|
|
QuerySubscriptionPool._onChange(record)
|
|
expect(subscription.applyChangeRecord).toHaveBeenCalledWith(record)
|
|
|
|
describe "unsubscribe", ->
|
|
it "should return an unsubscribe method", ->
|
|
expect(QuerySubscriptionPool.add(@query, {}, -> ) instanceof Function).toBe(true)
|
|
|
|
it "should remove the subscription", ->
|
|
unsub = QuerySubscriptionPool.add(@query, {}, -> )
|
|
expect(QuerySubscriptionPool._subscriptions.length).toBe(1)
|
|
unsub()
|
|
expect(QuerySubscriptionPool._subscriptions.length).toBe(0)
|