FEATURE: add category banner for why a user cannot post (#9576)

* FEATURE: add category banner for why a user cannot post

Adds a category banner for why a user is unable to post in a category.

Also adds an extra alert for the user when a user is unable to create a topic in a
category and they still try and click on the disabled-looking new topic
button.
This commit is contained in:
Jeff Wong
2020-04-30 07:39:11 -10:00
committed by GitHub
parent 03815f9795
commit 2cb9e85d14
16 changed files with 284 additions and 6 deletions

View File

@@ -0,0 +1,89 @@
import { acceptance } from "helpers/qunit-helpers";
import DiscoveryFixtures from "fixtures/discovery_fixtures";
acceptance("Category Banners", {
pretend(server, helper) {
server.get("/c/test-read-only-without-banner/5/l/latest.json", () => {
return helper.response(
DiscoveryFixtures["/latest_can_create_topic.json"]
);
});
server.get("/c/test-read-only-with-banner/6/l/latest.json", () => {
return helper.response(
DiscoveryFixtures["/latest_can_create_topic.json"]
);
});
},
loggedIn: true,
site: {
categories: [
{
id: 5,
name: "test read only without banner",
slug: "test-read-only-without-banner",
permission: null
},
{
id: 6,
name: "test read only with banner",
slug: "test-read-only-with-banner",
permission: null,
read_only_banner:
"You need to video yourself doing the secret handshake to post here"
}
]
}
});
QUnit.test("Does not display category banners when not set", async assert => {
await visit("/c/test-read-only-without-banner");
await click("#create-topic");
assert.ok(!visible(".bootbox.modal"), "it does not pop up a modal");
assert.ok(
!visible(".category-read-only-banner"),
"it does not show a banner"
);
});
QUnit.test("Displays category banners when set", async assert => {
await visit("/c/test-read-only-with-banner");
await click("#create-topic");
assert.ok(visible(".bootbox.modal"), "it pops up a modal");
await click(".modal-footer>.btn-primary");
assert.ok(!visible(".bootbox.modal"), "it closes the modal");
assert.ok(visible(".category-read-only-banner"), "it shows a banner");
});
acceptance("Anonymous Category Banners", {
pretend(server, helper) {
server.get("/c/test-read-only-with-banner/6/l/latest.json", () => {
return helper.response(
DiscoveryFixtures["/latest_can_create_topic.json"]
);
});
},
loggedIn: false,
site: {
categories: [
{
id: 6,
name: "test read only with banner",
slug: "test-read-only-with-banner",
permission: null,
read_only_banner:
"You need to video yourself doing the secret handshake to post here"
}
]
}
});
QUnit.test("Does not display category banners when set", async assert => {
await visit("/c/test-read-only-with-banner");
assert.ok(
!visible(".category-read-only-banner"),
"it does not show a banner"
);
});

View File

@@ -6120,5 +6120,107 @@ export default {
}
]
}
},
"/latest_can_create_topic.json": {
users: [
{
id: 1,
username: "tt1",
name: null,
avatar_template: "/letter_avatar_proxy/v4/letter/t/6de8d8/{size}.png"
}
],
primary_groups: [],
topic_list: {
can_create_topic: true,
draft: null,
draft_key: "new_topic",
draft_sequence: 0,
per_page: 30,
topics: [
{
id: 30,
title: "I am also creating a new topic here new topic",
fancy_title: "I am also creating a new topic here new topic",
slug: "i-am-also-creating-a-new-topic-here-new-topic",
posts_count: 6,
reply_count: 0,
highest_post_number: 6,
image_url: null,
created_at: "2020-04-27T23:47:44.218Z",
last_posted_at: "2020-04-28T22:45:47.529Z",
bumped: true,
bumped_at: "2020-04-28T22:02:20.215Z",
archetype: "regular",
unseen: false,
last_read_post_number: 5,
unread: 0,
new_posts: 0,
pinned: false,
unpinned: null,
visible: true,
closed: false,
archived: false,
notification_level: 1,
bookmarked: false,
liked: false,
tags: ["test", "test-tag"],
views: 6,
like_count: 0,
has_summary: false,
last_poster_username: "tt1",
category_id: 5,
pinned_globally: false,
featured_link: null,
posters: [
{
extras: "latest single",
description: "Original Poster, Most Recent Poster",
user_id: 1,
primary_group_id: null
}
]
},
{
id: 29,
title: "About the test category category",
fancy_title: "About the test category category",
slug: "about-the-test-category-category",
posts_count: 5,
reply_count: 0,
highest_post_number: 5,
image_url: null,
created_at: "2020-04-27T22:15:49.424Z",
last_posted_at: "2020-04-27T23:51:06.249Z",
bumped: true,
bumped_at: "2020-04-27T22:15:49.424Z",
archetype: "regular",
unseen: false,
pinned: false,
unpinned: null,
visible: true,
closed: false,
archived: false,
bookmarked: null,
liked: null,
tags: [],
views: 1,
like_count: 0,
has_summary: false,
last_poster_username: "tt1",
category_id: 5,
pinned_globally: false,
featured_link: null,
posters: [
{
extras: "latest single",
description: "Original Poster, Most Recent Poster",
user_id: 1,
primary_group_id: null
}
]
}
]
}
}
};