canvas-lms/spec/selenium/new_files_student_spec.rb

135 lines
5.3 KiB
Ruby
Raw Normal View History

#
# Copyright (C) 2015 - present Instructure, Inc.
#
# This file is part of Canvas.
#
# Canvas is free software: you can redistribute it and/or modify it under
# the terms of the GNU Affero General Public License as published by the Free
# Software Foundation, version 3 of the License.
#
# Canvas is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
# A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
# details.
#
# You should have received a copy of the GNU Affero General Public License along
# with this program. If not, see <http://www.gnu.org/licenses/>.
require File.expand_path(File.dirname(__FILE__) + '/common')
require File.expand_path(File.dirname(__FILE__) + '/helpers/files_common')
describe "better_file_browsing" do
include_context "in-process server selenium tests"
include FilesCommon
context "as a student" do
before :once do
@student = course_with_student(active_all: true).user
end
before :each do
user_session(@student)
end
def verify_hidden_item_not_searchable_as_student(search_text)
f("input[type='search']").send_keys "#{search_text}", :return
expect(f("body")).not_to contain_css(".ef-item-row")
end
context "in course with files" do
before :once do
txt_files = ["a_file.txt", "b_file.txt", "c_file.txt"]
@files = txt_files.map do |text_file|
add_file(fixture_file_upload("files/#{text_file}", 'text/plain'), @course, text_file)
end
end
it "should search for a file", :xbrowser, priority: "1", test_id: 220355 do
get "/courses/#{@course.id}/files"
f("input[type='search']").send_keys "b_fi", :return
expect(all_files_folders).to have_size 1
end
it "should not return unpublished files in search results", priority: "1", test_id: 238870 do
@files[0].update_attribute(:locked, true)
get "/courses/#{@course.id}/files"
verify_hidden_item_not_searchable_as_student("a_fi")
end
it "should not return hidden files in search results", priority: "1", test_id: 238871 do
@files[0].update_attribute(:hidden, true)
get "/courses/#{@course.id}/files"
verify_hidden_item_not_searchable_as_student("a_fi")
end
it "should not see upload file, add folder buttons and cloud icon", priority: "1", test_id: 327118 do
get "/courses/#{@course.id}/files"
spec: rework negative dom assertions fixes SD-1063, speeds up :allthethings: negative DOM assertions are :poop:, but if we must have them, make them more tolerable. the old way: expect(f(".something-that-should-be-gone")).to be_nil expect(fj("buhleeted:visible")).to be_nil expect(fln("Can't Click Here Anymore").to be_nil the new way: expect(container).not_to contain_css(".something-that-should-be-gone") expect(container).not_to contain_jqcss("buhleeted:visible") expect(container).not_to contain_link("Can't Click Here Anymore") (you can of course use these new matchers for positive assertions as well) although it's a tad more verbose, the new way is better because: 1. it's smart enough to bail once the assertion is met (versus the old way which would take 10-20 seconds to not find the thing and *then* run the assertion) 2. it requires them to be scoped, to reduce the likelihood of false positives (e.g. if the page is totally broken, then of course the assertion would pass) also reworked the various flash message assertions... see the new expect_flash_message and expect_no_flash_message this should remove over an hour of linear time off the build (10 sec per old assertion, except fj ones which took 20 sec)... so like a minute of actual time, cuz parallelization :P a consequence of this change is that f/fj/ff/ffj now raise if nothing is found, so you really have to go out of your way to do it the bad way. so don't :) Change-Id: I0fe6e8500947c27d748b70bb2cda585edf71e427 Reviewed-on: https://gerrit.instructure.com/78420 Tested-by: Jenkins Reviewed-by: Landon Wilkins <lwilkins@instructure.com> Product-Review: Landon Wilkins <lwilkins@instructure.com> QA-Review: Landon Wilkins <lwilkins@instructure.com>
2016-05-01 06:23:03 +08:00
content = f("#content")
expect(content).not_to contain_css('.btn-upload')
expect(content).not_to contain_css('.btn-add-folder')
expect(content).not_to contain_css('.btn-link.published-status')
end
it "should only see Download option on cog icon", priority: "1", test_id: 133105 do
skip_if_safari(:alert)
get "/courses/#{@course.id}/files"
spec: rework negative dom assertions fixes SD-1063, speeds up :allthethings: negative DOM assertions are :poop:, but if we must have them, make them more tolerable. the old way: expect(f(".something-that-should-be-gone")).to be_nil expect(fj("buhleeted:visible")).to be_nil expect(fln("Can't Click Here Anymore").to be_nil the new way: expect(container).not_to contain_css(".something-that-should-be-gone") expect(container).not_to contain_jqcss("buhleeted:visible") expect(container).not_to contain_link("Can't Click Here Anymore") (you can of course use these new matchers for positive assertions as well) although it's a tad more verbose, the new way is better because: 1. it's smart enough to bail once the assertion is met (versus the old way which would take 10-20 seconds to not find the thing and *then* run the assertion) 2. it requires them to be scoped, to reduce the likelihood of false positives (e.g. if the page is totally broken, then of course the assertion would pass) also reworked the various flash message assertions... see the new expect_flash_message and expect_no_flash_message this should remove over an hour of linear time off the build (10 sec per old assertion, except fj ones which took 20 sec)... so like a minute of actual time, cuz parallelization :P a consequence of this change is that f/fj/ff/ffj now raise if nothing is found, so you really have to go out of your way to do it the bad way. so don't :) Change-Id: I0fe6e8500947c27d748b70bb2cda585edf71e427 Reviewed-on: https://gerrit.instructure.com/78420 Tested-by: Jenkins Reviewed-by: Landon Wilkins <lwilkins@instructure.com> Product-Review: Landon Wilkins <lwilkins@instructure.com> QA-Review: Landon Wilkins <lwilkins@instructure.com>
2016-05-01 06:23:03 +08:00
content = f("#content")
f('.al-trigger-gray').click
expect(fln("Download")).to be_displayed
spec: rework negative dom assertions fixes SD-1063, speeds up :allthethings: negative DOM assertions are :poop:, but if we must have them, make them more tolerable. the old way: expect(f(".something-that-should-be-gone")).to be_nil expect(fj("buhleeted:visible")).to be_nil expect(fln("Can't Click Here Anymore").to be_nil the new way: expect(container).not_to contain_css(".something-that-should-be-gone") expect(container).not_to contain_jqcss("buhleeted:visible") expect(container).not_to contain_link("Can't Click Here Anymore") (you can of course use these new matchers for positive assertions as well) although it's a tad more verbose, the new way is better because: 1. it's smart enough to bail once the assertion is met (versus the old way which would take 10-20 seconds to not find the thing and *then* run the assertion) 2. it requires them to be scoped, to reduce the likelihood of false positives (e.g. if the page is totally broken, then of course the assertion would pass) also reworked the various flash message assertions... see the new expect_flash_message and expect_no_flash_message this should remove over an hour of linear time off the build (10 sec per old assertion, except fj ones which took 20 sec)... so like a minute of actual time, cuz parallelization :P a consequence of this change is that f/fj/ff/ffj now raise if nothing is found, so you really have to go out of your way to do it the bad way. so don't :) Change-Id: I0fe6e8500947c27d748b70bb2cda585edf71e427 Reviewed-on: https://gerrit.instructure.com/78420 Tested-by: Jenkins Reviewed-by: Landon Wilkins <lwilkins@instructure.com> Product-Review: Landon Wilkins <lwilkins@instructure.com> QA-Review: Landon Wilkins <lwilkins@instructure.com>
2016-05-01 06:23:03 +08:00
expect(content).not_to contain_link("Rename")
expect(content).not_to contain_link("Move")
expect(content).not_to contain_link("Delete")
end
it "should only see View and Download options on toolbar menu", priority: "1", test_id: 133109 do
get "/courses/#{@course.id}/files"
spec: rework negative dom assertions fixes SD-1063, speeds up :allthethings: negative DOM assertions are :poop:, but if we must have them, make them more tolerable. the old way: expect(f(".something-that-should-be-gone")).to be_nil expect(fj("buhleeted:visible")).to be_nil expect(fln("Can't Click Here Anymore").to be_nil the new way: expect(container).not_to contain_css(".something-that-should-be-gone") expect(container).not_to contain_jqcss("buhleeted:visible") expect(container).not_to contain_link("Can't Click Here Anymore") (you can of course use these new matchers for positive assertions as well) although it's a tad more verbose, the new way is better because: 1. it's smart enough to bail once the assertion is met (versus the old way which would take 10-20 seconds to not find the thing and *then* run the assertion) 2. it requires them to be scoped, to reduce the likelihood of false positives (e.g. if the page is totally broken, then of course the assertion would pass) also reworked the various flash message assertions... see the new expect_flash_message and expect_no_flash_message this should remove over an hour of linear time off the build (10 sec per old assertion, except fj ones which took 20 sec)... so like a minute of actual time, cuz parallelization :P a consequence of this change is that f/fj/ff/ffj now raise if nothing is found, so you really have to go out of your way to do it the bad way. so don't :) Change-Id: I0fe6e8500947c27d748b70bb2cda585edf71e427 Reviewed-on: https://gerrit.instructure.com/78420 Tested-by: Jenkins Reviewed-by: Landon Wilkins <lwilkins@instructure.com> Product-Review: Landon Wilkins <lwilkins@instructure.com> QA-Review: Landon Wilkins <lwilkins@instructure.com>
2016-05-01 06:23:03 +08:00
content = f("#content")
f('.ef-item-row').click
expect(f('.btn-download')).to be_displayed
expect(f('.btn-view')).to be_displayed
spec: rework negative dom assertions fixes SD-1063, speeds up :allthethings: negative DOM assertions are :poop:, but if we must have them, make them more tolerable. the old way: expect(f(".something-that-should-be-gone")).to be_nil expect(fj("buhleeted:visible")).to be_nil expect(fln("Can't Click Here Anymore").to be_nil the new way: expect(container).not_to contain_css(".something-that-should-be-gone") expect(container).not_to contain_jqcss("buhleeted:visible") expect(container).not_to contain_link("Can't Click Here Anymore") (you can of course use these new matchers for positive assertions as well) although it's a tad more verbose, the new way is better because: 1. it's smart enough to bail once the assertion is met (versus the old way which would take 10-20 seconds to not find the thing and *then* run the assertion) 2. it requires them to be scoped, to reduce the likelihood of false positives (e.g. if the page is totally broken, then of course the assertion would pass) also reworked the various flash message assertions... see the new expect_flash_message and expect_no_flash_message this should remove over an hour of linear time off the build (10 sec per old assertion, except fj ones which took 20 sec)... so like a minute of actual time, cuz parallelization :P a consequence of this change is that f/fj/ff/ffj now raise if nothing is found, so you really have to go out of your way to do it the bad way. so don't :) Change-Id: I0fe6e8500947c27d748b70bb2cda585edf71e427 Reviewed-on: https://gerrit.instructure.com/78420 Tested-by: Jenkins Reviewed-by: Landon Wilkins <lwilkins@instructure.com> Product-Review: Landon Wilkins <lwilkins@instructure.com> QA-Review: Landon Wilkins <lwilkins@instructure.com>
2016-05-01 06:23:03 +08:00
expect(content).not_to contain_css('.btn-move')
expect(content).not_to contain_css('.btn-restrict')
expect(content).not_to contain_css('.btn-delete')
end
it "should see calendar icon on restricted files within a given timeframe", priority: "1", test_id: 133108 do
@files[0].update_attributes unlock_at: Time.zone.now - 1.week,
lock_at: Time.zone.now + 1.week
get "/courses/#{@course.id}/files"
expect(f('.icon-calendar-day')).to be_displayed
f('.icon-calendar-day').click
wait_for_ajaximations
expect(f("body")).not_to contain_css("[name=permissions]")
end
end
context "in course with folders" do
before :once do
@folder = folder_model(name: "restricted_folder", context: @course)
@file = add_file(fixture_file_upload('files/example.pdf', 'application/pdf'),
@course, "example.pdf", @folder)
end
it "should not return files from hidden folders in search results", priority: "1", test_id: 171774 do
@folder.update_attribute :hidden, true
get "/courses/#{@course.id}/files"
verify_hidden_item_not_searchable_as_student("example")
end
it "should not return files from unpublished folders in search results", priority: "1", test_id: 171774 do
@folder.update_attribute :locked, true
get "/courses/#{@course.id}/files"
verify_hidden_item_not_searchable_as_student("example")
end
it "should let student access files in restricted folder hidden by link", priority: "1", test_id: 134750 do
@folder.update_attribute :hidden, true
get "/courses/#{@course.id}/files/folder/restricted_folder?preview=#{@file.id}"
refresh_page # the header seriously doesn't show up until you refres ¯\_(ツ)_/¯
expect(f('.ef-file-preview-header')).to be_present
end
end
end
spec: rework negative dom assertions fixes SD-1063, speeds up :allthethings: negative DOM assertions are :poop:, but if we must have them, make them more tolerable. the old way: expect(f(".something-that-should-be-gone")).to be_nil expect(fj("buhleeted:visible")).to be_nil expect(fln("Can't Click Here Anymore").to be_nil the new way: expect(container).not_to contain_css(".something-that-should-be-gone") expect(container).not_to contain_jqcss("buhleeted:visible") expect(container).not_to contain_link("Can't Click Here Anymore") (you can of course use these new matchers for positive assertions as well) although it's a tad more verbose, the new way is better because: 1. it's smart enough to bail once the assertion is met (versus the old way which would take 10-20 seconds to not find the thing and *then* run the assertion) 2. it requires them to be scoped, to reduce the likelihood of false positives (e.g. if the page is totally broken, then of course the assertion would pass) also reworked the various flash message assertions... see the new expect_flash_message and expect_no_flash_message this should remove over an hour of linear time off the build (10 sec per old assertion, except fj ones which took 20 sec)... so like a minute of actual time, cuz parallelization :P a consequence of this change is that f/fj/ff/ffj now raise if nothing is found, so you really have to go out of your way to do it the bad way. so don't :) Change-Id: I0fe6e8500947c27d748b70bb2cda585edf71e427 Reviewed-on: https://gerrit.instructure.com/78420 Tested-by: Jenkins Reviewed-by: Landon Wilkins <lwilkins@instructure.com> Product-Review: Landon Wilkins <lwilkins@instructure.com> QA-Review: Landon Wilkins <lwilkins@instructure.com>
2016-05-01 06:23:03 +08:00
end