2015-03-26 03:41:48 +08:00
|
|
|
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()
|
2015-04-07 02:46:20 +08:00
|
|
|
thread.metadata = [new Message(from: [ben], unread:true)]
|
2015-03-26 03:41:48 +08:00
|
|
|
|
|
|
|
@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')
|
|
|
|
|
2015-03-26 04:01:22 +08:00
|
|
|
describe "when thread.messages is available", ->
|
2015-03-26 03:41:48 +08:00
|
|
|
it "correctly produces items for display in a wide range of scenarios", ->
|
|
|
|
scenarios = [{
|
|
|
|
name: 'single read email'
|
|
|
|
in: [
|
|
|
|
new Message(unread: false, from: [@ben]),
|
|
|
|
]
|
2015-03-31 02:21:23 +08:00
|
|
|
out: [{contact: @ben, unread: false}]
|
2015-03-26 03:41:48 +08:00
|
|
|
},{
|
|
|
|
name: 'single unread email'
|
|
|
|
in: [
|
|
|
|
new Message(unread: true, from: [@evan]),
|
|
|
|
]
|
2015-03-31 02:21:23 +08:00
|
|
|
out: [{contact: @evan, unread: true}]
|
2015-03-26 03:41:48 +08:00
|
|
|
},{
|
|
|
|
name: 'single unread response'
|
|
|
|
in: [
|
|
|
|
new Message(unread: false, from: [@ben]),
|
|
|
|
new Message(unread: true, from: [@evan]),
|
|
|
|
]
|
2015-03-31 02:21:23 +08:00
|
|
|
out: [{contact: @ben, unread: false}, {contact: @evan, unread: true}]
|
2015-03-26 03:41:48 +08:00
|
|
|
},{
|
|
|
|
name: 'two unread responses'
|
|
|
|
in: [
|
|
|
|
new Message(unread: false, from: [@ben]),
|
|
|
|
new Message(unread: true, from: [@evan]),
|
|
|
|
new Message(unread: true, from: [@kavya]),
|
|
|
|
]
|
2015-03-31 02:21:23 +08:00
|
|
|
out: [{contact: @ben, unread: false},
|
|
|
|
{contact: @evan, unread: true},
|
|
|
|
{contact: @kavya, unread: true}]
|
2015-03-26 03:41:48 +08:00
|
|
|
},{
|
|
|
|
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]),
|
|
|
|
]
|
2015-03-31 02:21:23 +08:00
|
|
|
out: [{contact: @ben, unread: false}, {contact: @evan, unread: true}]
|
2015-03-26 03:41:48 +08:00
|
|
|
},{
|
|
|
|
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]),
|
|
|
|
]
|
2015-03-31 02:21:23 +08:00
|
|
|
out: [{contact: @ben, unread: false},
|
|
|
|
{spacer: true},
|
|
|
|
{contact: @michael, unread: true},
|
|
|
|
{contact: @evanAgain, unread: true}]
|
2015-03-26 03:41:48 +08:00
|
|
|
},{
|
|
|
|
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]),
|
|
|
|
]
|
2015-03-31 02:21:23 +08:00
|
|
|
out: [{contact: @ben, unread: false},
|
|
|
|
{spacer: true},
|
|
|
|
{contact: @michael, unread: true},
|
|
|
|
{contact: @kavya, unread: true}]
|
2015-03-26 03:41:48 +08:00
|
|
|
},{
|
|
|
|
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]),
|
|
|
|
]
|
2015-03-31 02:21:23 +08:00
|
|
|
out: [{contact: @ben, unread: false},
|
|
|
|
{spacer: true},
|
|
|
|
{contact: @michael, unread: true},
|
|
|
|
{contact: @evanAgain, unread: true}]
|
2015-03-26 03:41:48 +08:00
|
|
|
},{
|
|
|
|
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]),
|
|
|
|
]
|
2015-03-31 02:21:23 +08:00
|
|
|
out: [{contact: @ben, unread: false},
|
|
|
|
{spacer: true},
|
|
|
|
{contact: @ben, unread: false},
|
|
|
|
{contact: @evanAgain, unread: true}]
|
2015-03-26 03:41:48 +08:00
|
|
|
},{
|
|
|
|
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]),
|
|
|
|
]
|
2015-03-31 02:21:23 +08:00
|
|
|
out: [{contact: @ben, unread: false},
|
|
|
|
{spacer: true},
|
|
|
|
{contact: @michael, unread: false},
|
|
|
|
{contact: @ben, unread: false}]
|
2015-03-26 03:41:48 +08:00
|
|
|
}]
|
|
|
|
|
|
|
|
for scenario in scenarios
|
|
|
|
thread = new Thread()
|
2015-04-07 02:46:20 +08:00
|
|
|
thread.metadata = scenario.in
|
2015-03-26 03:41:48 +08:00
|
|
|
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]
|
2015-03-31 02:21:23 +08:00
|
|
|
out: [{contact: @ben, unread: false}]
|
2015-03-26 03:41:48 +08:00
|
|
|
},{
|
|
|
|
name: 'one participant (me)'
|
|
|
|
in: [me]
|
2015-03-31 02:21:23 +08:00
|
|
|
out: [{contact: me, unread: false}]
|
2015-03-26 03:41:48 +08:00
|
|
|
},{
|
|
|
|
name: 'two participants'
|
|
|
|
in: [@evan, @ben]
|
2015-03-31 02:21:23 +08:00
|
|
|
out: [{contact: @evan, unread: false}, {contact: @ben, unread: false}]
|
2015-03-26 03:41:48 +08:00
|
|
|
},{
|
|
|
|
name: 'two participants (me)'
|
|
|
|
in: [@ben, me]
|
2015-03-31 02:21:23 +08:00
|
|
|
out: [{contact: @ben, unread: false}]
|
2015-03-26 03:41:48 +08:00
|
|
|
},{
|
|
|
|
name: 'lots of participants'
|
|
|
|
in: [@ben, @evan, @michael, @kavya]
|
2015-03-31 02:21:23 +08:00
|
|
|
out: [{contact: @ben, unread: false},
|
|
|
|
{spacer: true},
|
|
|
|
{contact: @michael, unread: false},
|
|
|
|
{contact: @kavya, unread: false}]
|
2015-03-26 03:41:48 +08:00
|
|
|
}]
|
|
|
|
|
|
|
|
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))
|
2015-03-26 04:01:22 +08:00
|
|
|
expect(scenario.name).toBe('correct')
|