Skip to content

Commit

Permalink
Add not matching emoji test, and return empty array
Browse files Browse the repository at this point in the history
  • Loading branch information
Sonam Serchan authored and sonam-serchan committed Aug 1, 2023
1 parent a2a6306 commit 46c4958
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 12 deletions.
21 changes: 16 additions & 5 deletions src/emojis/emojiHandler.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,33 @@ const emojis = {
programming: ["javascript", "python"],
};

describe("Emoji handler", () => {
it("should return matching emojis for a given keyword", () => {
const keywords = Object.values(emojis).flat();
const keywords = Object.values(emojis).flat();

describe("Emoji handler", () => {
it("should return matching emoji for a given keyword", () => {
const matchingEmojis = findMatchingEmojiKeywords(
keywords,
"reactivity",
emojis
);
expect(matchingEmojis).toEqual(["react"]);
});

const matchingEmojis2 = findMatchingEmojiKeywords(
it("should return multiple matching emojis for a given keyword", () => {
const matchingEmojis = findMatchingEmojiKeywords(
keywords,
"javascript",
emojis
);
expect(matchingEmojis2).toEqual(["javascript", "programming"]);
expect(matchingEmojis).toEqual(["javascript", "programming"]);
});

it("should return empty array for a not matching keyword", () => {
const matchingEmojis = findMatchingEmojiKeywords(
keywords,
"random",
emojis
);
expect(matchingEmojis).toEqual([]);
});
});
9 changes: 2 additions & 7 deletions src/emojis/emojiHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,7 @@ export function getEmojisToReactWith(text: string): Array<string> {
const keywords = Object.values(emojis).flat();

// search for each keyword in the text
const emojisToReactWith = findMatchingEmojiKeywords(
keywords,
lowerCaseText,
emojis
);

return Array.from(new Set(emojisToReactWith));
return findMatchingEmojiKeywords(keywords, lowerCaseText, emojis);
}

export function findMatchingEmojiKeywords(
Expand All @@ -31,4 +25,5 @@ export function findMatchingEmojiKeywords(
return matchingEmojis;
}
}
return [];
}

0 comments on commit 46c4958

Please sign in to comment.