Mailspring/app/spec/components/participants-text-field-spec.tsx
Ben Gotow c629967c3d Add a proper address book with CardDAV + Google People support
commit 423cf4f407
Author: Ben Gotow <ben@foundry376.com>
Date:   Fri Oct 11 22:33:53 2019 -0500

    Replace belcard with homegrown VCard parser because our needs are minimal and the linux binary has relocation issues

commit 4ae19c0ed5
Author: Ben Gotow <ben@foundry376.com>
Date:   Fri Oct 11 10:38:26 2019 -0500

    Skip building a few more belr components, still looking for relocation error cause

commit a7ec02a449
Author: Ben Gotow <ben@foundry376.com>
Date:   Thu Oct 10 22:16:15 2019 -0500

    Fix windows SRV record lookups for contact directory autodiscovery

commit 318a31d279
Author: Ben Gotow <ben@foundry376.com>
Date:   Thu Oct 10 20:50:06 2019 -0500

    Leave vcard_grammar unpacked so mailsync can find it at runtime

commit bf7e43e37d
Author: Ben Gotow <ben@foundry376.com>
Date:   Thu Oct 10 20:43:01 2019 -0500

    Fix bug in icon case sensitivity

commit c283513653
Author: Ben Gotow <ben@foundry376.com>
Date:   Thu Oct 10 17:29:24 2019 -0500

    Renew Windows Authenticode code signing cert (there goes $500…)

commit d13235f65b
Author: Ben Gotow <ben@foundry376.com>
Date:   Wed Oct 9 23:25:34 2019 -0500

    Bump mailsync to move belr dlls

commit 00ca6431df
Author: Ben Gotow <ben@foundry376.com>
Date:   Wed Oct 9 23:22:53 2019 -0500

    Bump to xcode9 to fix odd C++11 error

commit 47903c99c4
Author: Ben Gotow <ben@foundry376.com>
Date:   Wed Oct 9 23:01:32 2019 -0500

    Bump mailsync to build belr as a dll instead of a static lib

commit 21d645d4e7
Author: Ben Gotow <ben@foundry376.com>
Date:   Wed Oct 9 22:38:24 2019 -0500

    Bump mailsync

commit 3f943031cb
Author: Ben Gotow <ben@foundry376.com>
Date:   Wed Oct 9 21:57:39 2019 -0500

    Bump mailsync to fix windows libetpan failure

commit 8fb55ca0fc
Author: Ben Gotow <ben@foundry376.com>
Date:   Wed Oct 9 21:36:57 2019 -0500

    Bump mailsync, add grammar

commit b959c54e50
Author: Ben Gotow <ben@foundry376.com>
Date:   Wed Oct 9 21:20:13 2019 -0500

    Bump mailsync for linux / win32

commit ddb5229d67
Author: Ben Gotow <ben@foundry376.com>
Date:   Tue Oct 8 22:44:12 2019 -0500

    Bump mailsync

commit f80e1bc422
Author: Ben Gotow <ben@foundry376.com>
Date:   Tue Oct 8 11:11:39 2019 -0500

    Fix LESS linter failures

commit 66dc60a731
Author: Ben Gotow <ben@foundry376.com>
Date:   Tue Oct 8 11:00:37 2019 -0500

    Extend participant search to return / expand groups

commit 3bded91307
Author: Ben Gotow <ben@foundry376.com>
Date:   Tue Oct 8 03:18:11 2019 -0500

    Add comments, etc

commit 4ede5446de
Author: Ben Gotow <ben@foundry376.com>
Date:   Tue Oct 8 02:38:50 2019 -0500

    Google People API contacts CRUD alongside CardDav

commit 96c6a64e46
Author: Ben Gotow <ben@foundry376.com>
Date:   Mon Oct 7 14:00:34 2019 -0500

    Build ContactBook concept to track which accounts have sync running

commit 1f6aab1083
Author: Ben Gotow <ben@foundry376.com>
Date:   Mon Oct 7 11:38:03 2019 -0500

    Contact and contact group CRUD, address book menus

commit b877c58d48
Author: Ben Gotow <ben@foundry376.com>
Date:   Sun Oct 6 16:32:33 2019 -0500

    Editing contact names working

commit 761079304c
Author: Ben Gotow <ben@foundry376.com>
Date:   Mon Sep 30 15:42:59 2019 -0500

    Improved styling of YYYYMMDD field

commit 71a567276b
Author: Ben Gotow <ben@foundry376.com>
Date:   Mon Sep 30 15:06:28 2019 -0500

    UI for edit + move + delete contacts

commit f1967dd603
Author: Ben Gotow <ben@foundry376.com>
Date:   Thu Sep 26 13:50:44 2019 -0500

    Allow you to turn on / off the “Found in Mail” autocompletions

commit 0c2b0eb03b
Author: Ben Gotow <ben@foundry376.com>
Date:   Thu Sep 26 13:50:14 2019 -0500

    Improve contacts window launch perf by lazy loading composer support, scanning less of fs for themes

commit 07abd6cb71
Author: Ben Gotow <ben@foundry376.com>
Date:   Thu Sep 26 04:36:10 2019 -0500

    Support for CardDav contact display, better groups presentation

commit 0a9e166d79
Author: Ben Gotow <ben@foundry376.com>
Date:   Tue Sep 24 12:42:37 2019 -0500

    Add hidden attribute to the model in prep for deletion of auto-created contacts

commit e6ce3b2af9
Author: Ben Gotow <ben@foundry376.com>
Date:   Tue Sep 24 12:12:52 2019 -0500

    Initial pass at address book

commit 740d7e8655
Author: Ben Gotow <ben@foundry376.com>
Date:   Tue Sep 24 08:27:06 2019 -0500

    Make headers of Preferences > Accounts consistent with General
2019-10-12 12:40:57 -05:00

210 lines
6.8 KiB
TypeScript

import React from 'react';
import { mount } from 'enzyme';
import { ContactStore, Contact } from 'mailspring-exports';
import { ParticipantsTextField } from 'mailspring-component-kit';
const participant1 = new Contact({
id: 'local-1',
email: 'ben@mailspring.com',
});
const participant2 = new Contact({
id: 'local-2',
email: 'ben@example.com',
name: 'Ben Gotow',
});
const participant3 = new Contact({
id: 'local-3',
email: 'evan@mailspring.com',
name: 'Evan Morikawa',
});
xdescribe('ParticipantsTextField', function ParticipantsTextFieldSpecs() {
beforeEach(() => {
spyOn(AppEnv, 'isMainWindow').andReturn(true);
this.propChange = jasmine.createSpy('change');
this.fieldName = 'to';
this.participants = {
to: [participant1, participant2],
cc: [participant3],
bcc: [],
};
this.renderedField = mount(
<ParticipantsTextField
field={this.fieldName}
label={this.fieldName}
visible
participants={this.participants}
draft={{ id: 'draft-1' }}
session={{}}
change={this.propChange}
/>
);
this.renderedInput = this.renderedField.find('input');
this.expectInputToYield = (input, expected) => {
const reviver = function reviver(k, v) {
if (k === 'id' || k === 'client_id' || k === 'server_id' || k === 'object') {
return undefined;
}
return v;
};
runs(() => {
this.renderedInput.simulate('change', { target: { value: input } });
advanceClock(100);
return this.renderedInput.simulate('keyDown', { key: 'Enter', keyCode: 9 });
});
waitsFor(() => {
return this.propChange.calls.length > 0;
});
runs(() => {
let found = this.propChange.mostRecentCall.args[0];
found = JSON.parse(JSON.stringify(found), reviver);
expect(found).toEqual(JSON.parse(JSON.stringify(expected), reviver));
// This advance clock needs to be here because our waitsFor latch
// catches the first time that propChange gets called. More stuff
// may happen after this and we need to advance the clock to
// "clear" all of that. If we don't do this it throws errors about
// `setState` being called on unmounted components :(
return advanceClock(100);
});
};
});
it('renders into the document', () => {
expect(this.renderedField.find(ParticipantsTextField).length).toBe(1);
});
describe('inserting participant text', () => {
it('should fire onChange with an updated participants hash', () => {
this.expectInputToYield('abc@abc.com', {
to: [
participant1,
participant2,
new Contact({ name: 'abc@abc.com', email: 'abc@abc.com' }),
],
cc: [participant3],
bcc: [],
});
});
it('should remove added participants from other fields', () => {
this.expectInputToYield(participant3.email, {
to: [
participant1,
participant2,
new Contact({ name: participant3.email, email: participant3.email }),
],
cc: [],
bcc: [],
});
});
it('should use the name of an existing contact in the ContactStore if possible', () => {
spyOn(ContactStore, 'searchContacts').andCallFake(val => {
if (val === participant3.name) {
return Promise.resolve([participant3]);
}
return Promise.resolve([]);
});
this.expectInputToYield(participant3.name, {
to: [participant1, participant2, participant3],
cc: [],
bcc: [],
});
});
it("should use the plain email if that's what's entered", () => {
spyOn(ContactStore, 'searchContacts').andCallFake(val => {
if (val === participant3.name) {
return Promise.resolve([participant3]);
}
return Promise.resolve([]);
});
this.expectInputToYield(participant3.email, {
to: [participant1, participant2, new Contact({ email: 'evan@mailspring.com' })],
cc: [],
bcc: [],
});
});
it('should not have the same contact auto-picked multiple times', () => {
spyOn(ContactStore, 'searchContacts').andCallFake(val => {
if (val === participant2.name) {
return Promise.resolve([participant2]);
}
return Promise.resolve([]);
});
this.expectInputToYield(participant2.name, {
to: [
participant1,
participant2,
new Contact({ email: participant2.name, name: participant2.name }),
],
cc: [participant3],
bcc: [],
});
});
describe('when text contains Name (Email) formatted data', () => {
it('should correctly parse it into named Contact objects', () => {
const newContact1 = new Contact({
id: 'b1',
name: 'Ben Imposter',
email: 'imposter@mailspring.com',
});
const newContact2 = new Contact({ name: 'Mailspring Team', email: 'feedback@mailspring.com' });
const inputs = [
'Ben Imposter <imposter@mailspring.com>, Mailspring Team <feedback@mailspring.com>',
'\n\nbla\nBen Imposter (imposter@mailspring.com), Mailspring Team (feedback@mailspring.com)',
'Hello world! I like cheese. \rBen Imposter (imposter@mailspring.com)\nMailspring Team (feedback@mailspring.com)',
'Ben Imposter<imposter@mailspring.com>Mailspring Team (feedback@mailspring.com)',
];
for (const input of inputs) {
this.expectInputToYield(input, {
to: [participant1, participant2, newContact1, newContact2],
cc: [participant3],
bcc: [],
});
}
});
});
describe('when text contains emails mixed with garbage text', () => {
it('should still parse out emails into Contact objects', () => {
const newContact1 = new Contact({
id: 'gm',
name: 'garbage-man@mailspring.com',
email: 'garbage-man@mailspring.com',
});
const newContact2 = new Contact({
id: 'rm',
name: 'recycling-guy@mailspring.com',
email: 'recycling-guy@mailspring.com',
});
const inputs = [
"Hello world I real. \n asd. garbage-man@mailspring.com—he's cool Also 'recycling-guy@mailspring.com'!",
'garbage-man@mailspring.com1WHOA I REALLY HATE DATA,recycling-guy@mailspring.com',
'nils.com garbage-man@mailspring.com @mailspring.com nope@.com nope! recycling-guy@mailspring.com HOLLA AT recycling-guy@mailspring.',
];
for (const input of inputs) {
this.expectInputToYield(input, {
to: [participant1, participant2, newContact1, newContact2],
cc: [participant3],
bcc: [],
});
}
});
});
});
});