diff --git a/javascripts/discourse/api-initializers/table-editor.js b/javascripts/discourse/api-initializers/table-editor.js index 76c1ea7..b3e6e0c 100644 --- a/javascripts/discourse/api-initializers/table-editor.js +++ b/javascripts/discourse/api-initializers/table-editor.js @@ -16,6 +16,7 @@ export default apiInitializer("0.11.1", (api) => { const openPopupBtn = document.createElement("button"); openPopupBtn.classList.add( "open-popup-link", + "btn-edit-md-table", "btn-default", "btn", "btn-icon-text" diff --git a/test/acceptance/table-builder-test.js b/test/acceptance/table-builder-test.js index 4e291c0..91a928b 100644 --- a/test/acceptance/table-builder-test.js +++ b/test/acceptance/table-builder-test.js @@ -1,10 +1,17 @@ -import { acceptance, exists } from "discourse/tests/helpers/qunit-helpers"; +import { + acceptance, + exists, + visible, +} from "discourse/tests/helpers/qunit-helpers"; import { click, visit } from "@ember/test-helpers"; import { test } from "qunit"; import { clearPopupMenuOptionsCallback } from "discourse/controllers/composer"; import selectKit from "discourse/tests/helpers/select-kit-helper"; +import pretender, { response } from "discourse/tests/helpers/create-pretender"; +import { cloneJSON } from "discourse-common/lib/object"; +import topicWithTable from "../fixtures/topic-with-table"; -acceptance("Table Builder", function (needs) { +acceptance("Table Builder - Create Table", function (needs) { needs.user(); needs.hooks.beforeEach(() => clearPopupMenuOptionsCallback()); @@ -31,4 +38,42 @@ acceptance("Table Builder", function (needs) { "it shows the builder button" ); }); + + test("Can see table builder button when replying to a topic", async function (assert) { + await visit("/t/internationalization-localization/280"); + await click("button.reply-to-post"); + assert.ok(exists("#reply-control")); + await click(".d-editor-button-bar .options"); + await selectKit(".toolbar-popup-menu-options").expand(); + assert.ok( + exists(".select-kit-row[data-value='showTableBuilder']"), + "it shows the builder button" + ); + }); +}); + +acceptance("Table Builder - Edit Table", function (needs) { + needs.pretender((server, helper) => { + server.get("/t/960.json", () => { + const topicList = cloneJSON(topicWithTable); + topicList.post_stream.posts[2].post_type = 4; + return helper.response(topicList); + }); + }); + + test("Can see edit button on post with table", async function (assert) { + await visit("/t/960"); + await focus(document.querySelector(".cooked .md-table")); + assert.ok(exists("button.btn-edit-md-table"), "Edit Table button exists"); + assert.ok( + visible("button.btn-edit-md-table"), + "Edit Table button is visible" + ); + await click("button.btn-edit-md-table"); + assert.ok( + exists(".insert-table-modal-modal"), + "Table Builder modal exists" + ); + await this.pauseTest(); + }); }); diff --git a/test/fixtures/topic-with-table.js b/test/fixtures/topic-with-table.js new file mode 100644 index 0000000..67fb3f3 --- /dev/null +++ b/test/fixtures/topic-with-table.js @@ -0,0 +1,296 @@ +export default { + post_stream: { + posts: [ + { + id: 18, + username: "eviltrout", + avatar_template: "/images/avatar.png", + name: "Evil Trout", + uploaded_avatar_id: 9, + created_at: "2015-08-13T14:49:11.840Z", + cooked: + '
\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n
MakeModelYear
ToyotaSupra1998
NissanSkyline1999
HondaS20002001
\n
', + post_number: 1, + post_type: 1, + updated_at: "2015-08-13T14:49:11.840Z", + reply_count: 0, + reply_to_post_number: null, + quote_count: 0, + incoming_link_count: 0, + reads: 1, + score: 0, + yours: true, + topic_id: 9, + topic_slug: "this-is-a-test-topic", + display_username: "", + primary_group_name: null, + version: 1, + can_edit: true, + can_delete: false, + can_recover: true, + read: true, + user_title: null, + actions_summary: [ + { id: 3, can_act: true }, + { id: 4, can_act: true }, + { id: 5, hidden: true, can_act: true }, + { id: 7, can_act: true }, + { id: 8, can_act: true }, + ], + moderator: false, + admin: true, + staff: true, + user_id: 1, + hidden: false, + hidden_reason_id: null, + trust_level: 4, + deleted_at: null, + user_deleted: false, + edit_reason: null, + can_view_edit_history: true, + wiki: false, + }, + { + id: 19, + username: "eviltrout", + avatar_template: "/images/avatar.png", + name: "Evil Trout", + uploaded_avatar_id: 9, + created_at: "2015-08-13T14:49:18.231Z", + cooked: + '

These are my favourite JDM cars:

\n
\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n
MakeModelYear
ToyotaSupra1998
NissanSkyline1999
HondaS20002001
\n

These are my favourite Euro cars:

\n
\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n
MakeModelYear
Porsche9641998
BMWM32005
Alfa RomeoGiulia2018
\n
', + post_number: 2, + post_type: 1, + updated_at: "2015-08-13T14:49:18.231Z", + reply_count: 0, + reply_to_post_number: null, + quote_count: 0, + incoming_link_count: 0, + reads: 1, + score: 0, + yours: true, + topic_id: 9, + topic_slug: "this-is-a-test-topic", + display_username: "", + primary_group_name: null, + version: 1, + can_edit: true, + can_delete: true, + can_recover: true, + read: true, + user_title: null, + actions_summary: [ + { id: 3, can_act: true }, + { id: 4, can_act: true }, + { id: 5, hidden: true, can_act: true }, + { id: 7, can_act: true }, + { id: 8, can_act: true }, + ], + moderator: false, + admin: true, + staff: true, + user_id: 1, + hidden: false, + hidden_reason_id: null, + trust_level: 4, + deleted_at: null, + user_deleted: false, + edit_reason: null, + can_view_edit_history: true, + wiki: false, + }, + { + id: 20, + username: "eviltrout", + avatar_template: "/images/avatar.png", + name: "Evil Trout", + uploaded_avatar_id: 9, + created_at: "2015-08-13T14:49:23.927Z", + cooked: + '
\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n
MakeModelPrice
ToyotaSupra$50,000
Celica$20,000
NissanGTR$80,000
\n
', + post_number: 3, + post_type: 1, + updated_at: "2015-08-13T14:49:23.927Z", + reply_count: 0, + reply_to_post_number: null, + quote_count: 0, + incoming_link_count: 0, + reads: 1, + score: 0, + yours: true, + topic_id: 9, + topic_slug: "this-is-a-test-topic", + display_username: "", + primary_group_name: null, + version: 1, + can_edit: true, + can_delete: true, + can_recover: true, + read: true, + user_title: null, + actions_summary: [ + { id: 3, can_act: true }, + { id: 4, can_act: true }, + { id: 5, hidden: true, can_act: true }, + { id: 7, can_act: true }, + { id: 8, can_act: true }, + ], + moderator: false, + admin: true, + staff: true, + user_id: 1, + hidden: false, + hidden_reason_id: null, + trust_level: 4, + deleted_at: null, + user_deleted: false, + edit_reason: null, + can_view_edit_history: true, + wiki: false, + }, + ], + stream: [18, 19, 20], + }, + id: 9, + title: "This is a test topic with tables!", + fancy_title: "This is a test topic with tables!", + posts_count: 3, + created_at: "2015-08-13T14:49:11.720Z", + views: 1, + reply_count: 0, + participant_count: 1, + like_count: 0, + last_posted_at: "2015-08-13T14:49:23.927Z", + visible: true, + closed: false, + archived: false, + has_summary: false, + archetype: "regular", + slug: "this-is-a-test-topic", + category_id: 24, + is_shared_draft: true, + word_count: 15, + deleted_at: null, + user_id: 1, + draft: null, + draft_key: "topic_9", + draft_sequence: 3, + posted: true, + unpinned: null, + pinned_globally: false, + pinned: false, + pinned_at: null, + pinned_until: null, + details: { + auto_close_at: null, + auto_close_hours: null, + auto_close_based_on_last_post: false, + created_by: { + id: 1, + username: "tgxworld", + uploaded_avatar_id: 9, + avatar_template: "/images/avatar.png", + }, + last_poster: { + id: 1, + username: "tgxworld", + uploaded_avatar_id: 9, + avatar_template: "/images/avatar.png", + }, + participants: [ + { + id: 1, + username: "tgxworld", + uploaded_avatar_id: 9, + avatar_template: "/images/avatar.png", + post_count: 3, + }, + ], + suggested_topics: [ + { + id: 8, + title: "This is a new and awesome topic!", + fancy_title: "This is a new and awesome topic!", + slug: "this-is-a-new-and-awesome-topic", + posts_count: 3, + reply_count: 0, + highest_post_number: 5, + image_url: null, + created_at: "2015-08-13T05:17:00.000Z", + last_posted_at: "2015-08-13T10:14:34.799Z", + bumped: true, + bumped_at: "2015-08-13T10:14:34.799Z", + unseen: false, + last_read_post_number: 5, + unread_posts: 0, + pinned: false, + unpinned: null, + visible: true, + closed: false, + archived: false, + notification_level: 2, + bookmarked: false, + bookmarks: [], + liked: false, + archetype: "regular", + like_count: 0, + views: 2, + category_id: 1, + }, + { + id: 7, + title: "This is a test category!", + fancy_title: "This is a test category!", + slug: "this-is-a-test-category", + posts_count: 3, + reply_count: 0, + highest_post_number: 3, + image_url: null, + created_at: "2015-08-10T13:40:38.439Z", + last_posted_at: "2015-08-13T01:59:44.928Z", + bumped: true, + bumped_at: "2015-08-13T01:58:35.206Z", + unseen: false, + last_read_post_number: 3, + unread_posts: 0, + pinned: false, + unpinned: null, + visible: true, + closed: false, + archived: false, + notification_level: 3, + bookmarked: false, + bookmarks: [], + liked: false, + archetype: "regular", + like_count: 0, + views: 2, + category_id: 1, + }, + ], + notification_level: 3, + notifications_reason_id: 1, + can_move_posts: true, + can_edit: true, + can_delete: true, + can_recover: true, + can_remove_allowed_users: true, + can_invite_to: true, + can_create_post: true, + can_reply_as_new_topic: true, + can_flag_topic: true, + }, + highest_post_number: 3, + last_read_post_number: 3, + deleted_by: null, + has_deleted: false, + actions_summary: [ + { id: 4, count: 0, hidden: false, can_act: true }, + { id: 7, count: 0, hidden: false, can_act: true }, + { id: 8, count: 0, hidden: false, can_act: true }, + ], + chunk_size: 20, + bookmarked: false, + bookmarks: [], + destination_category_id: 3, +};