mirror of
https://github.com/Foundry376/Mailspring.git
synced 2024-11-12 04:25:31 +08:00
886328ff7a
Great breakdown of React changes here: https://github.com/facebook/react/blob/master/CHANGELOG.md#0140-october-7-2015 Due to deprecation warnings, I don't think this will break third-party extensions unless they were doing really bad things.
71 lines
2.6 KiB
JavaScript
71 lines
2.6 KiB
JavaScript
import React from 'react';
|
|
import ReactDOM from 'react-dom';
|
|
import {findRenderedDOMComponentWithClass} from 'react-addons-test-utils';
|
|
|
|
import {Message} from 'nylas-exports'
|
|
import {renderIntoDocument} from '../../../spec/nylas-test-utils'
|
|
import OpenTrackingIcon from '../lib/open-tracking-icon'
|
|
import {PLUGIN_ID} from '../lib/open-tracking-constants'
|
|
|
|
|
|
function makeIcon(thread, props = {}) {
|
|
return renderIntoDocument(<OpenTrackingIcon {...props} thread={thread} />);
|
|
}
|
|
|
|
function find(component, className) {
|
|
return ReactDOM.findDOMNode(findRenderedDOMComponentWithClass(component, className))
|
|
}
|
|
|
|
function addOpenMetadata(obj, openCount) {
|
|
obj.applyPluginMetadata(PLUGIN_ID, {open_count: openCount});
|
|
}
|
|
|
|
describe("Open tracking icon", () => {
|
|
beforeEach(() => {
|
|
this.thread = {metadata: []};
|
|
});
|
|
|
|
|
|
it("shows no icon if the thread has no messages", () => {
|
|
const icon = find(makeIcon(this.thread), "open-tracking-icon");
|
|
expect(icon.children.length).toEqual(0);
|
|
});
|
|
|
|
it("shows no icon if the thread messages have no metadata", () => {
|
|
this.thread.metadata.push(new Message());
|
|
this.thread.metadata.push(new Message());
|
|
const icon = find(makeIcon(this.thread), "open-tracking-icon");
|
|
expect(icon.children.length).toEqual(0);
|
|
});
|
|
|
|
describe("With messages and metadata", () => {
|
|
beforeEach(() => {
|
|
this.messages = [new Message(), new Message(), new Message({draft: true})];
|
|
this.thread.metadata.push(...this.messages);
|
|
});
|
|
|
|
it("shows no icon if metadata is malformed", () => {
|
|
this.messages[0].applyPluginMetadata(PLUGIN_ID, {gar: "bage"});
|
|
const icon = find(makeIcon(this.thread), "open-tracking-icon");
|
|
expect(icon.children.length).toEqual(0);
|
|
});
|
|
|
|
it("shows an unopened icon if last non draft message has metadata and is unopened", () => {
|
|
addOpenMetadata(this.messages[0], 1);
|
|
addOpenMetadata(this.messages[1], 0);
|
|
const icon = find(makeIcon(this.thread), "open-tracking-icon");
|
|
expect(icon.children.length).toEqual(1);
|
|
expect(icon.querySelector("img.unopened")).not.toBeNull();
|
|
expect(icon.querySelector("img.opened")).toBeNull();
|
|
});
|
|
|
|
it("shows an opened icon if last non draft message with metadata is opened", () => {
|
|
addOpenMetadata(this.messages[0], 0);
|
|
addOpenMetadata(this.messages[1], 1);
|
|
const icon = find(makeIcon(this.thread), "open-tracking-icon");
|
|
expect(icon.children.length).toEqual(1);
|
|
expect(icon.querySelector("img.unopened")).toBeNull();
|
|
expect(icon.querySelector("img.opened")).not.toBeNull();
|
|
});
|
|
});
|
|
});
|