DEV: Add system tests and run using Github actions (#132)

* Add system tests

* Enable running system tests in github actions
This commit is contained in:
Natalie Tay 2022-12-09 10:35:07 +08:00 committed by GitHub
parent 1ecf494a78
commit 1246d67ea0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 130 additions and 2 deletions

View File

@ -14,7 +14,7 @@ jobs:
build:
name: ${{ matrix.build_type }}
runs-on: ubuntu-latest
container: discourse/discourse_test:slim${{ startsWith(matrix.build_type, 'frontend') && '-browsers' || '' }}
container: discourse/discourse_test:slim${{ (matrix.build_type == 'frontend' || matrix.build_type == 'system') && '-browsers' || '' }}
timeout-minutes: 30
env:
@ -28,7 +28,7 @@ jobs:
fail-fast: false
matrix:
build_type: ["backend", "frontend"]
build_type: ['backend', 'frontend', 'system']
steps:
- uses: actions/checkout@v3
@ -149,3 +149,18 @@ jobs:
if: matrix.build_type == 'frontend' && steps.check_qunit.outputs.files_exist == 'true'
run: QUNIT_EMBER_CLI=1 bundle exec rake plugin:qunit['${{ github.event.repository.name }}','1200000']
timeout-minutes: 10
- name: Ember Build for System Tests
if: matrix.build_type == 'system'
run: bin/ember-cli --build
- name: Plugin System Tests
if: matrix.build_type == 'system'
run: LOAD_PLUGINS=1 bin/system_rspec plugins/*/spec/system
- name: Upload failed system test screenshots
uses: actions/upload-artifact@v3
if: matrix.build_type == 'system' && failure()
with:
name: failed-system-test-screenshots
path: tmp/screenshots/*.png

View File

@ -0,0 +1,19 @@
# frozen_string_literal: true
module TopicVotingCategory
include ::RSpec::Matchers
def votes
'.nav-item_votes.votes'
end
def topic_with_vote_count(vote_count)
"tr.topic-list-item a.list-vote-count.vote-count-#{vote_count}"
end
def select_topic(topic)
find("tr[data-topic-id=\"#{topic.id}\"] a.list-vote-count.vote-count-0").click
end
end
PageObjects::Pages::Category.class_eval { include TopicVotingCategory }

View File

@ -0,0 +1,30 @@
# frozen_string_literal: true
module TopicVotingTopic
include ::RSpec::Matchers
def vote_count
find('.voting .vote-count')
end
def vote_popup
find('.voting-popup-menu')
end
def vote
find('button.vote-button').click
self
end
def remove_vote
vote
find('.remove-vote').click
self
end
def click_vote_popup_activity
find('.voting-popup-menu a').click
end
end
PageObjects::Pages::Topic.class_eval { include TopicVotingTopic }

View File

@ -0,0 +1,64 @@
# frozen_string_literal: true
RSpec.describe 'Voting', type: :system, js: true do
fab!(:user) { Fabricate(:user) }
fab!(:admin) { Fabricate(:admin) }
fab!(:category1) { Fabricate(:category) }
fab!(:category2) { Fabricate(:category) }
fab!(:topic1) { Fabricate(:topic, category: category1) }
fab!(:topic2) { Fabricate(:topic, category: category1) }
fab!(:topic3) { Fabricate(:topic, category: category2) }
fab!(:post1) { Fabricate(:post, topic: topic1) }
fab!(:post2) { Fabricate(:post, topic: topic2) }
fab!(:category_page) { PageObjects::Pages::Category.new }
fab!(:topic_page) { PageObjects::Pages::Topic.new }
fab!(:user_page) { PageObjects::Pages::User.new }
fab!(:admin_page) { PageObjects::Pages::AdminSettings.new }
before do
SiteSetting.voting_enabled = false
admin.activate
user.activate
sign_in(admin)
end
it 'enables voting in category topics and votes' do
category_page.visit(category1)
expect(category_page).to have_no_css(category_page.votes)
# enables voting
admin_page
.visit_filtered_plugin_setting('voting%20enabled')
.toggle_setting('voting_enabled', 'Allow users to vote on topics?')
category_page
.visit_settings(category1)
.toggle_setting('enable-topic-voting', 'Allow users to vote on topics in this category')
.save_settings
.back_to_category
# voting
category_page.visit(category1)
expect(category_page).to have_css(category_page.votes)
expect(category_page).to have_css(category_page.topic_with_vote_count(0), count: 2)
category_page.select_topic(topic1)
expect(topic_page.vote_count).to have_text('0')
topic_page.vote
expect(topic_page.vote_popup).to have_text('You have 3 votes left, see your votes')
expect(topic_page.vote_count).to have_text('1')
topic_page.click_vote_popup_activity
expect(user_page.active_user_primary_navigation).to have_text("Activity")
expect(user_page.active_user_secondary_navigation).to have_text("Votes")
expect(page).to have_css(".topic-list-body tr[data-topic-id=\"#{topic1.id}\"]")
expect(find(".topic-list-body tr[data-topic-id=\"#{topic1.id}\"] a.voted")).to have_text('1 vote')
find(".topic-list-body tr[data-topic-id=\"#{topic1.id}\"] a.raw-link").click
# unvoting
topic_page.remove_vote
expect(topic_page.vote_count).to have_text('0')
end
end