DEV: Apply code review.

DEV: Apply code review.
From b585f7f33635a2dd1586b1e356c4d15ac372cb69 Mon Sep 17 00:00:00 2001
From: Bianca Nenciu <nenciu.bianca@gmail.com>
Date: Mon, 3 Dec 2018 13:51:59 +0200
Subject: [PATCH] DEV: Apply code review.


diff --git a/app/assets/javascripts/admin/controllers/admin-email-advanced-test.js.es6 b/app/assets/javascripts/admin/controllers/admin-email-advanced-test.js.es6
index 2f9084b..34b2d7b 100644
--- a/app/assets/javascripts/admin/controllers/admin-email-advanced-test.js.es6
+++ b/app/assets/javascripts/admin/controllers/admin-email-advanced-test.js.es6
@@ -6,6 +6,7 @@ export default Ember.Controller.extend({
   text: null,
   elided: null,
   format: null,
+  loading: null,
 
   actions: {
     run() {
diff --git a/app/assets/javascripts/admin/templates/email-advanced-test.hbs b/app/assets/javascripts/admin/templates/email-advanced-test.hbs
index 2fc02ad..4a30060 100644
--- a/app/assets/javascripts/admin/templates/email-advanced-test.hbs
+++ b/app/assets/javascripts/admin/templates/email-advanced-test.hbs
@@ -2,7 +2,7 @@
 
 <div class='email-advanced-test'>
   <label for="email">{{i18n 'admin.email.advanced_test.email'}}</label>
-  {{textarea name="email" value=email class="advanced-test"}}
+  {{textarea name="email" value=email class="email-body"}}
   <button class='btn' {{action "run"}}>{{i18n 'admin.email.advanced_test.run'}}</button>
 </div>
 
diff --git a/app/assets/stylesheets/common/admin/emails.scss b/app/assets/stylesheets/common/admin/emails.scss
index 6be0f2b..732f3d4 100644
--- a/app/assets/stylesheets/common/admin/emails.scss
+++ b/app/assets/stylesheets/common/admin/emails.scss
@@ -89,7 +89,7 @@
     display: block;
   }
 
-  textarea {
+  .email-body {
     width: 95%;
     height: 150px;
     font-family: monospace;
diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml
index e1cad51..2016681 100644
--- a/config/locales/client.en.yml
+++ b/config/locales/client.en.yml
@@ -3415,7 +3415,7 @@ en:
         preview_digest: "Preview Summary"
         advanced_test:
           title: "Advanced Test"
-          desc: "See how Discourse processes recieved emails. To be able to correctly process the email, please paste below the whole original email message."
+          desc: "See how Discourse processes received emails. To be able to correctly process the email, please paste below the whole original email message."
           email: "Original message"
           run: "Run Test"
           text: "Selected Text Body"
diff --git a/spec/requests/admin/email_controller_spec.rb b/spec/requests/admin/email_controller_spec.rb
index a6d30ba..3df6f3a 100644
--- a/spec/requests/admin/email_controller_spec.rb
+++ b/spec/requests/admin/email_controller_spec.rb
@@ -184,4 +184,28 @@ describe Admin::EmailController do
       expect(incoming['error']).to eq(I18n.t("emails.incoming.unrecognized_error"))
     end
   end
+
+  describe '#advanced_test' do
+    it 'should ...' do
+      email = <<~EMAIL
+        From: "somebody" <somebody@example.com>
+        To: someone@example.com
+        Date: Mon, 3 Dec 2018 00:00:00 -0000
+        Subject: This is some subject
+        Content-Type: text/plain; charset="UTF-8"
+
+        Hello, this is a test!
+
+        ---
+
+        This part should be elided.
+      EMAIL
+      post "/admin/email/advanced-test.json", params: { email: email }
+      expect(response.status).to eq(200)
+      incoming = JSON.parse(response.body)
+      expect(incoming['format']).to eq(1)
+      expect(incoming['text']).to eq("Hello, this is a test!")
+      expect(incoming['elided']).to eq("---\n\nThis part should be elided.")
+    end
+  end
 end
diff --git a/test/javascripts/acceptance/admin-emails-test.js.es6 b/test/javascripts/acceptance/admin-emails-test.js.es6
new file mode 100644
index 0000000..f44cf63
--- /dev/null
+++ b/test/javascripts/acceptance/admin-emails-test.js.es6
@@ -0,0 +1,41 @@
+import { acceptance } from "helpers/qunit-helpers";
+
+acceptance("Admin - Emails", { loggedIn: true });
+
+const email = `
+From: "somebody" <somebody@example.com>
+To: someone@example.com
+Date: Mon, 3 Dec 2018 00:00:00 -0000
+Subject: This is some subject
+Content-Type: text/plain; charset="UTF-8"
+
+Hello, this is a test!
+
+---
+
+This part should be elided.`.trim();
+
+QUnit.test("shows selected and elided text", async assert => {
+  // prettier-ignore
+  server.post("/admin/email/advanced-test", () => { // eslint-disable-line no-undef
+    return [
+      200,
+      { "Content-Type": "application/json" },
+      {
+        format: 1,
+        text: "Hello, this is a test!",
+        elided: "---\n\nThis part should be elided.",
+      }
+    ];
+  });
+
+  await visit("/admin/email/advanced-test");
+  await fillIn("textarea.email-body", email);
+  await click(".email-advanced-test button");
+
+  assert.equal(find(".text pre").text(), "Hello, this is a test!");
+  assert.equal(
+    find(".elided pre").text(),
+    "---\n\nThis part should be elided."
+  );
+});

GitHub

1 Like