Skip to content

Commit f793af6

Browse files
authored
FIX: "browse latest topics" button in new new topics / replies subtabs (#36136)
wasn't working. The issue was that when we were in a subtab, and there was no more "new" topics or replies, the "ctaRoute" was shunted because we checked against "this.args.newListSubset" (which is always truthy in those subtabs). To fix it, I changed the conditionals to test against the presence of "this.ctaLabelWithAction.action" so that whenever the CTA button has an action, we don't use the route. When it doesn't have an action, we use the route. This is a follow up of 66179c6 Internal ref - t/168867
1 parent a8cfcfb commit f793af6

File tree

2 files changed

+127
-1
lines changed

2 files changed

+127
-1
lines changed

frontend/discourse/app/components/empty-topic-filter.gjs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,10 @@ export default class EmptyTopicFilter extends Component {
5050
}
5151

5252
get ctaRoute() {
53-
if (this.currentUser.new_new_view_enabled && this.args.newListSubset) {
53+
if (
54+
this.currentUser.new_new_view_enabled &&
55+
this.ctaLabelWithAction.action
56+
) {
5457
return;
5558
}
5659

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
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

Comments
 (0)