diff --git a/spec/system/page_objects/components/topic_map.rb b/spec/system/page_objects/components/topic_map.rb new file mode 100644 index 00000000000..c2df6e70b9e --- /dev/null +++ b/spec/system/page_objects/components/topic_map.rb @@ -0,0 +1,81 @@ +# frozen_string_literal: true + +module PageObjects + module Components + class TopicMap < PageObjects::Components::Base + TOPIC_MAP_KLASS = ".topic-map" + + def is_visible? + has_css?(TOPIC_MAP_KLASS) + end + + def is_not_visible? + has_no_css?(TOPIC_MAP_KLASS) + end + + def is_collapsed? + has_css?("#{TOPIC_MAP_KLASS} .map-collapsed") + end + + def expand + find("#{TOPIC_MAP_KLASS} .map-collapsed .btn").click if is_collapsed? + end + + def has_no_likes? + has_no_css?("#{TOPIC_MAP_KLASS} .likes") + end + + def has_no_links? + has_no_css?("#{TOPIC_MAP_KLASS} .links") + end + + def users_count + find("#{TOPIC_MAP_KLASS} .users .number").text.to_i + end + + def replies_count + find("#{TOPIC_MAP_KLASS} .replies .number").text.to_i + end + + def likes_count + find("#{TOPIC_MAP_KLASS} .likes .number").text.to_i + end + + def links_count + find("#{TOPIC_MAP_KLASS} .links .number").text.to_i + end + + def views_count + find("#{TOPIC_MAP_KLASS} .views .number").text.to_i + end + + def created_details + find("#{TOPIC_MAP_KLASS} .topic-map-post.created-at") + end + + def created_relative_date + created_details.find(".relative-date").text + end + + def last_reply_details + find("#{TOPIC_MAP_KLASS} .topic-map-post.last-reply") + end + + def last_reply_relative_date + last_reply_details.find(".relative-date").text + end + + def avatars_details + find("#{TOPIC_MAP_KLASS} .map .avatars").all(".poster.trigger-user-card") + end + + def expanded_map_avatars_details + find("#{TOPIC_MAP_KLASS} .topic-map-expanded .avatars").all(".poster.trigger-user-card") + end + + def has_no_avatars_details_in_map? + has_no_css?("#{TOPIC_MAP_KLASS} .map .avatars") + end + end + end +end diff --git a/spec/system/page_objects/pages/topic.rb b/spec/system/page_objects/pages/topic.rb index d5d77bbe66f..bf37806a188 100644 --- a/spec/system/page_objects/pages/topic.rb +++ b/spec/system/page_objects/pages/topic.rb @@ -6,12 +6,13 @@ module PageObjects def initialize @composer_component = PageObjects::Components::Composer.new @fast_edit_component = PageObjects::Components::FastEditor.new + @topic_map_component = PageObjects::Components::TopicMap.new end def visit_topic(topic, post_number: nil) url = "/t/#{topic.id}" url += "/#{post_number}" if post_number - page.visit url + page.visit(url) self end @@ -192,6 +193,18 @@ module PageObjects self end + def click_like_reaction_for(post) + post_by_number(post).find(".post-controls .actions .like").click + end + + def has_topic_map? + @topic_map_component.is_visible? + end + + def has_no_topic_map? + @topic_map_component.is_not_visible? + end + private def topic_footer_button_id(button) diff --git a/spec/system/topic_map_spec.rb b/spec/system/topic_map_spec.rb new file mode 100644 index 00000000000..574fdbdfea7 --- /dev/null +++ b/spec/system/topic_map_spec.rb @@ -0,0 +1,77 @@ +# frozen_string_literal: true +# +describe "Topic Map", type: :system do + fab!(:user) { Fabricate(:user, refresh_auto_groups: true) } + fab!(:topic) { Fabricate(:topic, user: user, created_at: 1.day.ago) } + fab!(:original_post) { Fabricate(:post, topic: topic, user: user, created_at: 1.day.ago) } + + fab!(:other_user) { Fabricate(:user, refresh_auto_groups: true) } + fab!(:last_post_user) { Fabricate(:user, refresh_auto_groups: true) } + + let(:topic_page) { PageObjects::Pages::Topic.new } + let(:topic_map) { PageObjects::Components::TopicMap.new } + + def avatar_url(user, size) + URI(user.avatar_template_url.gsub("{size}", size.to_s)).path + end + + it "updates the various topic stats, avatars" do + freeze_time + sign_in(user) + topic_page.visit_topic(topic) + + # topic map only appears after at least 1 reply + expect(topic_page).to have_no_topic_map + Fabricate(:post, topic: topic, created_at: 1.day.ago) + page.refresh + expect(topic_page).to have_topic_map + + # created avatar display + expect(topic_map.created_details).to have_selector("img[src=\"#{avatar_url(user, 24)}\"]") + expect(topic_map.created_relative_date).to eq "1d" + + # replies, user count + expect { + Fabricate(:post, topic: topic, user: user, created_at: 1.day.ago) + sign_in(last_post_user) + topic_page.visit_topic_and_open_composer(topic) + topic_page.send_reply("this is a cool-cat post") # fabricating posts doesn't update the last post details + topic_page.visit_topic(topic) + }.to change(topic_map, :replies_count).by(2).and change(topic_map, :users_count).by(1) + + #last reply avatar display + expect(topic_map.last_reply_details).to have_selector( + "img[src=\"#{avatar_url(last_post_user, 24)}\"]", + ) + expect(topic_map.last_reply_relative_date).to eq "1m" + + # avatars details with post counts + Fabricate(:post, topic: topic) + Fabricate(:post, user: user, topic: topic) + Fabricate(:post, user: last_post_user, topic: topic) + page.refresh + avatars = topic_map.avatars_details + expect(avatars.length).to eq 3 # max no. of avatars in a collapsed map + expect(avatars[0]).to have_selector("img[src=\"#{avatar_url(user, 48)}\"]") + expect(avatars[0].find(".post-count").text).to eq "3" + expect(avatars[1]).to have_selector("img[src=\"#{avatar_url(last_post_user, 48)}\"]") + expect(avatars[1].find(".post-count").text).to eq "2" + expect(avatars[2]).to have_no_css(".post-count") + + topic_map.expand + expect(topic_map).to have_no_avatars_details_in_map + expect(topic_map.expanded_map_avatars_details.length).to eq 4 + + # views count + expect { + sign_in(other_user) + topic_page.visit_topic(topic) + page.refresh + }.to change(topic_map, :views_count).by 1 + + # likes count + expect(topic_map).to have_no_likes + topic_page.click_like_reaction_for(original_post) + expect(topic_map.likes_count).to eq 1 + end +end