Skip to content

A platform for community discussion. Free, open, simple.

DEV: Tag group creation specs (#37034)

Natalie Tay7a30f4e08565
diff --git a/spec/system/page_objects/pages/admin_tag_groups.rb b/spec/system/page_objects/pages/admin_tag_groups.rb
new file mode 100644
index 00000000000..8d101d99751
--- /dev/null
+++ b/spec/system/page_objects/pages/admin_tag_groups.rb
@@ -0,0 +1,81 @@
+# frozen_string_literal: true
+
+module PageObjects
+ module Pages
+ class AdminTagGroups < PageObjects::Pages::Base
+ def tags_chooser
+ PageObjects::Components::SelectKit.new(".group-tags-list .tag-chooser")
+ end
+
+ def parent_tag_chooser
+ PageObjects::Components::SelectKit.new(".parent-tag-section .tag-chooser")
+ end
+
+ def has_tag_group_in_sidebar?(name)
+ has_css?(".tag-groups-sidebar li", text: name)
+ end
+
+ def has_no_tag_group_in_sidebar?(name)
+ has_no_css?(".tag-groups-sidebar li", text: name)
+ end
+
+ def has_tags_label?
+ has_css?(".group-tags-list label", text: I18n.t("js.tagging.groups.tags_label"))
+ end
+
+ def has_parent_tag_label?
+ has_css?(".parent-tag-section label", text: I18n.t("js.tagging.groups.parent_tag_label"))
+ end
+
+ def has_visible_permission_label?
+ has_css?(
+ "label[for='visible-permission']",
+ text: I18n.t("js.tagging.groups.usable_only_by_groups"),
+ )
+ end
+
+ def has_tag_in_group?(tag_name)
+ has_css?(".group-tags-list .tag-chooser", text: tag_name)
+ end
+
+ def visit
+ page.visit("/tag_groups")
+ self
+ end
+
+ def visit_tag_group(tag_group)
+ page.visit("/tag_groups/#{tag_group.id}")
+ self
+ end
+
+ def click_new_tag_group
+ if has_css?(".tag-groups-sidebar .btn-default", wait: 0)
+ find(".tag-groups-sidebar .btn-default").click
+ else
+ find(".tag-group-content .btn-primary").click
+ end
+ self
+ end
+
+ def fill_name(name)
+ find(".group-name input").fill_in(with: name)
+ self
+ end
+
+ def select_public_permission
+ find("#public-permission").click
+ self
+ end
+
+ def select_visible_permission
+ find("#visible-permission").click
+ self
+ end
+
+ def save
+ find(".tag-group-controls .btn-primary").click
+ self
+ end
+ end
+ end
+end
diff --git a/spec/system/tag_group_spec.rb b/spec/system/tag_group_spec.rb
new file mode 100644
index 00000000000..6b88260d676
--- /dev/null
+++ b/spec/system/tag_group_spec.rb
@@ -0,0 +1,76 @@
+# frozen_string_literal: true
+
+describe "Tag Groups", type: :system do
+ fab!(:admin)
+ fab!(:tag1) { Fabricate(:tag, name: "cats") }
+ fab!(:tag2) { Fabricate(:tag, name: "bats") }
+ fab!(:parent_tag) { Fabricate(:tag, name: "parent-tag") }
+
+ let(:tag_groups_page) { PageObjects::Pages::AdminTagGroups.new }
+
+ before do
+ SiteSetting.tagging_enabled = true
+ sign_in(admin)
+ end
+
+ describe "viewing an existing tag group" do
+ fab!(:tag_group) do
+ Fabricate(:tag_group, name: "Ats", tags: [tag1, tag2]).tap do |tg|
+ tg.update!(parent_tag: parent_tag)
+ tg.permissions = { 0 => TagGroupPermission.permission_types[:readonly] }
+ tg.save!
+ end
+ end
+
+ it "displays the correct labels and values" do
+ tag_groups_page.visit_tag_group(tag_group)
+
+ expect(tag_groups_page).to have_tags_label
+ expect(tag_groups_page).to have_parent_tag_label
+ expect(tag_groups_page).to have_visible_permission_label
+ expect(tag_groups_page).to have_tag_group_in_sidebar("Ats")
+ expect(tag_groups_page).to have_tag_in_group("cats")
+ expect(tag_groups_page).to have_tag_in_group("bats")
+ end
+ end
+
+ describe "creating a new tag group" do
+ fab!(:existing_tag_group) { Fabricate(:tag_group, name: "Existing Group") }
+
+ it "can create a tag group and see it after refresh" do
+ tag_groups_page.visit
+
+ expect(tag_groups_page).to have_tag_group_in_sidebar("Existing Group")
+
+ tag_groups_page.click_new_tag_group
+ tag_groups_page.fill_name("New Test Group")
+
+ tag_groups_page.tags_chooser.expand
+ tag_groups_page.tags_chooser.search("cats")
+ tag_groups_page.tags_chooser.select_row_by_name("cats")
+ tag_groups_page.tags_chooser.search("bats")
+ tag_groups_page.tags_chooser.select_row_by_name("bats")
+ tag_groups_page.tags_chooser.collapse
+
+ tag_groups_page.parent_tag_chooser.expand
+ tag_groups_page.parent_tag_chooser.search("parent-tag")
+ tag_groups_page.parent_tag_chooser.select_row_by_name("parent-tag")
+
+ tag_groups_page.select_visible_permission
+ tag_groups_page.save
+
+ expect(tag_groups_page).to have_tag_group_in_sidebar("New Test Group")
+
+ page.refresh
+
+ expect(tag_groups_page).to have_tag_group_in_sidebar("New Test Group")
+
+ find(".tag-groups-sidebar li", text: "New Test Group").click
+
+ expect(tag_groups_page).to have_tag_in_group("cats")
+ expect(tag_groups_page).to have_tag_in_group("bats")
+ expect(page).to have_css(".parent-tag-section .tag-chooser", text: "parent-tag")
+ expect(find("#visible-permission")).to be_checked
+ end
+ end
+end