|
| 1 | +/* |
| 2 | +Copyright 2022 Ryan Browne <[email protected]> |
| 3 | +
|
| 4 | +Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | +you may not use this file except in compliance with the License. |
| 6 | +You may obtain a copy of the License at |
| 7 | +
|
| 8 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +
|
| 10 | +Unless required by applicable law or agreed to in writing, software |
| 11 | +distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | +See the License for the specific language governing permissions and |
| 14 | +limitations under the License. |
| 15 | +*/ |
| 16 | + |
| 17 | +import EmojiProvider from '../../src/autocomplete/EmojiProvider'; |
| 18 | +import { mkStubRoom } from '../test-utils/test-utils'; |
| 19 | + |
| 20 | +const EMOJI_SHORTCODES = [ |
| 21 | + ":+1", |
| 22 | + ":heart", |
| 23 | + ":grinning", |
| 24 | + ":hand", |
| 25 | + ":man", |
| 26 | + ":sweat", |
| 27 | + ":monkey", |
| 28 | + ":boat", |
| 29 | + ":mailbox", |
| 30 | + ":cop", |
| 31 | + ":bow", |
| 32 | + ":kiss", |
| 33 | + ":golf", |
| 34 | +]; |
| 35 | + |
| 36 | +// Some emoji shortcodes are too short and do not actually trigger autocompletion until the ending `:`. |
| 37 | +// This means that we cannot compare their autocompletion before and after the ending `:` and have |
| 38 | +// to simply assert that the final completion with the colon is the exact emoji. |
| 39 | +const TOO_SHORT_EMOJI_SHORTCODE = [ |
| 40 | + { emojiShortcode: ":o", expectedEmoji: "⭕️" }, |
| 41 | +]; |
| 42 | + |
| 43 | +describe('EmojiProvider', function() { |
| 44 | + const testRoom = mkStubRoom(undefined, undefined, undefined); |
| 45 | + |
| 46 | + it.each(EMOJI_SHORTCODES)('Returns consistent results after final colon %s', async function(emojiShortcode) { |
| 47 | + const ep = new EmojiProvider(testRoom); |
| 48 | + const range = { "beginning": true, "start": 0, "end": 3 }; |
| 49 | + const completionsBeforeColon = await ep.getCompletions(emojiShortcode, range); |
| 50 | + const completionsAfterColon = await ep.getCompletions(emojiShortcode + ':', range); |
| 51 | + |
| 52 | + const firstCompletionWithoutColon = completionsBeforeColon[0].completion; |
| 53 | + const firstCompletionWithColon = completionsAfterColon[0].completion; |
| 54 | + |
| 55 | + expect(firstCompletionWithoutColon).toEqual(firstCompletionWithColon); |
| 56 | + }); |
| 57 | + |
| 58 | + it.each( |
| 59 | + TOO_SHORT_EMOJI_SHORTCODE, |
| 60 | + )('Returns correct results after final colon $emojiShortcode', async ({ emojiShortcode, expectedEmoji }) => { |
| 61 | + const ep = new EmojiProvider(testRoom); |
| 62 | + const range = { "beginning": true, "start": 0, "end": 3 }; |
| 63 | + const completions = await ep.getCompletions(emojiShortcode + ':', range); |
| 64 | + |
| 65 | + expect(completions[0].completion).toEqual(expectedEmoji); |
| 66 | + }); |
| 67 | +}); |
0 commit comments