From 5952a6c0ad87758d5f680452193d6ca6f90f368d Mon Sep 17 00:00:00 2001 From: Joffrey JAFFEUX Date: Mon, 25 Feb 2019 16:04:55 +0100 Subject: [PATCH] DEV: uses find() helper instead of this.$() in js tests (#7062) --- Dangerfile | 20 +++ .../test/components/invite-list-test.js.es6 | 25 ++- ...iscourse-poll-standard-results-test.js.es6 | 22 +-- .../components/themes-list-item-test.js.es6 | 6 +- .../admin/components/themes-list-test.js.es6 | 30 ++-- .../components/ace-editor-test.js.es6 | 8 +- .../components/d-button-test.js.es6 | 16 +- .../components/d-editor-test.js.es6 | 42 ++--- .../components/image-uploader-test.js.es6 | 10 +- .../components/text-field-test.js.es6 | 10 +- .../widgets/actions-summary-test.js.es6 | 12 +- .../widgets/avatar-flair-test.js.es6 | 10 +- test/javascripts/widgets/button-test.js.es6 | 14 +- .../widgets/hamburger-menu-test.js.es6 | 56 +++--- test/javascripts/widgets/header-test.js.es6 | 8 +- .../javascripts/widgets/home-logo-test.js.es6 | 44 ++--- .../widgets/post-links-test.js.es6 | 6 +- .../widgets/post-stream-test.js.es6 | 34 ++-- test/javascripts/widgets/post-test.js.es6 | 168 +++++++++--------- .../widgets/poster-name-test.js.es6 | 28 +-- .../javascripts/widgets/user-menu-test.js.es6 | 24 +-- test/javascripts/widgets/widget-test.js.es6 | 57 +++--- 22 files changed, 332 insertions(+), 318 deletions(-) diff --git a/Dangerfile b/Dangerfile index 2f6e4c30710..d1c3326dee6 100644 --- a/Dangerfile +++ b/Dangerfile @@ -22,7 +22,10 @@ files = (git.added_files + git.modified_files) .select { |path| !path.start_with?("plugins/") } .select { |path| path.end_with?("es6") || path.end_with?("rb") } +js_test_files = files.select { |path| path.end_with?("-test.js.es6") } + super_offenses = [] +jquery_find_offenses = [] files.each do |path| diff = git.diff_for_file(path) @@ -34,9 +37,26 @@ files.each do |path| end end +js_test_files.each do |path| + diff = git.diff_for_file(path) + + next if !diff + + diff.patch.lines.grep(/^\+\s\s/).each do |added_line| + jquery_find_offenses << path if added_line['this.$('] + end +end + if !super_offenses.empty? warn(%{ When possible use `this._super(...arguments)` instead of `this._super()`\n #{super_offenses.uniq.map { |o| github.html_link(o) }.join("\n")} }) end + +if !jquery_find_offenses.empty? + warn(%{ +Use `find()` instead of `this.$` in js tests`\n +#{jquery_find_offenses.uniq.map { |o| github.html_link(o) }.join("\n")} + }) +end diff --git a/app/assets/javascripts/wizard/test/components/invite-list-test.js.es6 b/app/assets/javascripts/wizard/test/components/invite-list-test.js.es6 index 95436fb69ed..a6fa548f8d2 100644 --- a/app/assets/javascripts/wizard/test/components/invite-list-test.js.es6 +++ b/app/assets/javascripts/wizard/test/components/invite-list-test.js.es6 @@ -10,13 +10,10 @@ componentTest("can add users", { async test(assert) { assert.ok( - this.$(".users-list .invite-list-user").length === 0, + find(".users-list .invite-list-user").length === 0, "no users at first" ); - assert.ok( - this.$(".new-user .invalid").length === 0, - "not invalid at first" - ); + assert.ok(find(".new-user .invalid").length === 0, "not invalid at first"); const firstVal = JSON.parse(this.get("field.value")); assert.equal(firstVal.length, 0, "empty JSON at first"); @@ -28,19 +25,19 @@ componentTest("can add users", { await click(".add-user"); assert.ok( - this.$(".users-list .invite-list-user").length === 0, + find(".users-list .invite-list-user").length === 0, "doesn't add a blank user" ); - assert.ok(this.$(".new-user .invalid").length === 1); + assert.ok(find(".new-user .invalid").length === 1); await fillIn(".invite-email", "eviltrout@example.com"); await click(".add-user"); assert.ok( - this.$(".users-list .invite-list-user").length === 1, + find(".users-list .invite-list-user").length === 1, "adds the user" ); - assert.ok(this.$(".new-user .invalid").length === 0); + assert.ok(find(".new-user .invalid").length === 0); const val = JSON.parse(this.get("field.value")); assert.equal(val.length, 1); @@ -56,23 +53,23 @@ componentTest("can add users", { await click(".add-user"); assert.ok( - this.$(".users-list .invite-list-user").length === 1, + find(".users-list .invite-list-user").length === 1, "can't add the same user twice" ); - assert.ok(this.$(".new-user .invalid").length === 1); + assert.ok(find(".new-user .invalid").length === 1); await fillIn(".invite-email", "not-an-email"); await click(".add-user"); assert.ok( - this.$(".users-list .invite-list-user").length === 1, + find(".users-list .invite-list-user").length === 1, "won't add an invalid email" ); - assert.ok(this.$(".new-user .invalid").length === 1); + assert.ok(find(".new-user .invalid").length === 1); await click(".invite-list .invite-list-user:eq(0) .remove-user"); assert.ok( - this.$(".users-list .invite-list-user").length === 0, + find(".users-list .invite-list-user").length === 0, "removed the user" ); } diff --git a/plugins/poll/test/javascripts/widgets/discourse-poll-standard-results-test.js.es6 b/plugins/poll/test/javascripts/widgets/discourse-poll-standard-results-test.js.es6 index bfcd7be01da..33ee000b0a1 100644 --- a/plugins/poll/test/javascripts/widgets/discourse-poll-standard-results-test.js.es6 +++ b/plugins/poll/test/javascripts/widgets/discourse-poll-standard-results-test.js.es6 @@ -19,8 +19,8 @@ widgetTest("options in descending order", { }, test(assert) { - assert.equal(this.$(".option .percentage:eq(0)").text(), "56%"); - assert.equal(this.$(".option .percentage:eq(1)").text(), "44%"); + assert.equal(find(".option .percentage:eq(0)").text(), "56%"); + assert.equal(find(".option .percentage:eq(1)").text(), "44%"); } }); @@ -38,8 +38,8 @@ widgetTest("options in ascending order", { }, test(assert) { - assert.equal(this.$(".option .percentage:eq(0)").text(), "56%"); - assert.equal(this.$(".option .percentage:eq(1)").text(), "44%"); + assert.equal(find(".option .percentage:eq(0)").text(), "56%"); + assert.equal(find(".option .percentage:eq(1)").text(), "44%"); } }); @@ -65,12 +65,12 @@ widgetTest("multiple options in descending order", { }, test(assert) { - assert.equal(this.$(".option .percentage:eq(0)").text(), "41%"); - assert.equal(this.$(".option .percentage:eq(1)").text(), "33%"); - assert.equal(this.$(".option .percentage:eq(2)").text(), "16%"); - assert.equal(this.$(".option .percentage:eq(3)").text(), "8%"); - assert.equal(this.$(".option span:nth-child(2):eq(3)").text(), "a"); - assert.equal(this.$(".option .percentage:eq(4)").text(), "8%"); - assert.equal(this.$(".option span:nth-child(2):eq(4)").text(), "b"); + assert.equal(find(".option .percentage:eq(0)").text(), "41%"); + assert.equal(find(".option .percentage:eq(1)").text(), "33%"); + assert.equal(find(".option .percentage:eq(2)").text(), "16%"); + assert.equal(find(".option .percentage:eq(3)").text(), "8%"); + assert.equal(find(".option span:nth-child(2):eq(3)").text(), "a"); + assert.equal(find(".option .percentage:eq(4)").text(), "8%"); + assert.equal(find(".option span:nth-child(2):eq(4)").text(), "b"); } }); diff --git a/test/javascripts/admin/components/themes-list-item-test.js.es6 b/test/javascripts/admin/components/themes-list-item-test.js.es6 index 82190fb0e70..d7506dc4c4c 100644 --- a/test/javascripts/admin/components/themes-list-item-test.js.es6 +++ b/test/javascripts/admin/components/themes-list-item-test.js.es6 @@ -11,7 +11,7 @@ componentTest("default theme", { test(assert) { assert.expect(1); - assert.equal(this.$(".d-icon-check").length, 1, "shows default theme icon"); + assert.equal(find(".d-icon-check").length, 1, "shows default theme icon"); } }); @@ -26,7 +26,7 @@ componentTest("pending updates", { test(assert) { assert.expect(1); - assert.equal(this.$(".d-icon-sync").length, 1, "shows pending update icon"); + assert.equal(find(".d-icon-sync").length, 1, "shows pending update icon"); } }); @@ -45,7 +45,7 @@ componentTest("broken theme", { test(assert) { assert.expect(1); assert.equal( - this.$(".d-icon-exclamation-circle").length, + find(".d-icon-exclamation-circle").length, 1, "shows broken theme icon" ); diff --git a/test/javascripts/admin/components/themes-list-test.js.es6 b/test/javascripts/admin/components/themes-list-test.js.es6 index 3842e8d8663..4eaba9b6e91 100644 --- a/test/javascripts/admin/components/themes-list-test.js.es6 +++ b/test/javascripts/admin/components/themes-list-test.js.es6 @@ -28,36 +28,36 @@ componentTest("current tab is themes", { test(assert) { assert.equal( - this.$(".themes-tab").hasClass("active"), + find(".themes-tab").hasClass("active"), true, "themes tab is active" ); assert.equal( - this.$(".components-tab").hasClass("active"), + find(".components-tab").hasClass("active"), false, "components tab is not active" ); assert.equal( - this.$(".inactive-indicator").index(), + find(".inactive-indicator").index(), -1, "there is no inactive themes separator when all themes are inactive" ); - assert.equal(this.$(".themes-list-item").length, 5, "displays all themes"); + assert.equal(find(".themes-list-item").length, 5, "displays all themes"); [2, 3].forEach(num => themes[num].set("user_selectable", true)); themes[4].set("default", true); this.set("themes", themes); const names = [4, 2, 3, 0, 1].map(num => themes[num].get("name")); // default theme always on top, followed by user-selectable ones and then the rest assert.deepEqual( - Array.from(this.$(".themes-list-item").find(".name")).map(node => + Array.from(find(".themes-list-item").find(".name")).map(node => node.innerText.trim() ), names, "sorts themes correctly" ); assert.equal( - this.$(".inactive-indicator").index(), + find(".inactive-indicator").index(), 3, "the separator is in the right location" ); @@ -65,19 +65,19 @@ componentTest("current tab is themes", { themes.forEach(theme => theme.set("user_selectable", true)); this.set("themes", themes); assert.equal( - this.$(".inactive-indicator").index(), + find(".inactive-indicator").index(), -1, "there is no inactive themes separator when all themes are user-selectable" ); this.set("themes", []); assert.equal( - this.$(".themes-list-item").length, + find(".themes-list-item").length, 1, "shows one entry with a message when there is nothing to display" ); assert.equal( - this.$(".themes-list-item span.empty") + find(".themes-list-item span.empty") .text() .trim(), I18n.t("admin.customize.theme.empty"), @@ -99,35 +99,35 @@ componentTest("current tab is components", { test(assert) { assert.equal( - this.$(".components-tab").hasClass("active"), + find(".components-tab").hasClass("active"), true, "components tab is active" ); assert.equal( - this.$(".themes-tab").hasClass("active"), + find(".themes-tab").hasClass("active"), false, "themes tab is not active" ); assert.equal( - this.$(".inactive-indicator").index(), + find(".inactive-indicator").index(), -1, "there is no separator" ); assert.equal( - this.$(".themes-list-item").length, + find(".themes-list-item").length, 5, "displays all components" ); this.set("components", []); assert.equal( - this.$(".themes-list-item").length, + find(".themes-list-item").length, 1, "shows one entry with a message when there is nothing to display" ); assert.equal( - this.$(".themes-list-item span.empty") + find(".themes-list-item span.empty") .text() .trim(), I18n.t("admin.customize.theme.empty"), diff --git a/test/javascripts/components/ace-editor-test.js.es6 b/test/javascripts/components/ace-editor-test.js.es6 index 7551a93da6b..d8f49be3464 100644 --- a/test/javascripts/components/ace-editor-test.js.es6 +++ b/test/javascripts/components/ace-editor-test.js.es6 @@ -6,7 +6,7 @@ componentTest("css editor", { template: '{{ace-editor mode="css"}}', test(assert) { assert.expect(1); - assert.ok(this.$(".ace_editor").length, "it renders the ace editor"); + assert.ok(find(".ace_editor").length, "it renders the ace editor"); } }); @@ -14,7 +14,7 @@ componentTest("html editor", { template: '{{ace-editor mode="html" content="wat"}}', test(assert) { assert.expect(1); - assert.ok(this.$(".ace_editor").length, "it renders the ace editor"); + assert.ok(find(".ace_editor").length, "it renders the ace editor"); } }); @@ -22,7 +22,7 @@ componentTest("sql editor", { template: '{{ace-editor mode="sql" content="SELECT * FROM users"}}', test(assert) { assert.expect(1); - assert.ok(this.$(".ace_editor").length, "it renders the ace editor"); + assert.ok(find(".ace_editor").length, "it renders the ace editor"); } }); @@ -30,7 +30,7 @@ componentTest("disabled editor", { template: '{{ace-editor mode="sql" content="SELECT * FROM users" disabled=true}}', test(assert) { - const $ace = this.$(".ace_editor"); + const $ace = find(".ace_editor"); assert.expect(3); assert.ok($ace.length, "it renders the ace editor"); assert.equal( diff --git a/test/javascripts/components/d-button-test.js.es6 b/test/javascripts/components/d-button-test.js.es6 index bcc207885c2..46038cd5b53 100644 --- a/test/javascripts/components/d-button-test.js.es6 +++ b/test/javascripts/components/d-button-test.js.es6 @@ -6,11 +6,11 @@ componentTest("icon only button", { test(assert) { assert.ok( - this.$("button.btn.btn-icon.no-text").length, + find("button.btn.btn-icon.no-text").length, "it has all the classes" ); - assert.ok(this.$("button .d-icon.d-icon-plus").length, "it has the icon"); - assert.equal(this.$("button").attr("tabindex"), "3", "it has the tabindex"); + assert.ok(find("button .d-icon.d-icon-plus").length, "it has the icon"); + assert.equal(find("button").attr("tabindex"), "3", "it has the tabindex"); } }); @@ -19,11 +19,11 @@ componentTest("icon and text button", { test(assert) { assert.ok( - this.$("button.btn.btn-icon-text").length, + find("button.btn.btn-icon-text").length, "it has all the classes" ); - assert.ok(this.$("button .d-icon.d-icon-plus").length, "it has the icon"); - assert.ok(this.$("button span.d-button-label").length, "it has the label"); + assert.ok(find("button .d-icon.d-icon-plus").length, "it has the icon"); + assert.ok(find("button span.d-button-label").length, "it has the label"); } }); @@ -31,8 +31,8 @@ componentTest("text only button", { template: '{{d-button label="topic.create"}}', test(assert) { - assert.ok(this.$("button.btn.btn-text").length, "it has all the classes"); - assert.ok(this.$("button span.d-button-label").length, "it has the label"); + assert.ok(find("button.btn.btn-text").length, "it has all the classes"); + assert.ok(find("button span.d-button-label").length, "it has the label"); } }); diff --git a/test/javascripts/components/d-editor-test.js.es6 b/test/javascripts/components/d-editor-test.js.es6 index cefbb859e39..746f32dfe28 100644 --- a/test/javascripts/components/d-editor-test.js.es6 +++ b/test/javascripts/components/d-editor-test.js.es6 @@ -7,12 +7,12 @@ componentTest("preview updates with markdown", { template: "{{d-editor value=value}}", async test(assert) { - assert.ok(this.$(".d-editor-button-bar").length); + assert.ok(find(".d-editor-button-bar").length); await fillIn(".d-editor-input", "hello **world**"); assert.equal(this.get("value"), "hello **world**"); assert.equal( - this.$(".d-editor-preview") + find(".d-editor-preview") .html() .trim(), "

hello world

" @@ -26,7 +26,7 @@ componentTest("preview sanitizes HTML", { async test(assert) { await fillIn(".d-editor-input", `">`); assert.equal( - this.$(".d-editor-preview") + find(".d-editor-preview") .html() .trim(), '

">

' @@ -43,7 +43,7 @@ componentTest("updating the value refreshes the preview", { async test(assert) { assert.equal( - this.$(".d-editor-preview") + find(".d-editor-preview") .html() .trim(), "

evil trout

" @@ -51,7 +51,7 @@ componentTest("updating the value refreshes the preview", { await this.set("value", "zogstrip"); assert.equal( - this.$(".d-editor-preview") + find(".d-editor-preview") .html() .trim(), "

zogstrip

" @@ -72,7 +72,7 @@ function testCase(title, testFunc) { this.set("value", "hello world."); }, test(assert) { - const textarea = jumpEnd(this.$("textarea.d-editor-input")[0]); + const textarea = jumpEnd(find("textarea.d-editor-input")[0]); testFunc.call(this, assert, textarea); } }); @@ -85,7 +85,7 @@ function composerTestCase(title, testFunc) { this.set("value", "hello world."); }, test(assert) { - const textarea = jumpEnd(this.$("textarea.d-editor-input")[0]); + const textarea = jumpEnd(find("textarea.d-editor-input")[0]); testFunc.call(this, assert, textarea); } }); @@ -196,13 +196,13 @@ testCase(`italic with a multiline selection`, async function(assert, textarea) { }); testCase("link modal (cancel)", async function(assert) { - assert.equal(this.$(".insert-link.hidden").length, 1); + assert.equal(find(".insert-link.hidden").length, 1); await click("button.link"); - assert.equal(this.$(".insert-link.hidden").length, 0); + assert.equal(find(".insert-link.hidden").length, 0); await click(".insert-link button.btn-danger"); - assert.equal(this.$(".insert-link.hidden").length, 1); + assert.equal(find(".insert-link.hidden").length, 1); assert.equal(this.get("value"), "hello world."); }); @@ -213,7 +213,7 @@ testCase("link modal (simple link)", async function(assert, textarea) { await fillIn(".insert-link input.link-url", url); await click(".insert-link button.btn-primary"); - assert.equal(this.$(".insert-link.hidden").length, 1); + assert.equal(find(".insert-link.hidden").length, 1); assert.equal(this.get("value"), `hello world.[${url}](${url})`); assert.equal(textarea.selectionStart, 13); assert.equal(textarea.selectionEnd, 13 + url.length); @@ -234,11 +234,11 @@ testCase("link modal (simple link) with selected text", async function( textarea.selectionEnd = 12; await click("button.link"); - assert.equal(this.$("input.link-text")[0].value, "hello world."); + assert.equal(find("input.link-text")[0].value, "hello world."); await fillIn(".insert-link input.link-url", "http://eviltrout.com"); await click(".insert-link button.btn-primary"); - assert.equal(this.$(".insert-link.hidden").length, 1); + assert.equal(find(".insert-link.hidden").length, 1); assert.equal(this.get("value"), "[hello world.](http://eviltrout.com)"); }); @@ -247,7 +247,7 @@ testCase("link modal (link with description)", async function(assert) { await fillIn(".insert-link input.link-url", "http://eviltrout.com"); await fillIn(".insert-link input.link-text", "evil trout"); await click(".insert-link button.btn-primary"); - assert.equal(this.$(".insert-link.hidden").length, 1); + assert.equal(find(".insert-link.hidden").length, 1); assert.equal( this.get("value"), "hello world.[evil trout](http://eviltrout.com)" @@ -271,7 +271,7 @@ function xyz(x, y, z) { }, async test(assert) { - const textarea = this.$("textarea.d-editor-input")[0]; + const textarea = find("textarea.d-editor-input")[0]; textarea.selectionStart = 0; textarea.selectionEnd = textarea.value.length; @@ -296,7 +296,7 @@ componentTest("code button", { }, async test(assert) { - const textarea = jumpEnd(this.$("textarea.d-editor-input")[0]); + const textarea = jumpEnd(find("textarea.d-editor-input")[0]); await click("button.code"); assert.equal(this.get("value"), ` ${I18n.t("composer.code_text")}`); @@ -384,7 +384,7 @@ componentTest("code fences", { }, async test(assert) { - const textarea = jumpEnd(this.$("textarea.d-editor-input")[0]); + const textarea = jumpEnd(find("textarea.d-editor-input")[0]); await click("button.code"); assert.equal( @@ -496,7 +496,7 @@ componentTest("quote button - empty lines", { this.set("value", "one\n\ntwo\n\nthree"); }, async test(assert) { - const textarea = jumpEnd(this.$("textarea.d-editor-input")[0]); + const textarea = jumpEnd(find("textarea.d-editor-input")[0]); textarea.selectionStart = 0; @@ -517,7 +517,7 @@ componentTest("quote button - selecting empty lines", { this.set("value", "one\n\n\n\ntwo"); }, async test(assert) { - const textarea = jumpEnd(this.$("textarea.d-editor-input")[0]); + const textarea = jumpEnd(find("textarea.d-editor-input")[0]); textarea.selectionStart = 6; textarea.selectionEnd = 10; @@ -650,7 +650,7 @@ componentTest("clicking the toggle-direction button toggles the direction", { }, async test(assert) { - const textarea = this.$("textarea.d-editor-input"); + const textarea = find("textarea.d-editor-input"); await click("button.toggle-direction"); assert.equal(textarea.attr("dir"), "rtl"); await click("button.toggle-direction"); @@ -693,7 +693,7 @@ componentTest("emoji", { this.set("value", "hello world."); }, async test(assert) { - jumpEnd(this.$("textarea.d-editor-input")[0]); + jumpEnd(find("textarea.d-editor-input")[0]); await click("button.emoji"); await click( diff --git a/test/javascripts/components/image-uploader-test.js.es6 b/test/javascripts/components/image-uploader-test.js.es6 index 9f61761b685..684339ec61e 100644 --- a/test/javascripts/components/image-uploader-test.js.es6 +++ b/test/javascripts/components/image-uploader-test.js.es6 @@ -6,13 +6,13 @@ componentTest("with image", { async test(assert) { assert.equal( - this.$(".d-icon-far-image").length, + find(".d-icon-far-image").length, 1, "it displays the upload icon" ); assert.equal( - this.$(".d-icon-far-trash-alt").length, + find(".d-icon-far-trash-alt").length, 1, "it displays the trash icon" ); @@ -32,19 +32,19 @@ componentTest("without image", { test(assert) { assert.equal( - this.$(".d-icon-far-image").length, + find(".d-icon-far-image").length, 1, "it displays the upload icon" ); assert.equal( - this.$(".d-icon-far-trash-alt").length, + find(".d-icon-far-trash-alt").length, 0, "it does not display trash icon" ); assert.equal( - this.$(".image-uploader-lightbox-btn").length, + find(".image-uploader-lightbox-btn").length, 0, "it does not display the button to open image lightbox" ); diff --git a/test/javascripts/components/text-field-test.js.es6 b/test/javascripts/components/text-field-test.js.es6 index 6535c923974..dae51393b16 100644 --- a/test/javascripts/components/text-field-test.js.es6 +++ b/test/javascripts/components/text-field-test.js.es6 @@ -6,7 +6,7 @@ componentTest("renders correctly with no properties set", { template: `{{text-field}}`, test(assert) { - assert.ok(this.$("input[type=text]").length); + assert.ok(find("input[type=text]").length); } }); @@ -18,8 +18,8 @@ componentTest("support a placeholder", { }, test(assert) { - assert.ok(this.$("input[type=text]").length); - assert.equal(this.$("input").prop("placeholder"), "placeholder.i18n.key"); + assert.ok(find("input[type=text]").length); + assert.equal(find("input").prop("placeholder"), "placeholder.i18n.key"); } }); @@ -30,7 +30,7 @@ componentTest("sets the dir attribute to ltr for Hebrew text", { }, test(assert) { - assert.equal(this.$("input").attr("dir"), "rtl"); + assert.equal(find("input").attr("dir"), "rtl"); } }); @@ -41,6 +41,6 @@ componentTest("sets the dir attribute to ltr for English text", { }, test(assert) { - assert.equal(this.$("input").attr("dir"), "ltr"); + assert.equal(find("input").attr("dir"), "ltr"); } }); diff --git a/test/javascripts/widgets/actions-summary-test.js.es6 b/test/javascripts/widgets/actions-summary-test.js.es6 index 40aeb3fb456..b6e09b2c26e 100644 --- a/test/javascripts/widgets/actions-summary-test.js.es6 +++ b/test/javascripts/widgets/actions-summary-test.js.es6 @@ -13,11 +13,11 @@ widgetTest("listing actions", { }); }, async test(assert) { - assert.equal(this.$(".post-actions .post-action").length, 2); + assert.equal(find(".post-actions .post-action").length, 2); await click(".post-action:eq(0) .action-link a"); assert.equal( - this.$(".post-action:eq(0) img.avatar").length, + find(".post-action:eq(0) img.avatar").length, 1, "clicking it shows the user" ); @@ -37,7 +37,7 @@ widgetTest("undo", { this.set("undoPostAction", () => (this.undid = true)); }, async test(assert) { - assert.equal(this.$(".post-actions .post-action").length, 1); + assert.equal(find(".post-actions .post-action").length, 1); await click(".action-link.undo"); assert.ok(this.undid, "it triggered the action"); @@ -62,7 +62,7 @@ widgetTest("deferFlags", { this.on("deferPostActionFlags", () => (this.deferred = true)); }, async test(assert) { - assert.equal(this.$(".post-actions .post-action").length, 1); + assert.equal(find(".post-actions .post-action").length, 1); await click(".action-link.defer-flags"); assert.ok(this.deferred, "it triggered the action"); @@ -80,11 +80,11 @@ widgetTest("post deleted", { }, test(assert) { assert.ok( - this.$(".post-action .d-icon-far-trash-alt").length === 1, + find(".post-action .d-icon-far-trash-alt").length === 1, "it has the deleted icon" ); assert.ok( - this.$(".avatar[title=eviltrout]").length === 1, + find(".avatar[title=eviltrout]").length === 1, "it has the deleted by avatar" ); } diff --git a/test/javascripts/widgets/avatar-flair-test.js.es6 b/test/javascripts/widgets/avatar-flair-test.js.es6 index 9902efc0959..c5e86d9e0c3 100644 --- a/test/javascripts/widgets/avatar-flair-test.js.es6 +++ b/test/javascripts/widgets/avatar-flair-test.js.es6 @@ -12,10 +12,10 @@ widgetTest("avatar flair with an icon", { }); }, test(assert) { - assert.ok(this.$(".avatar-flair").length, "it has the tag"); - assert.ok(this.$("svg.d-icon-bars").length, "it has the svg icon"); + assert.ok(find(".avatar-flair").length, "it has the tag"); + assert.ok(find("svg.d-icon-bars").length, "it has the svg icon"); assert.equal( - this.$(".avatar-flair").attr("style"), + find(".avatar-flair").attr("style"), "background-color: #CC0000; color: #FFFFFF; ", "it has styles" ); @@ -30,7 +30,7 @@ widgetTest("avatar flair with an image", { }); }, test(assert) { - assert.ok(this.$(".avatar-flair").length, "it has the tag"); - assert.ok(this.$("svg").length === 0, "it does not have an svg icon"); + assert.ok(find(".avatar-flair").length, "it has the tag"); + assert.ok(find("svg").length === 0, "it does not have an svg icon"); } }); diff --git a/test/javascripts/widgets/button-test.js.es6 b/test/javascripts/widgets/button-test.js.es6 index bd4e57dd0cc..f3ee10cb5b1 100644 --- a/test/javascripts/widgets/button-test.js.es6 +++ b/test/javascripts/widgets/button-test.js.es6 @@ -11,11 +11,11 @@ widgetTest("icon only button", { test(assert) { assert.ok( - this.$("button.btn.btn-icon.no-text").length, + find("button.btn.btn-icon.no-text").length, "it has all the classes" ); assert.ok( - this.$("button .d-icon.d-icon-far-smile").length, + find("button .d-icon.d-icon-far-smile").length, "it has the icon" ); } @@ -30,11 +30,11 @@ widgetTest("icon and text button", { test(assert) { assert.ok( - this.$("button.btn.btn-icon-text").length, + find("button.btn.btn-icon-text").length, "it has all the classes" ); - assert.ok(this.$("button .d-icon.d-icon-plus").length, "it has the icon"); - assert.ok(this.$("button span.d-button-label").length, "it has the label"); + assert.ok(find("button .d-icon.d-icon-plus").length, "it has the icon"); + assert.ok(find("button span.d-button-label").length, "it has the label"); } }); @@ -46,7 +46,7 @@ widgetTest("text only button", { }, test(assert) { - assert.ok(this.$("button.btn.btn-text").length, "it has all the classes"); - assert.ok(this.$("button span.d-button-label").length, "it has the label"); + assert.ok(find("button.btn.btn-text").length, "it has all the classes"); + assert.ok(find("button span.d-button-label").length, "it has the label"); } }); diff --git a/test/javascripts/widgets/hamburger-menu-test.js.es6 b/test/javascripts/widgets/hamburger-menu-test.js.es6 index e94233df476..ce9155a2e14 100644 --- a/test/javascripts/widgets/hamburger-menu-test.js.es6 +++ b/test/javascripts/widgets/hamburger-menu-test.js.es6 @@ -17,8 +17,8 @@ widgetTest("prioritize faq", { }, test(assert) { - assert.ok(this.$(".faq-priority").length); - assert.ok(!this.$(".faq-link").length); + assert.ok(find(".faq-priority").length); + assert.ok(!find(".faq-link").length); } }); @@ -31,8 +31,8 @@ widgetTest("prioritize faq - user has read", { }, test(assert) { - assert.ok(!this.$(".faq-priority").length); - assert.ok(this.$(".faq-link").length); + assert.ok(!find(".faq-priority").length); + assert.ok(find(".faq-link").length); } }); @@ -44,7 +44,7 @@ widgetTest("staff menu - not staff", { }, test(assert) { - assert.ok(!this.$(".admin-link").length); + assert.ok(!find(".admin-link").length); } }); @@ -59,10 +59,10 @@ widgetTest("staff menu", { }, test(assert) { - assert.ok(this.$(".admin-link").length); - assert.ok(this.$(".flagged-posts-link").length); - assert.equal(this.$(".flagged-posts").text(), "3"); - assert.ok(!this.$(".settings-link").length); + assert.ok(find(".admin-link").length); + assert.ok(find(".flagged-posts-link").length); + assert.equal(find(".flagged-posts").text(), "3"); + assert.ok(!find(".settings-link").length); } }); @@ -74,7 +74,7 @@ widgetTest("staff menu - admin", { }, test(assert) { - assert.ok(this.$(".settings-link").length); + assert.ok(find(".settings-link").length); } }); @@ -90,8 +90,8 @@ widgetTest("queued posts", { }, test(assert) { - assert.ok(this.$(".queued-posts-link").length); - assert.equal(this.$(".queued-posts").text(), "5"); + assert.ok(find(".queued-posts-link").length); + assert.equal(find(".queued-posts").text(), "5"); } }); @@ -103,7 +103,7 @@ widgetTest("queued posts - disabled", { }, test(assert) { - assert.ok(!this.$(".queued-posts-link").length); + assert.ok(!find(".queued-posts-link").length); } }); @@ -111,8 +111,8 @@ widgetTest("logged in links", { template: '{{mount-widget widget="hamburger-menu"}}', test(assert) { - assert.ok(this.$(".new-topics-link").length); - assert.ok(this.$(".unread-topics-link").length); + assert.ok(find(".new-topics-link").length); + assert.ok(find(".unread-topics-link").length); } }); @@ -121,13 +121,13 @@ widgetTest("general links", { anonymous: true, test(assert) { - assert.ok(this.$("li[class='']").length === 0); - assert.ok(this.$(".latest-topics-link").length); - assert.ok(!this.$(".new-topics-link").length); - assert.ok(!this.$(".unread-topics-link").length); - assert.ok(this.$(".top-topics-link").length); - assert.ok(this.$(".badge-link").length); - assert.ok(this.$(".category-link").length > 0); + assert.ok(find("li[class='']").length === 0); + assert.ok(find(".latest-topics-link").length); + assert.ok(!find(".new-topics-link").length); + assert.ok(!find(".unread-topics-link").length); + assert.ok(find(".top-topics-link").length); + assert.ok(find(".badge-link").length); + assert.ok(find(".category-link").length > 0); } }); @@ -213,7 +213,7 @@ widgetTest("badges link - disabled", { }, test(assert) { - assert.ok(!this.$(".badge-link").length); + assert.ok(!find(".badge-link").length); } }); @@ -221,7 +221,7 @@ widgetTest("badges link", { template: '{{mount-widget widget="hamburger-menu"}}', test(assert) { - assert.ok(this.$(".badge-link").length); + assert.ok(find(".badge-link").length); } }); @@ -229,7 +229,7 @@ widgetTest("user directory link", { template: '{{mount-widget widget="hamburger-menu"}}', test(assert) { - assert.ok(this.$(".user-directory-link").length); + assert.ok(find(".user-directory-link").length); } }); @@ -241,7 +241,7 @@ widgetTest("user directory link - disabled", { }, test(assert) { - assert.ok(!this.$(".user-directory-link").length); + assert.ok(!find(".user-directory-link").length); } }); @@ -249,7 +249,7 @@ widgetTest("general links", { template: '{{mount-widget widget="hamburger-menu"}}', test(assert) { - assert.ok(this.$(".about-link").length); - assert.ok(this.$(".keyboard-shortcuts-link").length); + assert.ok(find(".about-link").length); + assert.ok(find(".keyboard-shortcuts-link").length); } }); diff --git a/test/javascripts/widgets/header-test.js.es6 b/test/javascripts/widgets/header-test.js.es6 index 548faa08c10..6ccbd60cc13 100644 --- a/test/javascripts/widgets/header-test.js.es6 +++ b/test/javascripts/widgets/header-test.js.es6 @@ -5,8 +5,8 @@ moduleForWidget("header"); widgetTest("rendering basics", { template: '{{mount-widget widget="header"}}', test(assert) { - assert.ok(this.$("header.d-header").length); - assert.ok(this.$("#site-logo").length); + assert.ok(find("header.d-header").length); + assert.ok(find("#site-logo").length); } }); @@ -22,8 +22,8 @@ widgetTest("sign up / login buttons", { }, async test(assert) { - assert.ok(this.$("button.sign-up-button").length); - assert.ok(this.$("button.login-button").length); + assert.ok(find("button.sign-up-button").length); + assert.ok(find("button.login-button").length); await click("button.sign-up-button"); assert.ok(this.signupShown); diff --git a/test/javascripts/widgets/home-logo-test.js.es6 b/test/javascripts/widgets/home-logo-test.js.es6 index f8bbbfe1657..9e8ff183067 100644 --- a/test/javascripts/widgets/home-logo-test.js.es6 +++ b/test/javascripts/widgets/home-logo-test.js.es6 @@ -17,11 +17,11 @@ widgetTest("basics", { }, test(assert) { - assert.ok(this.$(".title").length === 1); + assert.ok(find(".title").length === 1); - assert.ok(this.$("img#site-logo.logo-big").length === 1); - assert.equal(this.$("#site-logo").attr("src"), bigLogo); - assert.equal(this.$("#site-logo").attr("alt"), title); + assert.ok(find("img#site-logo.logo-big").length === 1); + assert.equal(find("#site-logo").attr("src"), bigLogo); + assert.equal(find("#site-logo").attr("alt"), title); } }); @@ -35,9 +35,9 @@ widgetTest("basics - minimized", { }, test(assert) { - assert.ok(this.$("img.logo-small").length === 1); - assert.equal(this.$("img.logo-small").attr("src"), smallLogo); - assert.equal(this.$("img.logo-small").attr("alt"), title); + assert.ok(find("img.logo-small").length === 1); + assert.equal(find("img.logo-small").attr("src"), smallLogo); + assert.equal(find("img.logo-small").attr("alt"), title); } }); @@ -51,8 +51,8 @@ widgetTest("no logo", { }, test(assert) { - assert.ok(this.$("h1#site-text-logo.text-logo").length === 1); - assert.equal(this.$("#site-text-logo").text(), title); + assert.ok(find("h1#site-text-logo.text-logo").length === 1); + assert.equal(find("#site-text-logo").text(), title); } }); @@ -66,7 +66,7 @@ widgetTest("no logo - minimized", { }, test(assert) { - assert.ok(this.$(".d-icon-home").length === 1); + assert.ok(find(".d-icon-home").length === 1); } }); @@ -79,8 +79,8 @@ widgetTest("mobile logo", { }, test(assert) { - assert.ok(this.$("img#site-logo.logo-big").length === 1); - assert.equal(this.$("#site-logo").attr("src"), mobileLogo); + assert.ok(find("img#site-logo.logo-big").length === 1); + assert.equal(find("#site-logo").attr("src"), mobileLogo); } }); @@ -92,8 +92,8 @@ widgetTest("mobile without logo", { }, test(assert) { - assert.ok(this.$("img#site-logo.logo-big").length === 1); - assert.equal(this.$("#site-logo").attr("src"), bigLogo); + assert.ok(find("img#site-logo.logo-big").length === 1); + assert.equal(find("#site-logo").attr("src"), bigLogo); } }); @@ -108,9 +108,9 @@ widgetTest("basics, subfolder", { }, test(assert) { - assert.ok(this.$("img#site-logo.logo-big").length === 1); - assert.equal(this.$("#site-logo").attr("src"), `/forum${bigLogo}`); - assert.equal(this.$("#site-logo").attr("alt"), title); + assert.ok(find("img#site-logo.logo-big").length === 1); + assert.equal(find("#site-logo").attr("src"), `/forum${bigLogo}`); + assert.equal(find("#site-logo").attr("alt"), title); } }); @@ -125,9 +125,9 @@ widgetTest("basics, subfolder - minimized", { }, test(assert) { - assert.ok(this.$("img.logo-small").length === 1); - assert.equal(this.$("img.logo-small").attr("src"), `/forum${smallLogo}`); - assert.equal(this.$("img.logo-small").attr("alt"), title); + assert.ok(find("img.logo-small").length === 1); + assert.equal(find("img.logo-small").attr("src"), `/forum${smallLogo}`); + assert.equal(find("img.logo-small").attr("alt"), title); } }); @@ -141,7 +141,7 @@ widgetTest("mobile logo, subfolder", { }, test(assert) { - assert.ok(this.$("img#site-logo.logo-big").length === 1); - assert.equal(this.$("#site-logo").attr("src"), `/forum${mobileLogo}`); + assert.ok(find("img#site-logo.logo-big").length === 1); + assert.equal(find("#site-logo").attr("src"), `/forum${mobileLogo}`); } }); diff --git a/test/javascripts/widgets/post-links-test.js.es6 b/test/javascripts/widgets/post-links-test.js.es6 index 4dce86ea4b5..1b6de7d698e 100644 --- a/test/javascripts/widgets/post-links-test.js.es6 +++ b/test/javascripts/widgets/post-links-test.js.es6 @@ -23,7 +23,7 @@ widgetTest("duplicate links", { }, test(assert) { assert.equal( - this.$(".post-links a.track-link").length, + find(".post-links a.track-link").length, 1, "it hides the dupe link" ); @@ -47,8 +47,8 @@ widgetTest("collapsed links", { }); }, async test(assert) { - assert.ok(this.$(".expand-links").length === 1, "collapsed by default"); + assert.ok(find(".expand-links").length === 1, "collapsed by default"); await click("a.expand-links"); - assert.equal(this.$(".post-links a.track-link").length, 7); + assert.equal(find(".post-links a.track-link").length, 7); } }); diff --git a/test/javascripts/widgets/post-stream-test.js.es6 b/test/javascripts/widgets/post-stream-test.js.es6 index 040084efc46..ed52e1127da 100644 --- a/test/javascripts/widgets/post-stream-test.js.es6 +++ b/test/javascripts/widgets/post-stream-test.js.es6 @@ -61,55 +61,55 @@ postStreamTest("basics", { }, test(assert) { - assert.equal(this.$(".post-stream").length, 1); - assert.equal(this.$(".topic-post").length, 6, "renders all posts"); + assert.equal(find(".post-stream").length, 1); + assert.equal(find(".topic-post").length, 6, "renders all posts"); // look for special class bindings assert.equal( - this.$(".topic-post:eq(0).topic-owner").length, + find(".topic-post:eq(0).topic-owner").length, 1, "it applies the topic owner class" ); assert.equal( - this.$(".topic-post:eq(0).group-trout").length, + find(".topic-post:eq(0).group-trout").length, 1, "it applies the primary group class" ); assert.equal( - this.$(".topic-post:eq(0).regular").length, + find(".topic-post:eq(0).regular").length, 1, "it applies the regular class" ); assert.equal( - this.$(".topic-post:eq(1).moderator").length, + find(".topic-post:eq(1).moderator").length, 1, "it applies the moderator class" ); assert.equal( - this.$(".topic-post:eq(2).post-hidden").length, + find(".topic-post:eq(2).post-hidden").length, 1, "it applies the hidden class" ); assert.equal( - this.$(".topic-post:eq(3).whisper").length, + find(".topic-post:eq(3).whisper").length, 1, "it applies the whisper class" ); assert.equal( - this.$(".topic-post:eq(4).wiki").length, + find(".topic-post:eq(4).wiki").length, 1, "it applies the wiki class" ); // it renders an article for the body with appropriate attributes - assert.equal(this.$("article#post_2").length, 1); - assert.equal(this.$("article[data-user-id=123]").length, 1); - assert.equal(this.$("article[data-post-id=3]").length, 1); - assert.equal(this.$("article#post_5.via-email").length, 1); - assert.equal(this.$("article#post_6.is-auto-generated").length, 1); + assert.equal(find("article#post_2").length, 1); + assert.equal(find("article[data-user-id=123]").length, 1); + assert.equal(find("article[data-post-id=3]").length, 1); + assert.equal(find("article#post_5.via-email").length, 1); + assert.equal(find("article#post_6.is-auto-generated").length, 1); assert.equal( - this.$("article:eq(0) .main-avatar").length, + find("article:eq(0) .main-avatar").length, 1, "renders the main avatar" ); @@ -131,12 +131,12 @@ postStreamTest("deleted posts", { test(assert) { assert.equal( - this.$(".topic-post.deleted").length, + find(".topic-post.deleted").length, 1, "it applies the deleted class" ); assert.equal( - this.$(".deleted-user-avatar").length, + find(".deleted-user-avatar").length, 1, "it has the trash avatar" ); diff --git a/test/javascripts/widgets/post-test.js.es6 b/test/javascripts/widgets/post-test.js.es6 index 3ad9d7cdc86..12b5726ff14 100644 --- a/test/javascripts/widgets/post-test.js.es6 +++ b/test/javascripts/widgets/post-test.js.es6 @@ -8,11 +8,11 @@ widgetTest("basic elements", { this.set("args", { shareUrl: "/example", post_number: 1 }); }, test(assert) { - assert.ok(this.$(".names").length, "includes poster name"); + assert.ok(find(".names").length, "includes poster name"); - assert.ok(this.$("a.post-date").length, "includes post date"); - assert.ok(this.$("a.post-date[data-share-url]").length); - assert.ok(this.$("a.post-date[data-post-number]").length); + assert.ok(find("a.post-date").length, "includes post date"); + assert.ok(find("a.post-date[data-share-url]").length); + assert.ok(find("a.post-date[data-post-number]").length); } }); @@ -109,8 +109,8 @@ widgetTest("whisper", { this.set("args", { isWhisper: true }); }, test(assert) { - assert.ok(this.$(".topic-post.whisper").length === 1); - assert.ok(this.$(".post-info.whisper").length === 1); + assert.ok(find(".topic-post.whisper").length === 1); + assert.ok(find(".post-info.whisper").length === 1); } }); @@ -129,18 +129,18 @@ widgetTest("like count button", { this.set("args", { likeCount: 1 }); }, async test(assert) { - assert.ok(this.$("button.like-count").length === 1); - assert.ok(this.$(".who-liked").length === 0); + assert.ok(find("button.like-count").length === 1); + assert.ok(find(".who-liked").length === 0); // toggle it on await click("button.like-count"); - assert.ok(this.$(".who-liked").length === 1); - assert.ok(this.$(".who-liked a.trigger-user-card").length === 1); + assert.ok(find(".who-liked").length === 1); + assert.ok(find(".who-liked a.trigger-user-card").length === 1); // toggle it off await click("button.like-count"); - assert.ok(this.$(".who-liked").length === 0); - assert.ok(this.$(".who-liked a.trigger-user-card").length === 0); + assert.ok(find(".who-liked").length === 0); + assert.ok(find(".who-liked a.trigger-user-card").length === 0); } }); @@ -150,7 +150,7 @@ widgetTest(`like count with no likes`, { this.set("args", { likeCount: 0 }); }, test(assert) { - assert.ok(this.$("button.like-count").length === 0); + assert.ok(find("button.like-count").length === 0); } }); @@ -161,7 +161,7 @@ widgetTest("share button", { }, test(assert) { assert.ok( - !!this.$(".actions button[data-share-url]").length, + !!find(".actions button[data-share-url]").length, "it renders a share button" ); } @@ -179,18 +179,18 @@ widgetTest("liking", { }); }, async test(assert) { - assert.ok(!!this.$(".actions button.like").length); - assert.ok(this.$(".actions button.like-count").length === 0); + assert.ok(!!find(".actions button.like").length); + assert.ok(find(".actions button.like-count").length === 0); await click(".actions button.like"); - assert.ok(!this.$(".actions button.like").length); - assert.ok(!!this.$(".actions button.has-like").length); - assert.ok(this.$(".actions button.like-count").length === 1); + assert.ok(!find(".actions button.like").length); + assert.ok(!!find(".actions button.has-like").length); + assert.ok(find(".actions button.like-count").length === 1); await click(".actions button.has-like"); - assert.ok(!!this.$(".actions button.like").length); - assert.ok(!this.$(".actions button.has-like").length); - assert.ok(this.$(".actions button.like-count").length === 0); + assert.ok(!!find(".actions button.like").length); + assert.ok(!find(".actions button.has-like").length); + assert.ok(find(".actions button.like-count").length === 0); } }); @@ -204,11 +204,11 @@ widgetTest("anon liking", { this.on("showLogin", () => (this.loginShown = true)); }, async test(assert) { - assert.ok(!!this.$(".actions button.like").length); - assert.ok(this.$(".actions button.like-count").length === 0); + assert.ok(!!find(".actions button.like").length); + assert.ok(find(".actions button.like-count").length === 0); assert.equal( - this.$("button.like").attr("title"), + find("button.like").attr("title"), I18n.t("post.controls.like"), `shows the right button title for anonymous users` ); @@ -237,7 +237,7 @@ widgetTest(`edit button - can't edit`, { this.set("args", { canEdit: false }); }, test(assert) { - assert.equal(this.$("button.edit").length, 0, `button is not displayed`); + assert.equal(find("button.edit").length, 0, `button is not displayed`); } }); @@ -273,7 +273,7 @@ widgetTest(`delete topic button - can't delete`, { this.set("args", { canDeleteTopic: false }); }, test(assert) { - assert.equal(this.$("button.delete").length, 0, `button is not displayed`); + assert.equal(find("button.delete").length, 0, `button is not displayed`); } }); @@ -290,9 +290,9 @@ widgetTest( }, test(assert) { - assert.equal(this.$("button.delete").length, 1, `button is displayed`); + assert.equal(find("button.delete").length, 1, `button is displayed`); assert.equal( - this.$("button.delete").attr("title"), + find("button.delete").attr("title"), I18n.t("post.controls.delete_topic_disallowed"), `shows the right button title for users without permissions` ); @@ -319,7 +319,7 @@ widgetTest(`recover topic button - can't recover`, { this.set("args", { canRecoverTopic: false }); }, test(assert) { - assert.equal(this.$("button.recover").length, 0, `button is not displayed`); + assert.equal(find("button.recover").length, 0, `button is not displayed`); } }); @@ -342,7 +342,7 @@ widgetTest(`delete post button - can't delete`, { this.set("args", { canDelete: false }); }, test(assert) { - assert.equal(this.$("button.delete").length, 0, `button is not displayed`); + assert.equal(find("button.delete").length, 0, `button is not displayed`); } }); @@ -365,7 +365,7 @@ widgetTest(`recover post button - can't recover`, { this.set("args", { canRecover: false }); }, test(assert) { - assert.equal(this.$("button.recover").length, 0, `button is not displayed`); + assert.equal(find("button.recover").length, 0, `button is not displayed`); } }); @@ -377,7 +377,7 @@ widgetTest(`flagging`, { this.on("showFlags", () => (this.flagsShown = true)); }, async test(assert) { - assert.ok(this.$("button.create-flag").length === 1); + assert.ok(find("button.create-flag").length === 1); await click("button.create-flag"); assert.ok(this.flagsShown, "it triggered the action"); @@ -390,7 +390,7 @@ widgetTest(`flagging: can't flag`, { this.set("args", { canFlag: false }); }, test(assert) { - assert.ok(this.$("button.create-flag").length === 0); + assert.ok(find("button.create-flag").length === 0); } }); @@ -400,7 +400,7 @@ widgetTest(`flagging: can't flag when post is hidden`, { this.set("args", { canFlag: true, hidden: true }); }, test(assert) { - assert.ok(this.$("button.create-flag").length === 0); + assert.ok(find("button.create-flag").length === 0); } }); @@ -410,7 +410,7 @@ widgetTest(`read indicator`, { this.set("args", { read: true }); }, test(assert) { - assert.ok(this.$(".read-state.read").length); + assert.ok(find(".read-state.read").length); } }); @@ -420,7 +420,7 @@ widgetTest(`unread indicator`, { this.set("args", { read: false }); }, test(assert) { - assert.ok(this.$(".read-state").length); + assert.ok(find(".read-state").length); } }); @@ -434,9 +434,9 @@ widgetTest("reply directly above (supressed)", { }); }, test(assert) { - assert.equal(this.$("a.reply-to-tab").length, 0, "hides the tab"); + assert.equal(find("a.reply-to-tab").length, 0, "hides the tab"); assert.equal( - this.$(".avoid-tab").length, + find(".avoid-tab").length, 0, "doesn't have the avoid tab class" ); @@ -453,8 +453,8 @@ widgetTest("reply a few posts above (supressed)", { }); }, test(assert) { - assert.ok(this.$("a.reply-to-tab").length, "shows the tab"); - assert.equal(this.$(".avoid-tab").length, 1, "has the avoid tab class"); + assert.ok(find("a.reply-to-tab").length, "shows the tab"); + assert.equal(find(".avoid-tab").length, 1, "has the avoid tab class"); } }); @@ -469,10 +469,10 @@ widgetTest("reply directly above", { this.siteSettings.suppress_reply_directly_above = false; }, async test(assert) { - assert.equal(this.$(".avoid-tab").length, 1, "has the avoid tab class"); + assert.equal(find(".avoid-tab").length, 1, "has the avoid tab class"); await click("a.reply-to-tab"); - assert.equal(this.$("section.embedded-posts.top .cooked").length, 1); - assert.equal(this.$("section.embedded-posts .d-icon-arrow-up").length, 1); + assert.equal(find("section.embedded-posts.top .cooked").length, 1); + assert.equal(find("section.embedded-posts .d-icon-arrow-up").length, 1); } }); @@ -497,7 +497,7 @@ widgetTest("expand first post", { }, async test(assert) { await click(".topic-body .expand-post"); - assert.equal(this.$(".expand-post").length, 0, "button is gone"); + assert.equal(find(".expand-post").length, 0, "button is gone"); } }); @@ -507,8 +507,8 @@ widgetTest("can't bookmark", { this.set("args", { canBookmark: false }); }, test(assert) { - assert.equal(this.$("button.bookmark").length, 0); - assert.equal(this.$("button.bookmarked").length, 0); + assert.equal(find("button.bookmark").length, 0); + assert.equal(find("button.bookmarked").length, 0); } }); @@ -522,11 +522,11 @@ widgetTest("bookmark", { this.on("toggleBookmark", () => (args.bookmarked = true)); }, async test(assert) { - assert.equal(this.$(".post-menu-area .bookmark").length, 1); - assert.equal(this.$("button.bookmarked").length, 0); + assert.equal(find(".post-menu-area .bookmark").length, 1); + assert.equal(find("button.bookmarked").length, 0); await click("button.bookmark"); - assert.equal(this.$("button.bookmarked").length, 1); + assert.equal(find("button.bookmarked").length, 1); } }); @@ -536,7 +536,7 @@ widgetTest("can't show admin menu when you can't manage", { this.set("args", { canManage: false }); }, test(assert) { - assert.equal(this.$(".post-menu-area .show-post-admin-menu").length, 0); + assert.equal(find(".post-menu-area .show-post-admin-menu").length, 0); } }); @@ -546,12 +546,12 @@ widgetTest("show admin menu", { this.set("args", { canManage: true }); }, async test(assert) { - assert.equal(this.$(".post-admin-menu").length, 0); + assert.equal(find(".post-admin-menu").length, 0); await click(".post-menu-area .show-post-admin-menu"); - assert.equal(this.$(".post-admin-menu").length, 1, "it shows the popup"); + assert.equal(find(".post-admin-menu").length, 1, "it shows the popup"); await click(".post-menu-area"); assert.equal( - this.$(".post-admin-menu").length, + find(".post-admin-menu").length, 0, "clicking outside clears the popup" ); @@ -571,7 +571,7 @@ widgetTest("toggle moderator post", { await click(".post-admin-menu .toggle-post-type"); assert.ok(this.toggled); - assert.equal(this.$(".post-admin-menu").length, 0, "also hides the menu"); + assert.equal(find(".post-admin-menu").length, 0, "also hides the menu"); } }); widgetTest("toggle moderator post", { @@ -587,7 +587,7 @@ widgetTest("toggle moderator post", { await click(".post-admin-menu .toggle-post-type"); assert.ok(this.toggled); - assert.equal(this.$(".post-admin-menu").length, 0, "also hides the menu"); + assert.equal(find(".post-admin-menu").length, 0, "also hides the menu"); } }); @@ -602,7 +602,7 @@ widgetTest("rebake post", { await click(".post-menu-area .show-post-admin-menu"); await click(".post-admin-menu .rebuild-html"); assert.ok(this.baked); - assert.equal(this.$(".post-admin-menu").length, 0, "also hides the menu"); + assert.equal(find(".post-admin-menu").length, 0, "also hides the menu"); } }); @@ -617,7 +617,7 @@ widgetTest("unhide post", { await click(".post-menu-area .show-post-admin-menu"); await click(".post-admin-menu .unhide-post"); assert.ok(this.unhidden); - assert.equal(this.$(".post-admin-menu").length, 0, "also hides the menu"); + assert.equal(find(".post-admin-menu").length, 0, "also hides the menu"); } }); @@ -633,7 +633,7 @@ widgetTest("change owner", { await click(".post-menu-area .show-post-admin-menu"); await click(".post-admin-menu .change-owner"); assert.ok(this.owned); - assert.equal(this.$(".post-admin-menu").length, 0, "also hides the menu"); + assert.equal(find(".post-admin-menu").length, 0, "also hides the menu"); } }); @@ -656,7 +656,7 @@ widgetTest("reply - without permissions", { this.set("args", { canCreatePost: false }); }, test(assert) { - assert.equal(this.$(".post-controls .create").length, 0); + assert.equal(find(".post-controls .create").length, 0); } }); @@ -666,7 +666,7 @@ widgetTest("replies - no replies", { this.set("args", { replyCount: 0 }); }, test(assert) { - assert.equal(this.$("button.show-replies").length, 0); + assert.equal(find("button.show-replies").length, 0); } }); @@ -677,7 +677,7 @@ widgetTest("replies - multiple replies", { this.set("args", { replyCount: 2, replyDirectlyBelow: true }); }, test(assert) { - assert.equal(this.$("button.show-replies").length, 1); + assert.equal(find("button.show-replies").length, 1); } }); @@ -688,7 +688,7 @@ widgetTest("replies - one below, suppressed", { this.set("args", { replyCount: 1, replyDirectlyBelow: true }); }, test(assert) { - assert.equal(this.$("button.show-replies").length, 0); + assert.equal(find("button.show-replies").length, 0); } }); @@ -700,8 +700,8 @@ widgetTest("replies - one below, not suppressed", { }, async test(assert) { await click("button.show-replies"); - assert.equal(this.$("section.embedded-posts.bottom .cooked").length, 1); - assert.equal(this.$("section.embedded-posts .d-icon-arrow-down").length, 1); + assert.equal(find("section.embedded-posts.bottom .cooked").length, 1); + assert.equal(find("section.embedded-posts .d-icon-arrow-down").length, 1); } }); @@ -711,7 +711,7 @@ widgetTest("topic map not shown", { this.set("args", { showTopicMap: false }); }, test(assert) { - assert.equal(this.$(".topic-map").length, 0); + assert.equal(find(".topic-map").length, 0); } }); @@ -726,14 +726,14 @@ widgetTest("topic map - few posts", { }, async test(assert) { assert.equal( - this.$("li.avatars a.poster").length, + find("li.avatars a.poster").length, 0, "shows no participants when collapsed" ); await click("nav.buttons button"); assert.equal( - this.$(".topic-map-expanded a.poster").length, + find(".topic-map-expanded a.poster").length, 2, "shows all when expanded" ); @@ -757,19 +757,19 @@ widgetTest("topic map - participants", { }, async test(assert) { assert.equal( - this.$("li.avatars a.poster").length, + find("li.avatars a.poster").length, 3, "limits to three participants" ); await click("nav.buttons button"); - assert.equal(this.$("li.avatars a.poster").length, 0); + assert.equal(find("li.avatars a.poster").length, 0); assert.equal( - this.$(".topic-map-expanded a.poster").length, + find(".topic-map-expanded a.poster").length, 4, "shows all when expanded" ); - assert.equal(this.$("a.poster.toggled").length, 2, "two are toggled"); + assert.equal(find("a.poster.toggled").length, 2, "two are toggled"); } }); @@ -789,23 +789,23 @@ widgetTest("topic map - links", { }); }, async test(assert) { - assert.equal(this.$(".topic-map").length, 1); - assert.equal(this.$(".map.map-collapsed").length, 1); - assert.equal(this.$(".topic-map-expanded").length, 0); + assert.equal(find(".topic-map").length, 1); + assert.equal(find(".map.map-collapsed").length, 1); + assert.equal(find(".topic-map-expanded").length, 0); await click("nav.buttons button"); - assert.equal(this.$(".map.map-collapsed").length, 0); - assert.equal(this.$(".topic-map .d-icon-chevron-up").length, 1); - assert.equal(this.$(".topic-map-expanded").length, 1); + assert.equal(find(".map.map-collapsed").length, 0); + assert.equal(find(".topic-map .d-icon-chevron-up").length, 1); + assert.equal(find(".topic-map-expanded").length, 1); assert.equal( - this.$(".topic-map-expanded .topic-link").length, + find(".topic-map-expanded .topic-link").length, 5, "it limits the links displayed" ); await click(".link-summary button"); assert.equal( - this.$(".topic-map-expanded .topic-link").length, + find(".topic-map-expanded .topic-link").length, 6, "all links now shown" ); @@ -818,7 +818,7 @@ widgetTest("topic map - no summary", { this.set("args", { showTopicMap: true }); }, test(assert) { - assert.equal(this.$(".toggle-summary").length, 0); + assert.equal(find(".toggle-summary").length, 0); } }); @@ -830,7 +830,7 @@ widgetTest("topic map - has summary", { this.on("toggleSummary", () => (this.summaryToggled = true)); }, async test(assert) { - assert.equal(this.$(".toggle-summary").length, 1); + assert.equal(find(".toggle-summary").length, 1); await click(".toggle-summary button"); assert.ok(this.summaryToggled); @@ -848,7 +848,7 @@ widgetTest("pm map", { }); }, test(assert) { - assert.equal(this.$(".private-message-map").length, 1); - assert.equal(this.$(".private-message-map .user").length, 1); + assert.equal(find(".private-message-map").length, 1); + assert.equal(find(".private-message-map .user").length, 1); } }); diff --git a/test/javascripts/widgets/poster-name-test.js.es6 b/test/javascripts/widgets/poster-name-test.js.es6 index b150c333554..0801c2668b9 100644 --- a/test/javascripts/widgets/poster-name-test.js.es6 +++ b/test/javascripts/widgets/poster-name-test.js.es6 @@ -13,12 +13,12 @@ widgetTest("basic rendering", { }); }, test(assert) { - assert.ok(this.$(".names").length); - assert.ok(this.$("span.username").length); - assert.ok(this.$("a[data-user-card=eviltrout]").length); - assert.equal(this.$(".username a").text(), "eviltrout"); - assert.equal(this.$(".full-name a").text(), "Robin Ward"); - assert.equal(this.$(".user-title").text(), "Trout Master"); + assert.ok(find(".names").length); + assert.ok(find("span.username").length); + assert.ok(find("a[data-user-card=eviltrout]").length); + assert.equal(find(".username a").text(), "eviltrout"); + assert.equal(find(".full-name a").text(), "Robin Ward"); + assert.equal(find(".user-title").text(), "Trout Master"); } }); @@ -36,12 +36,12 @@ widgetTest("extra classes and glyphs", { }); }, test(assert) { - assert.ok(this.$("span.staff").length); - assert.ok(this.$("span.admin").length); - assert.ok(this.$("span.moderator").length); - assert.ok(this.$(".d-icon-shield-alt").length); - assert.ok(this.$("span.new-user").length); - assert.ok(this.$("span.fish").length); + assert.ok(find("span.staff").length); + assert.ok(find("span.admin").length); + assert.ok(find("span.moderator").length); + assert.ok(find(".d-icon-shield-alt").length); + assert.ok(find("span.new-user").length); + assert.ok(find("span.fish").length); } }); @@ -52,7 +52,7 @@ widgetTest("disable display name on posts", { this.set("args", { username: "eviltrout", name: "Robin Ward" }); }, test(assert) { - assert.equal(this.$(".full-name").length, 0); + assert.equal(find(".full-name").length, 0); } }); @@ -64,6 +64,6 @@ widgetTest("doesn't render a name if it's similar to the username", { this.set("args", { username: "eviltrout", name: "evil-trout" }); }, test(assert) { - assert.equal(this.$(".second").length, 0); + assert.equal(find(".second").length, 0); } }); diff --git a/test/javascripts/widgets/user-menu-test.js.es6 b/test/javascripts/widgets/user-menu-test.js.es6 index 25d59f5a629..a878a470f4f 100644 --- a/test/javascripts/widgets/user-menu-test.js.es6 +++ b/test/javascripts/widgets/user-menu-test.js.es6 @@ -6,12 +6,12 @@ widgetTest("basics", { template: '{{mount-widget widget="user-menu"}}', test(assert) { - assert.ok(this.$(".user-menu").length); - assert.ok(this.$(".user-activity-link").length); - assert.ok(this.$(".user-bookmarks-link").length); - assert.ok(this.$(".user-preferences-link").length); - assert.ok(this.$(".notifications").length); - assert.ok(this.$(".dismiss-link").length); + assert.ok(find(".user-menu").length); + assert.ok(find(".user-activity-link").length); + assert.ok(find(".user-bookmarks-link").length); + assert.ok(find(".user-preferences-link").length); + assert.ok(find(".notifications").length); + assert.ok(find(".dismiss-link").length); } }); @@ -47,7 +47,7 @@ widgetTest("log out", { }, async test(assert) { - assert.ok(this.$(".logout").length); + assert.ok(find(".logout").length); await click(".logout"); assert.ok(this.loggedOut); @@ -61,7 +61,7 @@ widgetTest("private messages - disabled", { }, test(assert) { - assert.ok(!this.$(".user-pms-link").length); + assert.ok(!find(".user-pms-link").length); } }); @@ -72,7 +72,7 @@ widgetTest("private messages - enabled", { }, test(assert) { - assert.ok(this.$(".user-pms-link").length); + assert.ok(find(".user-pms-link").length); } }); @@ -89,7 +89,7 @@ widgetTest("anonymous", { }, async test(assert) { - assert.ok(this.$(".enable-anonymous").length); + assert.ok(find(".enable-anonymous").length); await click(".enable-anonymous"); assert.ok(this.anonymous); } @@ -103,7 +103,7 @@ widgetTest("anonymous - disabled", { }, test(assert) { - assert.ok(!this.$(".enable-anonymous").length); + assert.ok(!find(".enable-anonymous").length); } }); @@ -119,7 +119,7 @@ widgetTest("anonymous - switch back", { }, async test(assert) { - assert.ok(this.$(".disable-anonymous").length); + assert.ok(find(".disable-anonymous").length); await click(".disable-anonymous"); assert.ok(this.anonymous); } diff --git a/test/javascripts/widgets/widget-test.js.es6 b/test/javascripts/widgets/widget-test.js.es6 index c3c8ccbbc1e..4ffcfa2ad3b 100644 --- a/test/javascripts/widgets/widget-test.js.es6 +++ b/test/javascripts/widgets/widget-test.js.es6 @@ -18,7 +18,7 @@ widgetTest("widget attributes are passed in via args", { }, test(assert) { - assert.equal(this.$(".test").text(), "Hello Robin"); + assert.equal(find(".test").text(), "Hello Robin"); } }); @@ -34,7 +34,7 @@ widgetTest("hbs template - no tagName", { }, test(assert) { - assert.equal(this.$("div.test").text(), "Hello Robin"); + assert.equal(find("div.test").text(), "Hello Robin"); } }); @@ -51,7 +51,7 @@ widgetTest("hbs template - with tagName", { }, test(assert) { - assert.equal(this.$("div.test").text(), "Hello Robin"); + assert.equal(find("div.test").text(), "Hello Robin"); } }); @@ -71,10 +71,7 @@ widgetTest("buildClasses", { }, test(assert) { - assert.ok( - this.$(".test.static.cool-class").length, - "it has all the classes" - ); + assert.ok(find(".test.static.cool-class").length, "it has all the classes"); } }); @@ -94,8 +91,8 @@ widgetTest("buildAttributes", { }, test(assert) { - assert.ok(this.$(".test[data-evil=trout]").length); - assert.ok(this.$(".test[aria-label=accessibility]").length); + assert.ok(find(".test[data-evil=trout]").length); + assert.ok(find(".test[aria-label=accessibility]").length); } }); @@ -113,7 +110,7 @@ widgetTest("buildId", { }, test(assert) { - assert.ok(this.$("#test-1234").length); + assert.ok(find("#test-1234").length); } }); @@ -137,11 +134,11 @@ widgetTest("widget state", { }, async test(assert) { - assert.ok(this.$("button.test").length, "it renders the button"); - assert.equal(this.$("button.test").text(), "0 clicks"); + assert.ok(find("button.test").length, "it renders the button"); + assert.equal(find("button.test").text(), "0 clicks"); - await click(this.$("button")); - assert.equal(this.$("button.test").text(), "1 clicks"); + await click(find("button")); + assert.equal(find("button.test").text(), "1 clicks"); } }); @@ -173,15 +170,15 @@ widgetTest("widget update with promise", { async test(assert) { assert.equal( - this.$("button.test") + find("button.test") .text() .trim(), "No name" ); - await click(this.$("button")); + await click(find("button")); assert.equal( - this.$("button.test") + find("button.test") .text() .trim(), "Robin" @@ -202,8 +199,8 @@ widgetTest("widget attaching", { }, test(assert) { - assert.ok(this.$(".container").length, "renders container"); - assert.ok(this.$(".container .embedded").length, "renders attached"); + assert.ok(find(".container").length, "renders container"); + assert.ok(find(".container .embedded").length, "renders attached"); } }); @@ -217,7 +214,7 @@ widgetTest("handlebars d-icon", { }, test(assert) { - assert.equal(this.$(".d-icon-arrow-down").length, 1); + assert.equal(find(".d-icon-arrow-down").length, 1); } }); @@ -243,9 +240,9 @@ widgetTest("handlebars i18n", { test(assert) { // comin up - assert.equal(this.$("span.string").text(), "evil"); - assert.equal(this.$("span.var").text(), "trout"); - assert.equal(this.$("a").prop("title"), "evil"); + assert.equal(find("span.string").text(), "evil"); + assert.equal(find("span.var").text(), "trout"); + assert.equal(find("a").prop("title"), "evil"); } }); @@ -268,8 +265,8 @@ widgetTest("handlebars #each", { }, test(assert) { - assert.equal(this.$("ul li").length, 3); - assert.equal(this.$("ul li:eq(0)").text(), "one"); + assert.equal(find("ul li").length, 3); + assert.equal(find("ul li:eq(0)").text(), "one"); } }); @@ -294,9 +291,9 @@ widgetTest("widget decorating", { }, test(assert) { - assert.ok(this.$(".decorate").length); - assert.equal(this.$(".decorate b").text(), "before"); - assert.equal(this.$(".decorate i").text(), "after"); + assert.ok(find(".decorate").length); + assert.equal(find(".decorate b").text(), "before"); + assert.equal(find(".decorate i").text(), "after"); } }); @@ -312,7 +309,7 @@ widgetTest("widget settings", { }, test(assert) { - assert.equal(this.$(".settings").text(), "age is 36"); + assert.equal(find(".settings").text(), "age is 36"); } }); @@ -332,6 +329,6 @@ widgetTest("override settings", { }, test(assert) { - assert.equal(this.$(".settings").text(), "age is 37"); + assert.equal(find(".settings").text(), "age is 37"); } });