Mailspring/internal_packages/thread-list/spec/thread-list-participants-spec.cjsx
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

195 lines
7.4 KiB
CoffeeScript

React = require "react/addons"
ReactTestUtils = React.addons.TestUtils
_ = require 'underscore-plus'
{NamespaceStore, Thread, Contact, Message} = require 'inbox-exports'
ThreadListParticipants = require '../lib/thread-list-participants'
describe "ThreadListParticipants", ->
it "renders into the document", ->
@participants = ReactTestUtils.renderIntoDocument(
<ThreadListParticipants thread={new Thread}/>
)
expect(ReactTestUtils.isCompositeComponentWithType(@participants, ThreadListParticipants)).toBe true
it "renders unread contacts with .unread-true", ->
ben = new Contact(email: 'ben@nilas.com', name: 'ben')
ben.unread = true
thread = new Thread()
thread.metadata = [new Message(from: [ben], unread:true)]
@participants = ReactTestUtils.renderIntoDocument(
<ThreadListParticipants thread={thread}/>
)
unread = ReactTestUtils.scryRenderedDOMComponentsWithClass(@participants, 'unread-true')
expect(unread.length).toBe(1)
describe "getParticipants", ->
beforeEach ->
@ben = new Contact(email: 'ben@nilas.com', name: 'ben')
@evan = new Contact(email: 'evan@nilas.com', name: 'evan')
@evanAgain = new Contact(email: 'evan@nilas.com', name: 'evan')
@michael = new Contact(email: 'michael@nilas.com', name: 'michael')
@kavya = new Contact(email: 'kavya@nilas.com', name: 'kavya')
describe "when thread.messages is available", ->
it "correctly produces items for display in a wide range of scenarios", ->
scenarios = [{
name: 'single read email'
in: [
new Message(unread: false, from: [@ben]),
]
out: [{contact: @ben, unread: false}]
},{
name: 'single unread email'
in: [
new Message(unread: true, from: [@evan]),
]
out: [{contact: @evan, unread: true}]
},{
name: 'single unread response'
in: [
new Message(unread: false, from: [@ben]),
new Message(unread: true, from: [@evan]),
]
out: [{contact: @ben, unread: false}, {contact: @evan, unread: true}]
},{
name: 'two unread responses'
in: [
new Message(unread: false, from: [@ben]),
new Message(unread: true, from: [@evan]),
new Message(unread: true, from: [@kavya]),
]
out: [{contact: @ben, unread: false},
{contact: @evan, unread: true},
{contact: @kavya, unread: true}]
},{
name: 'two unread responses (repeated participants)'
in: [
new Message(unread: false, from: [@ben]),
new Message(unread: true, from: [@evan]),
new Message(unread: true, from: [@evanAgain]),
]
out: [{contact: @ben, unread: false}, {contact: @evan, unread: true}]
},{
name: 'three unread responses (repeated participants)'
in: [
new Message(unread: false, from: [@ben]),
new Message(unread: true, from: [@evan]),
new Message(unread: true, from: [@michael]),
new Message(unread: true, from: [@evanAgain]),
]
out: [{contact: @ben, unread: false},
{spacer: true},
{contact: @michael, unread: true},
{contact: @evanAgain, unread: true}]
},{
name: 'three unread responses'
in: [
new Message(unread: false, from: [@ben]),
new Message(unread: true, from: [@evan]),
new Message(unread: true, from: [@michael]),
new Message(unread: true, from: [@kavya]),
]
out: [{contact: @ben, unread: false},
{spacer: true},
{contact: @michael, unread: true},
{contact: @kavya, unread: true}]
},{
name: 'three unread responses to long thread'
in: [
new Message(unread: false, from: [@ben]),
new Message(unread: false, from: [@evan]),
new Message(unread: false, from: [@michael]),
new Message(unread: false, from: [@ben]),
new Message(unread: true, from: [@evanAgain]),
new Message(unread: true, from: [@michael]),
new Message(unread: true, from: [@evanAgain]),
]
out: [{contact: @ben, unread: false},
{spacer: true},
{contact: @michael, unread: true},
{contact: @evanAgain, unread: true}]
},{
name: 'single unread responses to long thread'
in: [
new Message(unread: false, from: [@ben]),
new Message(unread: false, from: [@evan]),
new Message(unread: false, from: [@michael]),
new Message(unread: false, from: [@ben]),
new Message(unread: true, from: [@evanAgain]),
]
out: [{contact: @ben, unread: false},
{spacer: true},
{contact: @ben, unread: false},
{contact: @evanAgain, unread: true}]
},{
name: 'long read thread'
in: [
new Message(unread: false, from: [@ben]),
new Message(unread: false, from: [@evan]),
new Message(unread: false, from: [@michael]),
new Message(unread: false, from: [@ben]),
]
out: [{contact: @ben, unread: false},
{spacer: true},
{contact: @michael, unread: false},
{contact: @ben, unread: false}]
}]
for scenario in scenarios
thread = new Thread()
thread.metadata = scenario.in
participants = ReactTestUtils.renderIntoDocument(
<ThreadListParticipants thread={thread}/>
)
expect(participants.getParticipants()).toEqual(scenario.out)
# Slightly misuse jasmine to get the output we want to show
if (!_.isEqual(participants.getParticipants(), scenario.out))
expect(scenario.name).toBe('correct')
describe "when thread.messages is not available", ->
it "correctly produces items for display in a wide range of scenarios", ->
me = NamespaceStore.current().me()
scenarios = [{
name: 'one participant'
in: [@ben]
out: [{contact: @ben, unread: false}]
},{
name: 'one participant (me)'
in: [me]
out: [{contact: me, unread: false}]
},{
name: 'two participants'
in: [@evan, @ben]
out: [{contact: @evan, unread: false}, {contact: @ben, unread: false}]
},{
name: 'two participants (me)'
in: [@ben, me]
out: [{contact: @ben, unread: false}]
},{
name: 'lots of participants'
in: [@ben, @evan, @michael, @kavya]
out: [{contact: @ben, unread: false},
{spacer: true},
{contact: @michael, unread: false},
{contact: @kavya, unread: false}]
}]
for scenario in scenarios
thread = new Thread()
thread.participants = scenario.in
participants = ReactTestUtils.renderIntoDocument(
<ThreadListParticipants thread={thread}/>
)
expect(participants.getParticipants()).toEqual(scenario.out)
# Slightly misuse jasmine to get the output we want to show
if (!_.isEqual(participants.getParticipants(), scenario.out))
expect(scenario.name).toBe('correct')