DEV: Add more tests

This commit is contained in:
Keegan George 2022-09-29 16:14:15 -07:00
parent 55c80ed04f
commit 73b336c36d
No known key found for this signature in database
GPG Key ID: 91B40E38537AC000
3 changed files with 344 additions and 2 deletions

View File

@ -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"

View File

@ -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();
});
});

296
test/fixtures/topic-with-table.js vendored Normal file
View File

@ -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:
'<div class="md-table">\n<table>\n<thead>\n<tr>\n<th>Make</th>\n<th>Model</th>\n<th>Year</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td>Toyota</td>\n<td>Supra</td>\n<td>1998</td>\n</tr>\n<tr>\n<td>Nissan</td>\n<td>Skyline</td>\n<td>1999</td>\n</tr>\n<tr>\n<td>Honda</td>\n<td>S2000</td>\n<td>2001</td>\n</tr>\n</tbody>\n</table>\n</div>',
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:
'<p>These are my favourite JDM cars:</p>\n<div class="md-table">\n<table>\n<thead>\n<tr>\n<th>Make</th>\n<th>Model</th>\n<th>Year</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td>Toyota</td>\n<td>Supra</td>\n<td>1998</td>\n</tr>\n<tr>\n<td>Nissan</td>\n<td>Skyline</td>\n<td>1999</td>\n</tr>\n<tr>\n<td>Honda</td>\n<td>S2000</td>\n<td>2001</td>\n</tr>\n</tbody>\n</table>\n</div><p>These are my favourite Euro cars:</p>\n<div class="md-table">\n<table>\n<thead>\n<tr>\n<th>Make</th>\n<th>Model</th>\n<th>Year</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td>Porsche</td>\n<td>964</td>\n<td>1998</td>\n</tr>\n<tr>\n<td>BMW</td>\n<td>M3</td>\n<td>2005</td>\n</tr>\n<tr>\n<td>Alfa Romeo</td>\n<td>Giulia</td>\n<td>2018</td>\n</tr>\n</tbody>\n</table>\n</div>',
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:
'<div class="md-table">\n<table>\n<thead>\n<tr>\n<th>Make</th>\n<th>Model</th>\n<th>Price</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td>Toyota</td>\n<td>Supra</td>\n<td>$50,000</td>\n</tr>\n<tr>\n<td></td>\n<td>Celica</td>\n<td>$20,000</td>\n</tr>\n<tr>\n<td>Nissan</td>\n<td>GTR</td>\n<td>$80,000</td>\n</tr>\n</tbody>\n</table>\n</div>',
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,
};