From f6bd47d1c5ff83f3ebfd3edfb3e62df713897f0a Mon Sep 17 00:00:00 2001 From: jorg-vr Date: Tue, 21 Mar 2023 17:45:12 +0100 Subject: [PATCH] Add tests --- test/system/activities_test.rb | 60 ++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 test/system/activities_test.rb diff --git a/test/system/activities_test.rb b/test/system/activities_test.rb new file mode 100644 index 0000000000..181eb1675a --- /dev/null +++ b/test/system/activities_test.rb @@ -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('``') do + visit exercise_path(id: @instance.id) + assert_text '``' + + 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