Mailspring/app/internal_packages/activity-list/specs/activity-list-spec.jsx

245 lines
6.4 KiB
React
Raw Normal View History

import React from 'react';
import ReactTestUtils from 'react-addons-test-utils';
import {
Thread,
Actions,
Contact,
Message,
DatabaseStore,
FocusedPerspectiveStore,
} from 'mailspring-exports';
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';
const messages = [
new Message({
id: 'a',
2017-09-27 02:33:08 +08:00
accountId: '0000000000000000000000000',
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',
}),
],
}),
new Message({
id: 'b',
2017-09-27 02:33:08 +08:00
accountId: '0000000000000000000000000',
bcc: [
new Contact({
name: 'Ben Gotow',
email: 'ben@nylas.com',
}),
],
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',
}),
],
}),
new Message({
id: 'c',
2017-09-27 02:33:08 +08:00
accountId: '0000000000000000000000000',
bcc: [],
2017-09-27 02:33:08 +08:00
cc: [
new Contact({
name: 'Evan Morikawa',
email: 'evan@nylas.com',
}),
],
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',
}),
],
}),
];
let pluginValue = {
open_count: 1,
2017-09-27 02:33:08 +08:00
open_data: [
{
timestamp: 1461361759.351055,
},
],
};
messages[0].directlyAttachMetadata(OPEN_TRACKING_ID, pluginValue);
pluginValue = {
2017-09-27 02:33:08 +08:00
links: [
{
click_count: 1,
click_data: [
{
timestamp: 1461349232.495837,
},
],
},
],
tracked: true,
};
messages[0].directlyAttachMetadata(LINK_TRACKING_ID, pluginValue);
pluginValue = {
open_count: 1,
2017-09-27 02:33:08 +08:00
open_data: [
{
timestamp: 1461361763.28372,
},
],
};
messages[1].directlyAttachMetadata(OPEN_TRACKING_ID, pluginValue);
pluginValue = {
links: [],
tracked: false,
};
messages[1].directlyAttachMetadata(LINK_TRACKING_ID, pluginValue);
pluginValue = {
open_count: 0,
open_data: [],
};
messages[2].directlyAttachMetadata(OPEN_TRACKING_ID, pluginValue);
pluginValue = {
2017-09-27 02:33:08 +08:00
links: [
{
click_count: 0,
click_data: [],
},
],
tracked: true,
};
messages[2].directlyAttachMetadata(LINK_TRACKING_ID, pluginValue);
describe('ActivityList', function activityList() {
beforeEach(() => {
this.testSource = new TestDataSource();
2017-09-27 02:36:58 +08:00
spyOn(AppEnv.packages, 'pluginIdFor').andCallFake(pluginName => {
if (pluginName === 'open-tracking') {
2017-09-27 02:33:08 +08:00
return OPEN_TRACKING_ID;
}
if (pluginName === 'link-tracking') {
2017-09-27 02:33:08 +08:00
return LINK_TRACKING_ID;
}
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 => {
if (query._klass === Thread) {
const thread = new Thread({
2017-09-27 02:33:08 +08:00
id: '0000000000000000000000000',
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');
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'
);
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'
);
return items.length > 0;
});
runs(() => {
2017-09-27 02:33:08 +08:00
expect(
ReactTestUtils.scryRenderedDOMComponentsWithClass(this.component, 'activity-list-item')
.length
).toBe(3);
});
});
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'
);
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)');
});
});
xit('should focus the thread', () => {
runs(() => {
return this.testSource.manuallyTrigger(messages);
2017-09-27 02:33:08 +08:00
});
waitsFor(() => {
2017-09-27 02:33:08 +08:00
const items = ReactTestUtils.scryRenderedDOMComponentsWithClass(
this.component,
'activity-list-item'
);
return items.length > 0;
});
runs(() => {
2017-09-27 02:33:08 +08:00
const item = ReactTestUtils.scryRenderedDOMComponentsWithClass(
this.component,
'activity-list-item'
)[0];
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);
expect(Actions.closePopover.calls.length).toBe(1);
expect(Actions.setFocus.calls.length).toBe(1);
expect(Actions.ensureCategoryIsFocused.calls.length).toBe(1);
});
});
});
});