Skip to content

Commit

Permalink
#4282 fix: duplicated contact search result (#4944)
Browse files Browse the repository at this point in the history
* fix: dupliated contact search result

* feat: added ui test

* fix: pr review
  • Loading branch information
ioanmo226 authored Feb 8, 2023
1 parent 0730dc4 commit d1b6613
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
3 changes: 2 additions & 1 deletion extension/js/common/platform/store/contact-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -967,7 +967,8 @@ export class ContactStore extends AbstractStore {
reject
);
});
return raw;
// Remove duplicated results
return raw.filter((value, index, arr) => arr.findIndex(contact => contact.email === value.email) === index);
};

private static normalizeString = (str: string) => {
Expand Down
15 changes: 12 additions & 3 deletions test/source/browser/controllable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -461,9 +461,9 @@ abstract class ControllableBase {
throw new Error(`Could not find any frame in ${appearIn}s that matches ${urlMatchables.join(' ')}`);
};

public ensureElementsCount = async (selector: string, count: number) => {
const elements = await this.target.$$(selector);
expect(elements.length).to.equal(count);
public ensureElementsCount = async (selector: string, expectedCount: number) => {
const actualCount = await this.elementCount(selector);
expect(actualCount).to.equal(expectedCount);
};

public getFrame = async (urlMatchables: string[], { sleep = 1, timeout = 10 } = { sleep: 1, timeout: 10 }): Promise<ControllableFrame> => {
Expand Down Expand Up @@ -560,6 +560,15 @@ abstract class ControllableBase {
}
};

protected elementCount = async (selector: string): Promise<number> => {
selector = this.selector(selector);
if (this.isXpath(selector)) {
return (await this.target.$x(selector)).length;
} else {
return (await this.target.$$(selector)).length;
}
};

protected selsAsProcessedArr = (selector: string | string[]): string[] => {
return (Array.isArray(selector) ? selector : [selector]).map(this.selector);
};
Expand Down
2 changes: 2 additions & 0 deletions test/source/tests/compose.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,11 +190,13 @@ export const defineComposeTests = (testVariant: TestVariant, testWithBrowser: Te
await composePage1.type('@input-to', 'human'); // test guessing of contacts
await composePage1.waitAll(['@container-contacts', '@action-select-contact-name(Human at FlowCrypt)']);
await composePage1.waitAll(['@container-contacts', '@action-select-contact-email([email protected])']);
await composePage1.ensureElementsCount('@action-select-contact-email([email protected])', 1);
// works on subsequent search
const composePage2 = await ComposePageRecipe.openStandalone(t, browser, 'compose');
await composePage2.type('@input-to', 'human'); // test guessing of contacts
await composePage2.waitAll(['@container-contacts', '@action-select-contact-name(Human at FlowCrypt)']);
await composePage2.waitAll(['@container-contacts', '@action-select-contact-email([email protected])']);
await composePage1.ensureElementsCount('@action-select-contact-email([email protected])', 1);
})
);

Expand Down

0 comments on commit d1b6613

Please sign in to comment.