Welcome to Discourse!
',
+ side_by_side_markdown:
+ '
Welcome to Discourse! Welcome to Discourse!
',
+ },
+ title_changes: {
+ inline: '
',
+ side_by_side:
+ '
',
+ },
+ user_changes: null,
+ tags_changes: {
+ previous: ["tag1", "tag2"],
+ current: ["tag2", "tag3"],
+ },
+ wiki: false,
+ can_edit: true,
+};
+
+acceptance("History Modal - authorized", function (needs) {
+ needs.user();
+ needs.pretender((server, helper) => {
+ server.get("/posts/419/revisions/latest.json", () => {
+ return helper.response(revisionResponse);
+ });
+
+ server.get("/posts/419/revisions/1.json", () => {
+ return helper.response({ ...revisionResponse, current_revision: 1 });
+ });
+ });
+
+ test("edit post button", async function (assert) {
+ await visit("/t/internationalization-localization/280");
+ await click("article[data-post-id='419'] .edits button");
+ assert
+ .dom(".history-modal #revision-footer-buttons .edit-post")
+ .exists("displays the edit post button on the latest revision");
+ });
+
+ test("edit post button - not last revision", async function (assert) {
+ await visit("/t/internationalization-localization/280");
+ await click("article[data-post-id='419'] .edits button");
+ await click(".history-modal .previous-revision");
+ assert
+ .dom(".history-modal #revision-footer-buttons .edit-post")
+ .doesNotExist(
+ "hides the edit post button when not on the latest revision"
+ );
+ });
+});
+
+acceptance("History Modal - anonymous", function (needs) {
+ needs.pretender((server, helper) => {
+ server.get("/posts/419/revisions/latest.json", () => {
+ return helper.response({ ...revisionResponse, can_edit: false });
+ });
+ });
+
+ test("edit post button", async function (assert) {
+ await visit("/t/internationalization-localization/280");
+ await click("article[data-post-id='419'] .edits button");
+ assert
+ .dom(".history-modal #revision-footer-buttons .edit-post")
+ .doesNotExist(
+ "it should not display edit button when user cannot edit the post"
+ );
+ });
+});
diff --git a/app/assets/javascripts/discourse/tests/unit/controllers/history-test.js b/app/assets/javascripts/discourse/tests/unit/controllers/history-test.js
deleted file mode 100644
index cb3670e43de..00000000000
--- a/app/assets/javascripts/discourse/tests/unit/controllers/history-test.js
+++ /dev/null
@@ -1,120 +0,0 @@
-import { module, test } from "qunit";
-import { setupTest } from "ember-qunit";
-
-module("Unit | Controller | history", function (hooks) {
- setupTest(hooks);
-
- test("displayEdit", async function (assert) {
- const controller = this.owner.lookup("controller:history");
-
- controller.setProperties({
- model: { last_revision: 3, current_revision: 3, can_edit: false },
- topicController: {},
- });
-
- assert.strictEqual(
- controller.displayEdit,
- false,
- "it should not display edit button when user cannot edit the post"
- );
-
- controller.set("model.can_edit", true);
-
- assert.strictEqual(
- controller.displayEdit,
- true,
- "it should display edit button when user can edit the post"
- );
-
- controller.set("topicController", null);
- assert.strictEqual(
- controller.displayEdit,
- false,
- "it should not display edit button when there is not topic controller"
- );
- controller.set("topicController", {});
-
- controller.set("model.current_revision", 2);
- assert.strictEqual(
- controller.displayEdit,
- false,
- "it should only display the edit button on the latest revision"
- );
-
- const html = `
-
" width="276" height="183">
-
-
-
-
-
-
-
-
-
-
-
-
- Column
- Test
-
-
-
-
- Osama
- Testing
-
-
-
`;
-
- const expectedOutput = `
-
" width="276" height="183">
-
-
-
-
-
-
-
-
-
-
-
-
- Column
- Test
-
-
-
-
- Osama
- Testing
-
-
-
`;
-
- controller.setProperties({
- viewMode: "side_by_side",
- model: {
- body_changes: {
- side_by_side: html,
- },
- },
- });
-
- await controller.bodyDiffChanged();
-
- const output = controller.bodyDiff;
- assert.strictEqual(
- output,
- expectedOutput,
- "it keeps HTML safe and doesn't strip onebox tags"
- );
- });
-});