Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jorg-vr committed Mar 21, 2023
1 parent 307f893 commit f6bd47d
Showing 1 changed file with 60 additions and 0 deletions.
60 changes: 60 additions & 0 deletions test/system/activities_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
require 'capybara/minitest'
require 'application_system_test_case'

class ActivitiesTest < ApplicationSystemTestCase
include Devise::Test::IntegrationHelpers
# Make the Capybara DSL available in all integration tests
include Capybara::DSL
# Make `assert_*` methods behave like Minitest assertions
include Capybara::Minitest::Assertions

setup do
@instance = exercises(:python_exercise)
@user = users(:zeus)
sign_in @user
end

test 'should show exercise' do
visit exercise_path(id: @instance.id)
assert_text @instance.name_en
end

test 'should show boilerplate in code editor' do
@instance.stubs(:boilerplate).returns('boilerplate') do
visit exercise_path(id: @instance.id)
assert_text 'boilerplate'
end
end

test 'show latest submission in code editor' do
create(:submission, exercise: @instance, user: @user, status: :correct, code: 'print("hello")')
visit exercise_path(id: @instance.id)
assert_text 'print("hello")'
end

test 'should show message to clear editor if latest submission is shown' do
create(:submission, exercise: @instance, user: @user, status: :correct, code: 'print("hello")')
visit exercise_path(id: @instance.id)
assert_text 'Clear editor'
end

test 'should show message to restore boilerplate if latest submission is shown' do
@instance.stubs(:boilerplate).returns('boilerplate') do
create(:submission, exercise: @instance, user: @user, status: :correct, code: 'print("hello")')
visit exercise_path(id: @instance.id)
assert_text 'Restore boilerplate'
end
end

test 'should not break on complex unicode characters' do
@instance.stubs(:boilerplate).returns('`<script>alert("πŸ˜€")</script>`') do
visit exercise_path(id: @instance.id)
assert_text '`<script>alert("πŸ˜€")</script>`'

create(:submission, exercise: @instance, user: @user, status: :correct, code: 'print("πŸ˜€")')
visit exercise_path(id: @instance.id)
assert_text 'print("πŸ˜€")'
assert_text 'Restore boilerplate'
end
end
end

0 comments on commit f6bd47d

Please sign in to comment.