Fix up tests.

pull/26/head
Mikunj 7 years ago
parent 9d342e8951
commit 4e6df71999

@ -1434,23 +1434,7 @@
if (!this.isPrivate()) { if (!this.isPrivate()) {
return ''; return '';
} }
const number = this.id; return this.id;
try {
const parsedNumber = libphonenumber.parse(number);
const regionCode = libphonenumber.getRegionCodeForNumber(parsedNumber);
if (regionCode === storage.get('regionCode')) {
return libphonenumber.format(
parsedNumber,
libphonenumber.PhoneNumberFormat.NATIONAL
);
}
return libphonenumber.format(
parsedNumber,
libphonenumber.PhoneNumberFormat.INTERNATIONAL
);
} catch (e) {
return number;
}
}, },
isPrivate() { isPrivate() {

@ -38,7 +38,7 @@
}); });
describe('Conversation', function() { describe('Conversation', function() {
var attributes = { type: 'private', id: '+18085555555' }; var attributes = { type: 'private', id: '771d11d01e56d9bfc3d74115c33225a632321b509ac17a13fdeac71165d09b94ab' };
before(async () => { before(async () => {
var convo = new Whisper.ConversationCollection().add(attributes); var convo = new Whisper.ConversationCollection().add(attributes);
await window.Signal.Data.saveConversation(convo.attributes, { await window.Signal.Data.saveConversation(convo.attributes, {
@ -59,7 +59,7 @@
after(clearDatabase); after(clearDatabase);
it('sorts its contacts in an intl-friendly way', function() { it('sorts its contacts in an intl-friendly way', function() {
var convo = new Whisper.Conversation({ id: '+18085555555' }); var convo = new Whisper.Conversation({ id: '771d11d01e56d9bfc3d74115c33225a632321b509ac17a13fdeac71165d09b94ab' });
convo.contactCollection.add( convo.contactCollection.add(
new Whisper.Conversation({ new Whisper.Conversation({
name: 'C', name: 'C',
@ -83,7 +83,7 @@
it('contains its own messages', async function() { it('contains its own messages', async function() {
var convo = new Whisper.ConversationCollection().add({ var convo = new Whisper.ConversationCollection().add({
id: '+18085555555', id: '771d11d01e56d9bfc3d74115c33225a632321b509ac17a13fdeac71165d09b94ab',
}); });
await convo.fetchMessages(); await convo.fetchMessages();
assert.notEqual(convo.messageCollection.length, 0); assert.notEqual(convo.messageCollection.length, 0);
@ -91,7 +91,7 @@
it('contains only its own messages', async function() { it('contains only its own messages', async function() {
var convo = new Whisper.ConversationCollection().add({ var convo = new Whisper.ConversationCollection().add({
id: '+18085556666', id: '6eb56f06737d0966239e70d431d4dfd9e57c1e7dddacaf61907fcbc14295e424fd',
}); });
await convo.fetchMessages(); await convo.fetchMessages();
assert.strictEqual(convo.messageCollection.length, 0); assert.strictEqual(convo.messageCollection.length, 0);
@ -109,7 +109,7 @@
it('has a title', function() { it('has a title', function() {
var convos = new Whisper.ConversationCollection(); var convos = new Whisper.ConversationCollection();
var convo = convos.add(attributes); var convo = convos.add(attributes);
assert.equal(convo.getTitle(), '+1 808-555-5555'); assert.equal(convo.getTitle(), '771d11d01e56d9bfc3d74115c33225a632321b509ac17a13fdeac71165d09b94ab');
convo = convos.add({ type: '' }); convo = convos.add({ type: '' });
assert.equal(convo.getTitle(), 'Unknown group'); assert.equal(convo.getTitle(), 'Unknown group');
@ -121,7 +121,7 @@
it('returns the number', function() { it('returns the number', function() {
var convos = new Whisper.ConversationCollection(); var convos = new Whisper.ConversationCollection();
var convo = convos.add(attributes); var convo = convos.add(attributes);
assert.equal(convo.getNumber(), '+1 808-555-5555'); assert.equal(convo.getNumber(), '771d11d01e56d9bfc3d74115c33225a632321b509ac17a13fdeac71165d09b94ab');
convo = convos.add({ type: '' }); convo = convos.add({ type: '' });
assert.equal(convo.getNumber(), ''); assert.equal(convo.getNumber(), '');
@ -134,41 +134,21 @@
assert.property(avatar, 'color'); assert.property(avatar, 'color');
}); });
describe('phone number parsing', function() { describe('when set to private', function() {
after(function() { it('correctly validates hex numbers', function() {
storage.remove('regionCode'); const regularId = new Whisper.Conversation({ type: 'private', id: '771d11d01e56d9bfc3d74115c33225a632321b509ac17a13fdeac71165d09b94ab' });
const invalidId = new Whisper.Conversation({ type: 'private', id: 'j71d11d01e56d9bfc3d74115c33225a632321b509ac17a13fdeac71165d09b94ab' });
assert.ok(regularId.isValid());
assert.notOk(invalidId.isValid());
}); });
function checkAttributes(number) {
var convo = new Whisper.ConversationCollection().add({ it('correctly validates length', function() {
type: 'private', const regularId = new Whisper.Conversation({ type: 'private', id: '771d11d01e56d9bfc3d74115c33225a632321b509ac17a13fdeac71165d09b94ab' });
}); const shortId = new Whisper.Conversation({ type: 'private', id: '771d11d' });
convo.set('id', number); const longId = new Whisper.Conversation({ type: 'private', id: '771d11d01e56d9bfc3d74115c33225a632321b509ac17a13fdeac71165d09b94abaa' });
convo.validate(convo.attributes); assert.ok(regularId.isValid());
assert.strictEqual(convo.get('id'), '+14155555555', number); assert.notOk(shortId.isValid());
} assert.notOk(longId.isValid());
it('processes the phone number when validating', function() {
['+14155555555'].forEach(checkAttributes);
});
it('defaults to the local regionCode', function() {
storage.put('regionCode', 'US');
['14155555555', '4155555555'].forEach(checkAttributes);
});
it('works with common phone number formats', function() {
storage.put('regionCode', 'US');
[
'415 555 5555',
'415-555-5555',
'(415) 555 5555',
'(415) 555-5555',
'1 415 555 5555',
'1 415-555-5555',
'1 (415) 555 5555',
'1 (415) 555-5555',
'+1 415 555 5555',
'+1 415-555-5555',
'+1 (415) 555 5555',
'+1 (415) 555-5555',
].forEach(checkAttributes);
}); });
}); });
}); });
@ -178,7 +158,7 @@
beforeEach(async function() { beforeEach(async function() {
convo = new Whisper.ConversationCollection().add({ convo = new Whisper.ConversationCollection().add({
id: '+14155555555', id: '771d11d01e56d9bfc3d74115c33225a632321b509ac17a13fdeac71165d09b94ab',
type: 'private', type: 'private',
name: 'John Doe', name: 'John Doe',
}); });
@ -202,21 +182,20 @@
}) })
); );
} }
it('matches by partial phone number', function() { it('matches by partial keys', function() {
return testSearch([ return testSearch([
'1', '1',
'4', '771',
'+1', '1e',
'415', '56d9bfc3d74115c3322',
'4155', '6d9bfc3d74115c33225a632321b509ac17a13fdeac71165d',
'4155555555', '771d11d01e56d9bfc3d74115c33225a632321b509ac17a13fdeac71165d09b94ab'
'14155555555',
'+14155555555',
]); ]);
}); });
it('matches by name', function() { // TODO: Re-enable once we have nickanme functionality
return testSearch(['John', 'Doe', 'john', 'doe', 'John Doe', 'john doe']); // it('matches by name', function() {
}); // return testSearch(['John', 'Doe', 'john', 'doe', 'John Doe', 'john doe']);
// });
it('does not match +', async function() { it('does not match +', async function() {
var collection = new Whisper.ConversationCollection(); var collection = new Whisper.ConversationCollection();
await collection.search('+'); await collection.search('+');

@ -1,28 +1,4 @@
describe('ConversationSearchView', function() { describe('ConversationSearchView', function() {
it('should match partial numbers', function() {
var $el = $('<div><div class="new-contact contact hide"></div></div>');
var view = new Whisper.ConversationSearchView({
el: $el,
input: $('<input>'),
}).render();
var maybe_numbers = [
'+1 415',
'+1415',
'+1415',
'415',
'(415)',
' (415',
'(415) 123 4567',
'+1 (415) 123 4567',
' +1 (415) 123 4567',
'1 (415) 123 4567',
'1 415-123-4567',
'415-123-4567',
];
maybe_numbers.forEach(function(n) {
assert.ok(view.maybeNumber(n), n);
});
});
describe('Searching for left groups', function() { describe('Searching for left groups', function() {
let convo; let convo;

Loading…
Cancel
Save