From 184c9cba6d7a568e6ba9c6051d206b50bf3fc84c Mon Sep 17 00:00:00 2001 From: Janis4411 Date: Wed, 20 Jul 2022 16:22:35 +0200 Subject: [PATCH] created new feature test to check that only users with the right permission are able to see the new autosave-hide feature --- .../features/external_user_statistics_spec.rb | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 spec/features/external_user_statistics_spec.rb diff --git a/spec/features/external_user_statistics_spec.rb b/spec/features/external_user_statistics_spec.rb new file mode 100644 index 00000000..0716daee --- /dev/null +++ b/spec/features/external_user_statistics_spec.rb @@ -0,0 +1,45 @@ +# frozen_string_literal: true + +require 'rails_helper' + +describe 'ExternalUserStatistics', js: true do + let(:learner) { create(:external_user) } + let(:exercise) { create(:dummy, user: user) } + let(:study_group) { create(:study_group) } + let(:password) { 'password123456' } + + before do + 2.times { create(:submission, cause: 'autosave', user: learner, exercise: exercise, study_group: study_group) } + 2.times { create(:submission, cause: 'run', user: learner, exercise: exercise, study_group: study_group) } + create(:submission, cause: 'assess', user: learner, exercise: exercise, study_group: study_group) + create(:submission, cause: 'submit', user: learner, exercise: exercise, study_group: study_group) + + study_group.external_users << learner + study_group.internal_users << user + study_group.save + + visit(sign_in_path) + fill_in('email', with: user.email) + fill_in('password', with: password) + click_button(I18n.t('sessions.new.link')) + allow_any_instance_of(LtiHelper).to receive(:lti_outcome_service?).and_return(true) + visit(statistics_external_user_exercise_path(id: exercise.id, external_user_id: learner.id)) + end + + context 'when a admin accesses the page' do + let(:user) { create(:admin, password: password) } + + it 'does display the option to enable autosaves' do + expect(page).to have_content(I18n.t('exercises.external_users.statistics.toggle_status_on')).or have_content(I18n.t('exercises.external_users.statistics.toggle_status_off')) + end + end + + context 'when a teacher accesses the page' do + let(:user) { create(:teacher, password: password) } + + it 'does not display the option to enable autosaves' do + expect(page).not_to have_content(I18n.t('exercises.external_users.statistics.toggle_status_on')) + expect(page).not_to have_content(I18n.t('exercises.external_users.statistics.toggle_status_off')) + end + end +end