Mailspring/spec-inbox/inbox-sync-worker-spec.coffee
Ben Gotow 523ed4b316 feat(thread-list): Inifite scrolling, powered by new DatabaseView, InboxSyncWorker
Summary:
NamespaceStore needs to be more careful about triggering unnecessarily

ThreadListParticipants should use minimum set of <span> tags, not one per name

FocusedTagStore triggers only when the tag has actually changed

New InboxSyncWorker is responsible for fetching contacts, calendars, threads

Update the draft list to look like the thread list

ThreadStore now uses a "Database View" to vend items, which will free it up to focus on things like selection soon. The DatabaseView handles pagination and maintains a cache of items in a "retained range" the view needs. It also abstracts the...

..."thread metadata" concept into a general purpose pattern

Thread-list package implements SearchView to match the DatabaseView. Instead of fetching items from the database it uses the search API

Update existing specs

Bug fix

Specs for focused stores

New specs!

Pad search range so we prefetch the next pages

Clear the scroll offset if the view is changed (between tabs)

Test Plan: Run 58 new tests with 110 new assertions!

Reviewers: evan

Reviewed By: evan

Differential Revision: https://review.inboxapp.com/D1398
2015-04-06 11:46:20 -07:00

116 lines
3.9 KiB
CoffeeScript

_ = require 'underscore-plus'
InboxLongConnection = require '../src/flux/inbox-long-connection'
InboxSyncWorker = require '../src/flux/inbox-sync-worker'
Thread = require '../src/flux/models/thread'
describe "InboxSyncWorker", ->
beforeEach ->
@apiRequests = []
@api =
getCollection: (namespace, model, params, requestOptions) =>
@apiRequests.push({namespace, model, params, requestOptions})
getThreads: (namespace, params, requestOptions) =>
@apiRequests.push({namespace, model:'threads', params, requestOptions})
@state =
"contacts": {busy: true}
"calendars": {complete: true}
spyOn(atom.config, 'get').andCallFake (key) =>
expected = "inbox.namespace-id.worker-state"
return throw new Error("Not stubbed!") unless key is expected
return @state
spyOn(atom.config, 'set').andCallFake (key, val) =>
expected = "inbox.namespace-id.worker-state"
return throw new Error("Not stubbed!") unless key is expected
@state = val
@worker = new InboxSyncWorker(@api, 'namespace-id')
@connection = @worker.connection()
describe "start", ->
it "should open the long polling connection", ->
spyOn(@connection, 'start')
@worker.start()
expect(@connection.start).toHaveBeenCalled()
it "should start querying for model collections that haven't been fully cached", ->
@worker.start()
expect(@apiRequests.length).toBe(2)
modelsRequested = _.map @apiRequests, (r) -> r.model
expect(modelsRequested).toEqual(['threads', 'contacts'])
it "should mark incomplete collections as `busy`", ->
@worker.start()
expect(@state).toEqual({
"contacts": {busy: true}
"threads": {busy: true}
"calendars": {complete: true}
})
describe "when an API request completes", ->
beforeEach ->
@worker.start()
@request = @apiRequests[0]
@apiRequests = []
describe "successfully, with models", ->
it "should request the next page", ->
models = []
models.push(new Thread) for i in [0..499]
@request.requestOptions.success(models)
expect(@apiRequests.length).toBe(1)
expect(@apiRequests[0].params).toEqual({limit:500; offset: 500})
describe "successfully, with fewer models than requested", ->
beforeEach ->
models = []
models.push(new Thread) for i in [0..100]
@request.requestOptions.success(models)
it "should not request another page", ->
@request.requestOptions.success([])
expect(@apiRequests.length).toBe(0)
it "should update the state to complete", ->
@request.requestOptions.success([])
expect(@state).toEqual({
"contacts": {busy: true}
"threads": {complete : true}
"calendars": {complete: true}
})
describe "successfully, with no models", ->
it "should not request another page", ->
@request.requestOptions.success([])
expect(@apiRequests.length).toBe(0)
it "should update the state to complete", ->
@request.requestOptions.success([])
expect(@state).toEqual({
"contacts": {busy: true}
"threads": {complete : true}
"calendars": {complete: true}
})
describe "with an error", ->
it "should log the error to the state", ->
err = new Error("Oh no a network error")
@request.requestOptions.error(err)
expect(@state).toEqual({
"contacts": {busy: true}
"threads": {busy: false, error: err.toString()}
"calendars": {complete: true}
})
it "should not request another page", ->
@request.requestOptions.error(new Error("Oh no a network error"))
expect(@apiRequests.length).toBe(0)
describe "cleanup", ->
it "should termiate the long polling connection", ->
spyOn(@connection, 'end')
@worker.cleanup()
expect(@connection.end).toHaveBeenCalled()