Mailspring/spec/models/query-subscription-pool-spec.coffee
Ben Gotow 30c58e90a6 feat(observables): Implementation of observables to replace some stores
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
2015-12-07 16:52:46 -08:00

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)