2017-09-07 07:19:48 +08:00
|
|
|
import React from 'react';
|
2017-09-27 03:03:04 +08:00
|
|
|
import ReactTestUtils from 'react-dom/test-utils';
|
2017-09-07 07:19:48 +08:00
|
|
|
import {
|
|
|
|
Thread,
|
|
|
|
Actions,
|
|
|
|
Contact,
|
|
|
|
Message,
|
|
|
|
DatabaseStore,
|
|
|
|
FocusedPerspectiveStore,
|
2017-09-27 02:42:18 +08:00
|
|
|
} from 'mailspring-exports';
|
2017-09-07 07:19:48 +08:00
|
|
|
import ActivityList from '../lib/activity-list';
|
|
|
|
import ActivityListStore from '../lib/activity-list-store';
|
|
|
|
import TestDataSource from '../lib/test-data-source';
|
|
|
|
|
2017-09-27 02:33:08 +08:00
|
|
|
const OPEN_TRACKING_ID = 'open-tracking-id';
|
|
|
|
const LINK_TRACKING_ID = 'link-tracking-id';
|
2017-09-07 07:19:48 +08:00
|
|
|
|
|
|
|
const messages = [
|
|
|
|
new Message({
|
|
|
|
id: 'a',
|
2017-09-27 02:33:08 +08:00
|
|
|
accountId: '0000000000000000000000000',
|
2017-09-07 07:19:48 +08:00
|
|
|
bcc: [],
|
|
|
|
cc: [],
|
2017-09-27 02:33:08 +08:00
|
|
|
snippet: 'Testing.',
|
|
|
|
subject: 'Open me!',
|
|
|
|
threadId: '0000000000000000000000000',
|
|
|
|
to: [
|
|
|
|
new Contact({
|
|
|
|
name: 'Jackie Luo',
|
|
|
|
email: 'jackie@nylas.com',
|
|
|
|
}),
|
|
|
|
],
|
2017-09-07 07:19:48 +08:00
|
|
|
}),
|
|
|
|
new Message({
|
|
|
|
id: 'b',
|
2017-09-27 02:33:08 +08:00
|
|
|
accountId: '0000000000000000000000000',
|
|
|
|
bcc: [
|
|
|
|
new Contact({
|
|
|
|
name: 'Ben Gotow',
|
|
|
|
email: 'ben@nylas.com',
|
|
|
|
}),
|
|
|
|
],
|
2017-09-07 07:19:48 +08:00
|
|
|
cc: [],
|
2017-09-27 02:33:08 +08:00
|
|
|
snippet: 'Hey! I am in town for the week...',
|
|
|
|
subject: 'Coffee?',
|
|
|
|
threadId: '0000000000000000000000000',
|
|
|
|
to: [
|
|
|
|
new Contact({
|
|
|
|
name: 'Jackie Luo',
|
|
|
|
email: 'jackie@nylas.com',
|
|
|
|
}),
|
|
|
|
],
|
2017-09-07 07:19:48 +08:00
|
|
|
}),
|
|
|
|
new Message({
|
|
|
|
id: 'c',
|
2017-09-27 02:33:08 +08:00
|
|
|
accountId: '0000000000000000000000000',
|
2017-09-07 07:19:48 +08:00
|
|
|
bcc: [],
|
2017-09-27 02:33:08 +08:00
|
|
|
cc: [
|
|
|
|
new Contact({
|
|
|
|
name: 'Evan Morikawa',
|
|
|
|
email: 'evan@nylas.com',
|
|
|
|
}),
|
|
|
|
],
|
2017-09-07 07:19:48 +08:00
|
|
|
snippet: "Here's the latest deals!",
|
2017-09-27 02:33:08 +08:00
|
|
|
subject: 'Newsletter',
|
|
|
|
threadId: '0000000000000000000000000',
|
|
|
|
to: [
|
|
|
|
new Contact({
|
|
|
|
name: 'Juan Tejada',
|
|
|
|
email: 'juan@nylas.com',
|
|
|
|
}),
|
|
|
|
],
|
2017-09-07 07:19:48 +08:00
|
|
|
}),
|
|
|
|
];
|
|
|
|
|
|
|
|
let pluginValue = {
|
|
|
|
open_count: 1,
|
2017-09-27 02:33:08 +08:00
|
|
|
open_data: [
|
|
|
|
{
|
|
|
|
timestamp: 1461361759.351055,
|
|
|
|
},
|
|
|
|
],
|
2017-09-07 07:19:48 +08:00
|
|
|
};
|
2017-09-26 13:35:25 +08:00
|
|
|
messages[0].directlyAttachMetadata(OPEN_TRACKING_ID, pluginValue);
|
2017-09-07 07:19:48 +08:00
|
|
|
pluginValue = {
|
2017-09-27 02:33:08 +08:00
|
|
|
links: [
|
|
|
|
{
|
|
|
|
click_count: 1,
|
|
|
|
click_data: [
|
|
|
|
{
|
|
|
|
timestamp: 1461349232.495837,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
],
|
2017-09-07 07:19:48 +08:00
|
|
|
tracked: true,
|
|
|
|
};
|
2017-09-26 13:35:25 +08:00
|
|
|
messages[0].directlyAttachMetadata(LINK_TRACKING_ID, pluginValue);
|
2017-09-07 07:19:48 +08:00
|
|
|
pluginValue = {
|
|
|
|
open_count: 1,
|
2017-09-27 02:33:08 +08:00
|
|
|
open_data: [
|
|
|
|
{
|
|
|
|
timestamp: 1461361763.28372,
|
|
|
|
},
|
|
|
|
],
|
2017-09-07 07:19:48 +08:00
|
|
|
};
|
2017-09-26 13:35:25 +08:00
|
|
|
messages[1].directlyAttachMetadata(OPEN_TRACKING_ID, pluginValue);
|
2017-09-07 07:19:48 +08:00
|
|
|
pluginValue = {
|
|
|
|
links: [],
|
|
|
|
tracked: false,
|
|
|
|
};
|
2017-09-26 13:35:25 +08:00
|
|
|
messages[1].directlyAttachMetadata(LINK_TRACKING_ID, pluginValue);
|
2017-09-07 07:19:48 +08:00
|
|
|
pluginValue = {
|
|
|
|
open_count: 0,
|
|
|
|
open_data: [],
|
|
|
|
};
|
2017-09-26 13:35:25 +08:00
|
|
|
messages[2].directlyAttachMetadata(OPEN_TRACKING_ID, pluginValue);
|
2017-09-07 07:19:48 +08:00
|
|
|
pluginValue = {
|
2017-09-27 02:33:08 +08:00
|
|
|
links: [
|
|
|
|
{
|
|
|
|
click_count: 0,
|
|
|
|
click_data: [],
|
|
|
|
},
|
|
|
|
],
|
2017-09-07 07:19:48 +08:00
|
|
|
tracked: true,
|
|
|
|
};
|
2017-09-26 13:35:25 +08:00
|
|
|
messages[2].directlyAttachMetadata(LINK_TRACKING_ID, pluginValue);
|
2017-09-07 07:19:48 +08:00
|
|
|
|
|
|
|
describe('ActivityList', function activityList() {
|
|
|
|
beforeEach(() => {
|
|
|
|
this.testSource = new TestDataSource();
|
2017-09-27 02:36:58 +08:00
|
|
|
spyOn(AppEnv.packages, 'pluginIdFor').andCallFake(pluginName => {
|
2017-09-07 07:19:48 +08:00
|
|
|
if (pluginName === 'open-tracking') {
|
2017-09-27 02:33:08 +08:00
|
|
|
return OPEN_TRACKING_ID;
|
2017-09-07 07:19:48 +08:00
|
|
|
}
|
|
|
|
if (pluginName === 'link-tracking') {
|
2017-09-27 02:33:08 +08:00
|
|
|
return LINK_TRACKING_ID;
|
2017-09-07 07:19:48 +08:00
|
|
|
}
|
2017-09-27 02:33:08 +08:00
|
|
|
return null;
|
|
|
|
});
|
|
|
|
spyOn(ActivityListStore, '_dataSource').andReturn(this.testSource);
|
|
|
|
spyOn(FocusedPerspectiveStore, 'sidebarAccountIds').andReturn(['0000000000000000000000000']);
|
|
|
|
spyOn(DatabaseStore, 'run').andCallFake(query => {
|
2017-09-07 07:19:48 +08:00
|
|
|
if (query._klass === Thread) {
|
|
|
|
const thread = new Thread({
|
2017-09-27 02:33:08 +08:00
|
|
|
id: '0000000000000000000000000',
|
2017-09-07 07:19:48 +08:00
|
|
|
accountId: TEST_ACCOUNT_ID,
|
|
|
|
});
|
|
|
|
return Promise.resolve(thread);
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
});
|
2017-09-27 02:33:08 +08:00
|
|
|
spyOn(ActivityListStore, 'focusThread').andCallThrough();
|
2017-09-27 02:36:58 +08:00
|
|
|
spyOn(AppEnv, 'displayWindow');
|
2017-09-27 02:33:08 +08:00
|
|
|
spyOn(Actions, 'closePopover');
|
|
|
|
spyOn(Actions, 'setFocus');
|
|
|
|
spyOn(Actions, 'ensureCategoryIsFocused');
|
2017-09-07 07:19:48 +08:00
|
|
|
ActivityListStore.activate();
|
|
|
|
this.component = ReactTestUtils.renderIntoDocument(<ActivityList />);
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('when no actions are found', () => {
|
|
|
|
it('should show empty state', () => {
|
2017-09-27 02:33:08 +08:00
|
|
|
const items = ReactTestUtils.scryRenderedDOMComponentsWithClass(
|
|
|
|
this.component,
|
|
|
|
'activity-list-item'
|
|
|
|
);
|
2017-09-07 07:19:48 +08:00
|
|
|
expect(items.length).toBe(0);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('when actions are found', () => {
|
|
|
|
it('should show activity list items', () => {
|
|
|
|
this.testSource.manuallyTrigger(messages);
|
|
|
|
waitsFor(() => {
|
2017-09-27 02:33:08 +08:00
|
|
|
const items = ReactTestUtils.scryRenderedDOMComponentsWithClass(
|
|
|
|
this.component,
|
|
|
|
'activity-list-item'
|
|
|
|
);
|
2017-09-07 07:19:48 +08:00
|
|
|
return items.length > 0;
|
|
|
|
});
|
|
|
|
runs(() => {
|
2017-09-27 02:33:08 +08:00
|
|
|
expect(
|
|
|
|
ReactTestUtils.scryRenderedDOMComponentsWithClass(this.component, 'activity-list-item')
|
|
|
|
.length
|
|
|
|
).toBe(3);
|
2017-09-07 07:19:48 +08:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should show the correct items', () => {
|
|
|
|
this.testSource.manuallyTrigger(messages);
|
|
|
|
waitsFor(() => {
|
2017-09-27 02:33:08 +08:00
|
|
|
const items = ReactTestUtils.scryRenderedDOMComponentsWithClass(
|
|
|
|
this.component,
|
|
|
|
'activity-list-item'
|
|
|
|
);
|
2017-09-07 07:19:48 +08:00
|
|
|
return items.length > 0;
|
|
|
|
});
|
|
|
|
runs(() => {
|
2017-09-27 02:33:08 +08:00
|
|
|
expect(
|
|
|
|
ReactTestUtils.scryRenderedDOMComponentsWithClass(this.component, 'activity-list-item')[0]
|
|
|
|
.textContent
|
|
|
|
).toBe('Someone opened:Apr 22 2016Coffee?');
|
|
|
|
expect(
|
|
|
|
ReactTestUtils.scryRenderedDOMComponentsWithClass(this.component, 'activity-list-item')[1]
|
|
|
|
.textContent
|
|
|
|
).toBe('Jackie Luo opened:Apr 22 2016Open me!');
|
|
|
|
expect(
|
|
|
|
ReactTestUtils.scryRenderedDOMComponentsWithClass(this.component, 'activity-list-item')[2]
|
|
|
|
.textContent
|
|
|
|
).toBe('Jackie Luo clicked:Apr 22 2016(No Subject)');
|
2017-09-07 07:19:48 +08:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
xit('should focus the thread', () => {
|
|
|
|
runs(() => {
|
|
|
|
return this.testSource.manuallyTrigger(messages);
|
2017-09-27 02:33:08 +08:00
|
|
|
});
|
2017-09-07 07:19:48 +08:00
|
|
|
waitsFor(() => {
|
2017-09-27 02:33:08 +08:00
|
|
|
const items = ReactTestUtils.scryRenderedDOMComponentsWithClass(
|
|
|
|
this.component,
|
|
|
|
'activity-list-item'
|
|
|
|
);
|
2017-09-07 07:19:48 +08:00
|
|
|
return items.length > 0;
|
|
|
|
});
|
|
|
|
runs(() => {
|
2017-09-27 02:33:08 +08:00
|
|
|
const item = ReactTestUtils.scryRenderedDOMComponentsWithClass(
|
|
|
|
this.component,
|
|
|
|
'activity-list-item'
|
|
|
|
)[0];
|
2017-09-07 07:19:48 +08:00
|
|
|
ReactTestUtils.Simulate.click(item);
|
|
|
|
});
|
|
|
|
waitsFor(() => {
|
|
|
|
return ActivityListStore.focusThread.calls.length > 0;
|
|
|
|
});
|
|
|
|
runs(() => {
|
2017-09-27 02:36:58 +08:00
|
|
|
expect(AppEnv.displayWindow.calls.length).toBe(1);
|
2017-09-07 07:19:48 +08:00
|
|
|
expect(Actions.closePopover.calls.length).toBe(1);
|
|
|
|
expect(Actions.setFocus.calls.length).toBe(1);
|
|
|
|
expect(Actions.ensureCategoryIsFocused.calls.length).toBe(1);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|