From ee60488e6aca4f9a720c60a1b083a46c365e5b60 Mon Sep 17 00:00:00 2001 From: Jeff Wong Date: Wed, 27 May 2020 16:57:56 -0700 Subject: [PATCH] DEV: add acceptance test for encoded subcategory follow-up on 63323bd7a8ff2128abf10c675bcad225dab13cd2 Add acceptance tests on ember routing to ensure that ember can route to a sub-category via slug-only. https://github.com/discourse/discourse/commit/63323bd7a8ff2128abf10c675bcad225dab13cd2 --- .../acceptance/encoded-category-test.js | 56 +++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 test/javascripts/acceptance/encoded-category-test.js diff --git a/test/javascripts/acceptance/encoded-category-test.js b/test/javascripts/acceptance/encoded-category-test.js new file mode 100644 index 0000000000..bc64c0825c --- /dev/null +++ b/test/javascripts/acceptance/encoded-category-test.js @@ -0,0 +1,56 @@ +import { acceptance } from "helpers/qunit-helpers"; +import DiscoveryFixtures from "fixtures/discovery_fixtures"; + +acceptance("Encoded Sub Category Discovery", { + pretend(server, helper) { + server.get( + "/c/%E6%BC%A2%E5%AD%97-parent/%E6%BC%A2%E5%AD%97-subcategory/6/l/latest.json", + () => { + return helper.response( + DiscoveryFixtures["/latest_can_create_topic.json"] + ); + } + ); + server.get( + "/c/%E6%BC%A2%E5%AD%97-parent/%E6%BC%A2%E5%AD%97-subcategory/find_by_slug.json", + () => { + //respond with an error here: these tests are to check that ember can route this itself without falling back to rails + return helper.response(500, {}); + } + ); + }, + settings: { + slug_generation_method: "encoded" + }, + site: { + categories: [ + { + id: 5, + name: "漢字-parent", + slug: "%E6%BC%A2%E5%AD%97-parent", + permission: null + }, + { + id: 6, + name: "漢字-subcategory", + slug: "%E6%BC%A2%E5%AD%97-subcategory", + permission: null, + parent_category_id: 5 + } + ] + } +}); + +QUnit.test("Visit subcategory by slug", async assert => { + let bodySelector = + "body.category-\\%E6\\%BC\\%A2\\%E5\\%AD\\%97-parent-\\%E6\\%BC\\%A2\\%E5\\%AD\\%97-subcategory"; + await visit("/c/%E6%BC%A2%E5%AD%97-parent/%E6%BC%A2%E5%AD%97-subcategory"); + assert.ok($(bodySelector).length, "has the default navigation"); + assert.ok(exists(".topic-list"), "The list of topics was rendered"); + assert.ok(exists(".topic-list .topic-list-item"), "has topics"); + + await visit("/c/漢字-parent/漢字-subcategory"); + assert.ok($(bodySelector).length, "has the default navigation"); + assert.ok(exists(".topic-list"), "The list of topics was rendered"); + assert.ok(exists(".topic-list .topic-list-item"), "has topics"); +});