created new feature test to check that only users with the right permission are able to see the new autosave-hide feature

This commit is contained in:
Janis4411
2022-07-20 16:22:35 +02:00
committed by Sebastian Serth
parent 67dd8566b6
commit 184c9cba6d

View File

@ -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