|
| 1 | +import { click, render } from "@ember/test-helpers"; |
| 2 | +import { module, test } from "qunit"; |
| 3 | +import EmptyTopicFilter from "discourse/components/empty-topic-filter"; |
| 4 | +import { setupRenderingTest } from "discourse/tests/helpers/component-test"; |
| 5 | + |
| 6 | +module("Integration | Component | EmptyTopicFilter", function (hooks) { |
| 7 | + setupRenderingTest(hooks); |
| 8 | + |
| 9 | + test("renders empty state with CTA when viewing topics with available replies", async function (assert) { |
| 10 | + this.currentUser.new_new_view_enabled = true; |
| 11 | + this.trackingCounts = { newReplies: 5, newTopics: 0 }; |
| 12 | + this.newListSubset = "topics"; |
| 13 | + this.actionCalled = false; |
| 14 | + this.changeNewListSubset = () => { |
| 15 | + this.set("actionCalled", true); |
| 16 | + }; |
| 17 | + |
| 18 | + await render( |
| 19 | + <template> |
| 20 | + <EmptyTopicFilter |
| 21 | + @newFilter={{true}} |
| 22 | + @newListSubset={{this.newListSubset}} |
| 23 | + @trackingCounts={{this.trackingCounts}} |
| 24 | + @changeNewListSubset={{this.changeNewListSubset}} |
| 25 | + /> |
| 26 | + </template> |
| 27 | + ); |
| 28 | + |
| 29 | + assert.dom(".empty-state__cta button").exists("CTA button is rendered"); |
| 30 | + assert |
| 31 | + .dom(".empty-state__cta button") |
| 32 | + .hasText(/replies/i, "CTA suggests browsing replies"); |
| 33 | + |
| 34 | + await click(".empty-state__cta button"); |
| 35 | + assert.true(this.actionCalled, "action is called when button is clicked"); |
| 36 | + }); |
| 37 | + |
| 38 | + test("renders empty state with CTA when viewing replies with available topics", async function (assert) { |
| 39 | + this.currentUser.new_new_view_enabled = true; |
| 40 | + this.trackingCounts = { newReplies: 0, newTopics: 5 }; |
| 41 | + this.newListSubset = "replies"; |
| 42 | + this.actionCalled = false; |
| 43 | + this.changeNewListSubset = () => { |
| 44 | + this.set("actionCalled", true); |
| 45 | + }; |
| 46 | + |
| 47 | + await render( |
| 48 | + <template> |
| 49 | + <EmptyTopicFilter |
| 50 | + @newFilter={{true}} |
| 51 | + @newListSubset={{this.newListSubset}} |
| 52 | + @trackingCounts={{this.trackingCounts}} |
| 53 | + @changeNewListSubset={{this.changeNewListSubset}} |
| 54 | + /> |
| 55 | + </template> |
| 56 | + ); |
| 57 | + |
| 58 | + assert.dom(".empty-state__cta button").exists("CTA button is rendered"); |
| 59 | + assert |
| 60 | + .dom(".empty-state__cta button") |
| 61 | + .hasText(/topics/i, "CTA suggests browsing topics"); |
| 62 | + |
| 63 | + await click(".empty-state__cta button"); |
| 64 | + assert.true(this.actionCalled, "action is called when button is clicked"); |
| 65 | + }); |
| 66 | + |
| 67 | + test("renders empty state with discovery.latest link when no alternative content available", async function (assert) { |
| 68 | + this.currentUser.new_new_view_enabled = true; |
| 69 | + this.trackingCounts = { newReplies: 0, newTopics: 0 }; |
| 70 | + this.newListSubset = "topics"; |
| 71 | + this.changeNewListSubset = () => {}; |
| 72 | + |
| 73 | + await render( |
| 74 | + <template> |
| 75 | + <EmptyTopicFilter |
| 76 | + @newFilter={{true}} |
| 77 | + @newListSubset={{this.newListSubset}} |
| 78 | + @trackingCounts={{this.trackingCounts}} |
| 79 | + @changeNewListSubset={{this.changeNewListSubset}} |
| 80 | + /> |
| 81 | + </template> |
| 82 | + ); |
| 83 | + |
| 84 | + assert.dom(".empty-state__cta button").exists("CTA button is rendered"); |
| 85 | + assert |
| 86 | + .dom(".empty-state__cta button") |
| 87 | + .hasText(/latest/i, "CTA links to latest topics"); |
| 88 | + }); |
| 89 | + |
| 90 | + test("renders empty state with discovery.latest link when new_new_view is disabled", async function (assert) { |
| 91 | + this.currentUser.new_new_view_enabled = false; |
| 92 | + this.trackingCounts = { newReplies: 5, newTopics: 0 }; |
| 93 | + this.newListSubset = "topics"; |
| 94 | + this.changeNewListSubset = () => {}; |
| 95 | + |
| 96 | + await render( |
| 97 | + <template> |
| 98 | + <EmptyTopicFilter |
| 99 | + @newFilter={{true}} |
| 100 | + @newListSubset={{this.newListSubset}} |
| 101 | + @trackingCounts={{this.trackingCounts}} |
| 102 | + @changeNewListSubset={{this.changeNewListSubset}} |
| 103 | + /> |
| 104 | + </template> |
| 105 | + ); |
| 106 | + |
| 107 | + assert.dom(".empty-state__cta button").exists("CTA button is rendered"); |
| 108 | + assert |
| 109 | + .dom(".empty-state__cta button") |
| 110 | + .hasText(/latest/i, "CTA links to latest topics"); |
| 111 | + }); |
| 112 | + |
| 113 | + test("renders empty state for unread filter", async function (assert) { |
| 114 | + this.currentUser.new_new_view_enabled = false; |
| 115 | + |
| 116 | + await render( |
| 117 | + <template><EmptyTopicFilter @unreadFilter={{true}} /></template> |
| 118 | + ); |
| 119 | + |
| 120 | + assert.dom(".empty-state").exists("empty state is rendered"); |
| 121 | + assert.dom(".empty-state__cta button").exists("CTA button is rendered"); |
| 122 | + }); |
| 123 | +}); |
0 commit comments