mirror of
https://github.com/Foundry376/Mailspring.git
synced 2024-11-12 12:40:08 +08:00
37 lines
1.5 KiB
CoffeeScript
37 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)
|