Browse Source

ComposeArea: Add shortcode UI test

Danilo Bargen 6 years ago
parent
commit
bab0c1a89c
2 changed files with 29 additions and 1 deletions
  1. 1 1
      src/directives/compose_area.ts
  2. 28 0
      tests/ui/run.ts

+ 1 - 1
src/directives/compose_area.ts

@@ -269,7 +269,7 @@ export default [
                         const text = extractText(composeDiv[0], logAdapter($log.warn, logTag), false);
                         if (text === '\n') {
                             composeDiv[0].innerText = '';
-                        } else if (ev.keyCode === 190 && caretPosition !== null) {
+                        } else if ((ev.keyCode === 190 || ev.key === ':') && caretPosition !== null) {
                             // A ':' is pressed, try to parse
                             const currentWord = stringService.getWord(text, caretPosition.fromChar, [':']);
                             if (currentWord.realLength > 2 && currentWord.word.substr(0, 1) === ':') {

+ 28 - 0
tests/ui/run.ts

@@ -40,6 +40,20 @@ async function extractText(driver: WebDriver): Promise<string> {
     return driver.executeScript<string>(script);
 }
 
+/**
+ * Helper function to send a KeyUp event.
+ */
+async function sendKeyUp(driver: WebDriver, key: string): Promise<void> {
+    const script = `
+        const e = document.createEvent('HTMLEvents');
+        e.initEvent('keyup', false, true);
+        e.key = '${key}';
+        const element = document.querySelector("div.compose");
+        element.dispatchEvent(e);
+    `;
+    return driver.executeScript<void>(script);
+}
+
 /**
  * The emoji trigger should toggle the emoji keyboard.
  */
@@ -173,6 +187,19 @@ async function regression672(driver: WebDriver) {
     expect(text).to.equal('hello\n😫😫\nworld');
 }
 
+/**
+ * Insert emoji with a shortcode.
+ */
+async function insertEmojiWithShortcode(driver: WebDriver) {
+    // Insert text
+    await driver.findElement(composeArea).click();
+    await driver.findElement(composeArea).sendKeys('hello :+1:');
+    await sendKeyUp(driver, ':');
+
+    const text = await extractText(driver);
+    expect(text).to.equal('hello 👍');
+}
+
 // Register tests here
 const TESTS: Array<[string, Testfunc]> = [
     ['Show and hide emoji selector', showEmojiSelector],
@@ -181,6 +208,7 @@ const TESTS: Array<[string, Testfunc]> = [
     ['Regression test #574', regression574],
     ['Regression test #671', regression671],
     ['Regression test #672', regression672],
+    ['Insert emoji through shortcode', insertEmojiWithShortcode],
 ];
 
 // Test runner