diff --git a/test/system/projects/samples/attachments_test.rb b/test/system/projects/samples/attachments_test.rb new file mode 100644 index 0000000000..9fc7e57678 --- /dev/null +++ b/test/system/projects/samples/attachments_test.rb @@ -0,0 +1,577 @@ +# frozen_string_literal: true + +require 'application_system_test_case' + +module Projects + module Samples + class AttachmentsTest < ApplicationSystemTestCase + include ActionView::Helpers::SanitizeHelper + + setup do + @user = users(:john_doe) + login_as @user + @sample1 = samples(:sample1) + @sample2 = samples(:sample2) + @project = projects(:project1) + @namespace = groups(:group_one) + end + + test 'user with role >= Maintainer should be able to see upload, concatenate and delete files buttons' do + visit namespace_project_sample_url(@namespace, @project, @sample2) + assert_selector 'a', text: I18n.t('projects.samples.show.new_attachment_button'), count: 1 + assert_selector 'a', text: I18n.t('projects.samples.show.concatenate_button'), count: 1 + assert_selector 'a', text: I18n.t('projects.samples.show.delete_files_button'), count: 1 + end + + test 'user with role < Maintainer should not be able to see upload, concatenate and delete files buttons' do + user = users(:ryan_doe) + login_as user + visit namespace_project_sample_url(@namespace, @project, @sample2) + assert_selector 'a', text: I18n.t('projects.samples.show.new_attachment_button'), count: 0 + assert_selector 'a', text: I18n.t('projects.samples.show.concatenate_button'), count: 0 + assert_selector 'a', text: I18n.t('projects.samples.show.delete_files_button'), count: 0 + end + + test 'user with role >= Maintainer should be able to attach a file to a Sample' do + visit namespace_project_sample_url(@namespace, @project, @sample2) + assert_selector 'a', text: I18n.t('projects.samples.show.new_attachment_button'), count: 1 + within('#table-listing') do + assert_text I18n.t('projects.samples.show.no_files') + assert_text I18n.t('projects.samples.show.no_associated_files') + assert_no_text 'test_file_2.fastq.gz' + end + click_on I18n.t('projects.samples.show.upload_files') + + within('dialog') do + attach_file 'attachment[files][]', Rails.root.join('test/fixtures/files/data_export_1.zip') + # check that button goes from being enabled to disabled when clicked + assert_selector 'input[type=submit]:not(:disabled)' + click_on I18n.t('projects.samples.show.upload') + assert_selector 'input[type=submit]:disabled' + end + + assert_text I18n.t('projects.samples.attachments.create.success', filename: 'data_export_1.zip') + within('#table-listing') do + assert_no_text I18n.t('projects.samples.show.no_files') + assert_no_text I18n.t('projects.samples.show.no_associated_files') + assert_text 'data_export_1.zip' + end + end + + test 'user with role >= Maintainer should not be able to attach a duplicate file to a Sample' do + visit namespace_project_sample_url(@namespace, @project, @sample1) + assert_selector 'a', text: I18n.t('projects.samples.show.new_attachment_button'), count: 1 + click_on I18n.t('projects.samples.show.upload_files') + + within('dialog') do + attach_file 'attachment[files][]', Rails.root.join('test/fixtures/files/test_file_2.fastq.gz') + click_on I18n.t('projects.samples.show.upload') + end + click_on I18n.t('projects.samples.show.upload_files') + + within('dialog') do + attach_file 'attachment[files][]', Rails.root.join('test/fixtures/files/test_file_2.fastq.gz') + click_on I18n.t('projects.samples.show.upload') + end + + assert_text 'checksum matches existing file' + end + + test 'user with role >= Maintainer not be able to upload uncompressed files to a Sample' do + visit namespace_project_sample_url(@namespace, @project, @sample1) + assert_selector 'a', text: I18n.t('projects.samples.show.new_attachment_button'), count: 1 + click_on I18n.t('projects.samples.show.upload_files') + + within('dialog') do + attach_file 'attachment[files][]', [Rails.root.join('test/fixtures/files/TestSample_S1_L001_R1_001.fastq.gz'), + Rails.root.join('test/fixtures/files/TestSample_S1_L001_R2_001.fastq.gz'), + Rails.root.join('test/fixtures/files/test_file.fastq')] + assert_text I18n.t('projects.samples.show.files_ignored') + assert_text 'test_file.fastq' + + click_on I18n.t('projects.samples.show.upload') + end + + assert_text I18n.t('projects.samples.attachments.create.success', + filename: 'TestSample_S1_L001_R1_001.fastq.gz') + assert_text I18n.t('projects.samples.attachments.create.success', + filename: 'TestSample_S1_L001_R2_001.fastq.gz') + assert_no_text I18n.t('projects.samples.attachments.create.success', filename: 'test_file.fastq') + + # View paired files + within('#table-listing') do + assert_text 'TestSample_S1_L001_R1_001.fastq.gz' + assert_text 'TestSample_S1_L001_R2_001.fastq.gz' + end + end + + test 'user with role >= Maintainer should be able to delete a file from a Sample' do + visit namespace_project_sample_url(@namespace, @project, @sample1) + + within('#attachments-table-body') do + assert_link text: I18n.t('projects.samples.attachments.attachment.delete'), count: 2 + click_on I18n.t('projects.samples.attachments.attachment.delete'), match: :first + end + + within('dialog') do + assert_accessible + assert_text I18n.t('projects.samples.attachments.delete_attachment_modal.description') + click_button I18n.t('projects.samples.attachments.delete_attachment_modal.submit_button') + end + + assert_text I18n.t('projects.samples.attachments.destroy.success', filename: 'test_file_A.fastq') + within('#table-listing') do + assert_no_text 'test_file_A.fastq' + end + end + + test 'user with role >= Maintainer should be able to attach, view, and destroy paired files to a Sample' do + visit namespace_project_sample_url(@namespace, @project, @sample2) + # Initial View + assert_selector 'a', text: I18n.t('projects.samples.show.new_attachment_button'), count: 1 + within('#table-listing') do + assert_text I18n.t('projects.samples.show.no_files') + assert_text I18n.t('projects.samples.show.no_associated_files') + assert_selector 'button', text: I18n.t('projects.samples.attachments.attachment.delete'), count: 0 + end + click_on I18n.t('projects.samples.show.upload_files') + + # Attach paired files + within('dialog') do + attach_file 'attachment[files][]', + [Rails.root.join('test/fixtures/files/TestSample_S1_L001_R1_001.fastq.gz'), + Rails.root.join('test/fixtures/files/TestSample_S1_L001_R2_001.fastq.gz')] + click_on I18n.t('projects.samples.show.upload') + end + + assert_text I18n.t('projects.samples.attachments.create.success', + filename: 'TestSample_S1_L001_R1_001.fastq.gz') + assert_text I18n.t('projects.samples.attachments.create.success', + filename: 'TestSample_S1_L001_R2_001.fastq.gz') + + # View paired files + within('#table-listing') do + assert_text 'TestSample_S1_L001_R1_001.fastq.gz' + assert_text 'TestSample_S1_L001_R2_001.fastq.gz' + assert_link text: I18n.t('projects.samples.attachments.attachment.delete'), count: 1 + end + + # Destroy paired files + within('#attachments-table-body') do + click_on I18n.t('projects.samples.attachments.attachment.delete'), match: :first + end + + within('dialog') do + click_button I18n.t('projects.samples.attachments.delete_attachment_modal.submit_button') + end + + assert_text I18n.t('projects.samples.attachments.destroy.success', + filename: 'TestSample_S1_L001_R1_001.fastq.gz') + assert_text I18n.t('projects.samples.attachments.destroy.success', + filename: 'TestSample_S1_L001_R2_001.fastq.gz') + within('#table-listing') do + assert_no_text 'TestSample_S1_L001_R1_001.fastq.gz' + assert_no_text 'TestSample_S1_L001_R2_001.fastq.gz' + assert_text I18n.t('projects.samples.show.no_files') + assert_text I18n.t('projects.samples.show.no_associated_files') + end + end + + test 'user should not be able to see the upload file button for the sample' do + user = users(:ryan_doe) + login_as user + + visit namespace_project_sample_url(@namespace, @project, @sample1) + + assert_selector 'a', text: I18n.t('projects.samples.index.upload_file'), count: 0 + end + + test 'should concatenate single end attachment files and keep originals' do + visit namespace_project_sample_url(@namespace, @project, @sample1) + within %(turbo-frame[id="table-listing"]) do + assert_selector 'table #attachments-table-body tr', count: 2 + all('input[type=checkbox]').each { |checkbox| checkbox.click unless checkbox.checked? } + end + click_link I18n.t('projects.samples.show.concatenate_button'), match: :first + within('span[data-controller-connected="true"] dialog') do + assert_text 'test_file_A.fastq' + assert_text 'test_file_B.fastq' + fill_in I18n.t('projects.samples.attachments.concatenations.modal.basename'), with: 'concatenated_file' + click_on I18n.t('projects.samples.attachments.concatenations.modal.submit_button') + assert_html5_inputs_valid + end + within %(turbo-frame[id="table-listing"]) do + assert_text 'concatenated_file' + assert_selector 'table #attachments-table-body tr', count: 3 + end + end + + test 'should concatenate paired end attachment files and keep originals' do + login_as users(:jeff_doe) + project = projects(:projectA) + sample = samples(:sampleB) + namespace = namespaces_user_namespaces(:jeff_doe_namespace) + visit namespace_project_sample_url(namespace, project, sample) + within %(turbo-frame[id="table-listing"]) do + assert_selector 'table #attachments-table-body tr', count: 6 + find('table #attachments-table-body tr', text: 'test_file_fwd_1.fastq').find('input').click + find('table #attachments-table-body tr', text: 'test_file_fwd_2.fastq').find('input').click + find('table #attachments-table-body tr', text: 'test_file_fwd_3.fastq').find('input').click + end + click_link I18n.t('projects.samples.show.concatenate_button'), match: :first + within('span[data-controller-connected="true"] dialog') do + assert_text 'test_file_fwd_1.fastq' + assert_text 'test_file_rev_1.fastq' + assert_text 'test_file_fwd_2.fastq' + assert_text 'test_file_rev_2.fastq' + assert_text 'test_file_fwd_3.fastq' + assert_text 'test_file_rev_3.fastq' + fill_in I18n.t('projects.samples.attachments.concatenations.modal.basename'), with: 'concatenated_file' + click_on I18n.t('projects.samples.attachments.concatenations.modal.submit_button') + assert_html5_inputs_valid + end + within %(turbo-frame[id="table-listing"]) do + assert_text 'concatenated_file' + assert_selector 'table #attachments-table-body tr', count: 7 + end + end + + test 'should concatenate single end attachment files and remove originals' do + visit namespace_project_sample_url(@namespace, @project, @sample1) + within %(turbo-frame[id="table-listing"]) do + assert_selector 'table #attachments-table-body tr', count: 2 + all('input[type=checkbox]').each { |checkbox| checkbox.click unless checkbox.checked? } + end + click_link I18n.t('projects.samples.show.concatenate_button'), match: :first + within('span[data-controller-connected="true"] dialog') do + assert_text 'test_file_A.fastq' + assert_text 'test_file_B.fastq' + fill_in I18n.t('projects.samples.attachments.concatenations.modal.basename'), with: 'concatenated_file' + check 'Delete originals' + click_on I18n.t('projects.samples.attachments.concatenations.modal.submit_button') + assert_html5_inputs_valid + end + within %(turbo-frame[id="table-listing"]) do + assert_text 'concatenated_file' + assert_selector 'table #attachments-table-body tr', count: 1 + end + end + + test 'should concatenate paired end attachment files and remove originals' do + login_as users(:jeff_doe) + project = projects(:projectA) + sample = samples(:sampleB) + namespace = namespaces_user_namespaces(:jeff_doe_namespace) + visit namespace_project_sample_url(namespace, project, sample) + within %(turbo-frame[id="table-listing"]) do + assert_selector 'table #attachments-table-body tr', count: 6 + find('table #attachments-table-body tr', text: 'test_file_fwd_1.fastq').find('input').click + find('table #attachments-table-body tr', text: 'test_file_fwd_2.fastq').find('input').click + find('table #attachments-table-body tr', text: 'test_file_fwd_3.fastq').find('input').click + end + click_link I18n.t('projects.samples.show.concatenate_button'), match: :first + within('span[data-controller-connected="true"] dialog') do + assert_text 'test_file_fwd_1.fastq' + assert_text 'test_file_rev_1.fastq' + assert_text 'test_file_fwd_2.fastq' + assert_text 'test_file_rev_2.fastq' + assert_text 'test_file_fwd_3.fastq' + assert_text 'test_file_rev_3.fastq' + fill_in I18n.t('projects.samples.attachments.concatenations.modal.basename'), with: 'concatenated_file' + check 'Delete originals' + click_on I18n.t('projects.samples.attachments.concatenations.modal.submit_button') + assert_html5_inputs_valid + end + within %(turbo-frame[id="table-listing"]) do + assert_text 'concatenated_file_1.fastq' + assert_text 'concatenated_file_2.fastq' + assert_selector 'table #attachments-table-body tr', count: 4 + end + end + + test 'should not concatenate single and paired end attachment files' do + login_as users(:jeff_doe) + project = projects(:projectA) + sample = samples(:sampleB) + namespace = namespaces_user_namespaces(:jeff_doe_namespace) + visit namespace_project_sample_url(namespace, project, sample) + within %(turbo-frame[id="table-listing"]) do + assert_selector 'table #attachments-table-body tr', count: 6 + find('table #attachments-table-body tr', text: 'test_file_fwd_1.fastq').find('input').click + find('table #attachments-table-body tr', text: 'test_file_fwd_2.fastq').find('input').click + find('table #attachments-table-body tr', text: 'test_file_fwd_3.fastq').find('input').click + find('table #attachments-table-body tr', text: 'test_file_D.fastq').find('input').click + end + click_link I18n.t('projects.samples.show.concatenate_button'), match: :first + within('span[data-controller-connected="true"] dialog') do + assert_text 'test_file_fwd_1.fastq' + assert_text 'test_file_rev_1.fastq' + assert_text 'test_file_fwd_2.fastq' + assert_text 'test_file_rev_2.fastq' + assert_text 'test_file_fwd_3.fastq' + assert_text 'test_file_rev_3.fastq' + assert_text 'test_file_D.fastq' + fill_in I18n.t('projects.samples.attachments.concatenations.modal.basename'), with: 'concatenated_file' + click_on I18n.t('projects.samples.attachments.concatenations.modal.submit_button') + assert_html5_inputs_valid + end + within %(turbo-frame[id="concatenation-alert"]) do + assert_text I18n.t('services.attachments.concatenation.incorrect_file_types') + end + end + + test 'should not concatenate compressed and uncompressed attachment files' do + login_as users(:jeff_doe) + project = projects(:projectA) + sample = samples(:sampleB) + namespace = namespaces_user_namespaces(:jeff_doe_namespace) + visit namespace_project_sample_url(namespace, project, sample) + within %(turbo-frame[id="table-listing"]) do + assert_selector 'table #attachments-table-body tr', count: 6 + find('table #attachments-table-body tr', text: 'test_file_D.fastq').find('input').click + find('table #attachments-table-body tr', text: 'test_file_2.fastq').find('input').click + end + click_link I18n.t('projects.samples.show.concatenate_button'), match: :first + within('span[data-controller-connected="true"] dialog') do + assert_text 'test_file_D.fastq' + assert_text 'test_file_2.fastq.gz' + fill_in I18n.t('projects.samples.attachments.concatenations.modal.basename'), with: 'concatenated_file' + click_on I18n.t('projects.samples.attachments.concatenations.modal.submit_button') + assert_html5_inputs_valid + end + within %(turbo-frame[id="concatenation-alert"]) do + assert_text I18n.t('services.attachments.concatenation.incorrect_fastq_file_types') + end + end + + test 'user with guest access should not be able to see the concatenate attachment files button' do + user = users(:ryan_doe) + login_as user + + visit namespace_project_sample_url(@namespace, @project, @sample1) + + assert_selector 'a', text: I18n.t('projects.samples.show.concatenate_button'), count: 0 + end + + test 'shouldn\'t concatenate files as the basename provided is not in the correct format' do + login_as users(:jeff_doe) + project = projects(:projectA) + sample = samples(:sampleB) + namespace = namespaces_user_namespaces(:jeff_doe_namespace) + visit namespace_project_sample_url(namespace, project, sample) + within %(turbo-frame[id="table-listing"]) do + assert_selector 'table #attachments-table-body tr', count: 6 + find('table #attachments-table-body tr', text: 'test_file_fwd_1.fastq').find('input').click + find('table #attachments-table-body tr', text: 'test_file_fwd_2.fastq').find('input').click + find('table #attachments-table-body tr', text: 'test_file_fwd_3.fastq').find('input').click + end + click_link I18n.t('projects.samples.show.concatenate_button'), match: :first + within('span[data-controller-connected="true"] dialog') do + assert_text 'test_file_fwd_1.fastq' + assert_text 'test_file_rev_1.fastq' + assert_text 'test_file_fwd_2.fastq' + assert_text 'test_file_rev_2.fastq' + assert_text 'test_file_fwd_3.fastq' + assert_text 'test_file_rev_3.fastq' + fill_in I18n.t('projects.samples.attachments.concatenations.modal.basename'), with: 'concatenated file' + check 'Delete originals' + click_on I18n.t('projects.samples.attachments.concatenations.modal.submit_button') + !assert_html5_inputs_valid + end + end + + test 'should concatenate files as the basename provided is not in the correct format but fixed after error' do + login_as users(:jeff_doe) + project = projects(:projectA) + sample = samples(:sampleB) + namespace = namespaces_user_namespaces(:jeff_doe_namespace) + visit namespace_project_sample_url(namespace, project, sample) + within %(turbo-frame[id="table-listing"]) do + assert_selector 'table #attachments-table-body tr', count: 6 + find('table #attachments-table-body tr', text: 'test_file_fwd_1.fastq').find('input').click + find('table #attachments-table-body tr', text: 'test_file_fwd_2.fastq').find('input').click + find('table #attachments-table-body tr', text: 'test_file_fwd_3.fastq').find('input').click + end + click_link I18n.t('projects.samples.show.concatenate_button'), match: :first + within('span[data-controller-connected="true"] dialog') do + assert_text 'test_file_fwd_1.fastq' + assert_text 'test_file_rev_1.fastq' + assert_text 'test_file_fwd_2.fastq' + assert_text 'test_file_rev_2.fastq' + assert_text 'test_file_fwd_3.fastq' + assert_text 'test_file_rev_3.fastq' + fill_in I18n.t('projects.samples.attachments.concatenations.modal.basename'), with: 'concatenated file' + check 'Delete originals' + click_on I18n.t('projects.samples.attachments.concatenations.modal.submit_button') + fill_in I18n.t('projects.samples.attachments.concatenations.modal.basename'), with: 'concatenated_file' + click_on I18n.t('projects.samples.attachments.concatenations.modal.submit_button') + assert_html5_inputs_valid + end + within %(turbo-frame[id="table-listing"]) do + assert_text 'concatenated_file_1.fastq' + assert_text 'concatenated_file_2.fastq' + assert_selector 'table #attachments-table-body tr', count: 4 + end + end + + test 'should be able to delete multiple attachments' do + visit namespace_project_sample_url(@namespace, @project, @sample1) + within %(turbo-frame[id="table-listing"]) do + assert_selector 'table #attachments-table-body tr', count: 2 + find('table #attachments-table-body tr', text: 'test_file_A.fastq').find('input').click + find('table #attachments-table-body tr', text: 'test_file_B.fastq').find('input').click + end + click_link I18n.t('projects.samples.show.delete_files_button'), match: :first + within('span[data-controller-connected="true"] dialog') do + assert_text 'test_file_A.fastq' + assert_text 'test_file_B.fastq' + click_on I18n.t('projects.samples.attachments.deletions.modal.submit_button') + assert_html5_inputs_valid + end + assert_text I18n.t('projects.samples.attachments.deletions.destroy.success') + within %(turbo-frame[id="table-listing"]) do + assert_selector 'table #attachments-table-body tr', count: 0 + assert_no_text 'test_file_A.fastq' + assert_no_text 'test_file_B.fastq' + assert_text I18n.t('projects.samples.show.no_files') + assert_text I18n.t('projects.samples.show.no_associated_files') + end + end + + test 'should be able to delete multiple attachments including paired files' do + login_as users(:jeff_doe) + project = projects(:projectA) + sample = samples(:sampleB) + namespace = namespaces_user_namespaces(:jeff_doe_namespace) + visit namespace_project_sample_url(namespace, project, sample) + within %(turbo-frame[id="table-listing"]) do + assert_selector 'table #attachments-table-body tr', count: 6 + find('table #attachments-table-body tr', text: 'test_file_fwd_1.fastq').find('input').click + find('table #attachments-table-body tr', text: 'test_file_fwd_2.fastq').find('input').click + find('table #attachments-table-body tr', text: 'test_file_fwd_3.fastq').find('input').click + find('table #attachments-table-body tr', text: 'test_file_D.fastq').find('input').click + end + click_link I18n.t('projects.samples.show.delete_files_button'), match: :first + within('span[data-controller-connected="true"] dialog') do + assert_text 'test_file_fwd_1.fastq' + assert_text 'test_file_rev_1.fastq' + assert_text 'test_file_fwd_2.fastq' + assert_text 'test_file_rev_2.fastq' + assert_text 'test_file_fwd_3.fastq' + assert_text 'test_file_rev_3.fastq' + assert_text 'test_file_D.fastq' + click_on I18n.t('projects.samples.attachments.deletions.modal.submit_button') + end + assert_text I18n.t('projects.samples.attachments.deletions.destroy.success') + within %(turbo-frame[id="table-listing"]) do + assert_selector 'table #attachments-table-body tr', count: 2 + assert_no_text 'test_file_fwd_1.fastq' + assert_no_text 'test_file_rev_1.fastq' + assert_no_text 'test_file_fwd_2.fastq' + assert_no_text 'test_file_rev_2.fastq' + assert_no_text 'test_file_fwd_3.fastq' + assert_no_text 'test_file_rev_3.fastq' + assert_no_text 'test_file_D.fastq' + end + end + + test 'user can see delete buttons as owner' do + visit namespace_project_sample_url(@namespace, @project, @sample1) + assert_text I18n.t('projects.samples.show.delete_files_button'), count: 1 + within %(turbo-frame[id="table-listing"]) do + assert_selector 'table #attachments-table-body tr', count: 2 + assert_text I18n.t('projects.samples.attachments.attachment.delete'), count: 2 + end + end + + test 'user should not see sample attachment delete buttons if they are non-owner' do + login_as users(:ryan_doe) + visit namespace_project_sample_url(@namespace, @project, @sample1) + assert_text I18n.t('projects.samples.show.delete_files_button'), count: 0 + within %(turbo-frame[id="table-listing"]) do + assert_selector 'table #attachments-table-body tr', count: 2 + assert_text I18n.t('projects.samples.attachments.attachment.delete'), count: 0 + end + end + + test 'user with role >= Maintainer can see attachment checkboxes' do + visit namespace_project_sample_url(@namespace, @project, @sample1) + within %(turbo-frame[id="table-listing"]) do + assert_selector 'table #attachments-table-body input[type=checkbox]', count: 2 + end + end + + test 'user with role < Maintainer should not see checkboxes' do + login_as users(:ryan_doe) + visit namespace_project_sample_url(@namespace, @project, @sample1) + within %(turbo-frame[id="table-listing"]) do + assert_selector 'table #attachments-table-body input[type=checkbox]', count: 0 + end + end + + test 'initially checking off files and click files tab will still have same files checked' do + login_as users(:jeff_doe) + project = projects(:projectA) + sample = samples(:sampleB) + namespace = namespaces_user_namespaces(:jeff_doe_namespace) + visit namespace_project_sample_url(namespace, project, sample) + within %(turbo-frame[id="table-listing"]) do + assert_selector 'table #attachments-table-body tr', count: 6 + all('input[type="checkbox"]')[0].click + all('input[type="checkbox"]')[2].click + all('input[type="checkbox"]')[4].click + end + + click_on I18n.t('projects.samples.show.tabs.metadata') + + within %(#sample-tabs) do + click_on I18n.t('projects.samples.show.tabs.files') + end + + within %(turbo-frame[id="table-listing"]) do + assert all('input[type="checkbox"]')[0].checked? + assert all('input[type="checkbox"]')[2].checked? + assert all('input[type="checkbox"]')[4].checked? + assert_not all('input[type="checkbox"]')[1].checked? + assert_not all('input[type="checkbox"]')[3].checked? + assert_not all('input[type="checkbox"]')[5].checked? + end + end + + test 'delete single attachment with remove link while all attachments selected followed by multiple deletion' do + visit namespace_project_sample_url(@namespace, @project, @sample1) + + within('#attachments-table-body') do + assert_link text: I18n.t('projects.samples.attachments.attachment.delete'), count: 2 + all('input[type=checkbox]').each { |checkbox| checkbox.click unless checkbox.checked? } + click_on I18n.t('projects.samples.attachments.attachment.delete'), match: :first + end + + within('dialog') do + assert_text I18n.t('projects.samples.attachments.delete_attachment_modal.description') + click_button I18n.t('projects.samples.attachments.delete_attachment_modal.submit_button') + end + + assert_text I18n.t('projects.samples.attachments.destroy.success', filename: 'test_file_A.fastq') + within('#table-listing') do + assert_no_text 'test_file_A.fastq' + assert_text 'test_file_B.fastq' + end + + click_link I18n.t('projects.samples.show.delete_files_button'), match: :first + + within('dialog') do + assert_text 'test_file_B.fastq' + assert_no_text 'test_file_A.fastq' + click_button I18n.t('projects.samples.attachments.deletions.modal.submit_button') + end + + assert_text I18n.t('projects.samples.attachments.deletions.destroy.success') + assert_no_text 'test_file_A.fastq' + assert_no_text 'test_file_B.fastq' + assert_text I18n.t('projects.samples.show.no_files') + assert_selector 'a.cursor-not-allowed.pointer-events-none', count: 2 + end + end + end +end diff --git a/test/system/projects/samples/history_test.rb b/test/system/projects/samples/history_test.rb new file mode 100644 index 0000000000..253f6ff23c --- /dev/null +++ b/test/system/projects/samples/history_test.rb @@ -0,0 +1,58 @@ +# frozen_string_literal: true + +require 'application_system_test_case' + +module Projects + module Samples + class HistoryTest < ApplicationSystemTestCase + include ActionView::Helpers::SanitizeHelper + + setup do + @user = users(:john_doe) + login_as @user + @sample1 = samples(:sample1) + @project = projects(:project1) + @namespace = groups(:group_one) + end + + test 'can see the list of sample change versions' do + @sample1.create_logidze_snapshot! + visit namespace_project_sample_path(@namespace, @project, @sample1, tab: 'history') + + within('#table-listing') do + assert_selector 'ol', count: 1 + assert_selector 'li', count: 1 + + assert_selector 'h2', text: I18n.t(:'components.history.link_text', version: 1) + + assert_selector 'p', text: I18n.t(:'components.history.created_by', type: 'Sample', user: 'System') + end + end + + test 'can see sample history version changes' do + @sample1.create_logidze_snapshot! + visit namespace_project_sample_path(@namespace, @project, @sample1, tab: 'history') + click_on 'Version 1' + + within('#sample_modal') do + assert_selector 'h1', text: I18n.t(:'components.history.link_text', version: 1) + assert_selector 'p', text: I18n.t(:'projects.samples.show.history.modal.created_by', + user: 'System') + + assert_no_text I18n.t(:'components.history_version.previous_version') + assert_text I18n.t(:'components.history_version.current_version', version: 1) + + assert_selector 'dt', text: 'name' + assert_selector 'dt', text: 'description' + assert_selector 'dt', text: 'puid' + assert_selector 'dt', text: 'project_id' + + assert_selector 'dd', text: 'Project 1 Sample 1' + assert_selector 'dd', text: 'Sample 1 description.' + assert_selector 'dd', text: @sample1.puid + assert_selector 'dd', text: @sample1.project.id + end + end + end + end +end diff --git a/test/system/projects/samples/metadata_test.rb b/test/system/projects/samples/metadata_test.rb new file mode 100644 index 0000000000..5be2d25609 --- /dev/null +++ b/test/system/projects/samples/metadata_test.rb @@ -0,0 +1,548 @@ +# frozen_string_literal: true + +require 'application_system_test_case' + +module Projects + module Samples + class AttachmentsTest < ApplicationSystemTestCase + include ActionView::Helpers::SanitizeHelper + + setup do + @user = users(:john_doe) + login_as @user + @sample1 = samples(:sample1) + @sample2 = samples(:sample2) + @sample3 = samples(:sample30) + @sample32 = samples(:sample32) + @project = projects(:project1) + @project2 = projects(:projectA) + @project29 = projects(:project29) + @namespace = groups(:group_one) + @group12a = groups(:subgroup_twelve_a) + end + + test 'view sample metadata' do + visit namespace_project_sample_url(@group12a, @project29, @sample32) + + assert_text I18n.t('projects.samples.show.tabs.metadata') + click_on I18n.t('projects.samples.show.tabs.metadata') + + within %(turbo-frame[id="table-listing"]) do + assert_text I18n.t('projects.samples.show.table_header.key').upcase + assert_selector 'table#metadata-table tbody tr', count: 2 + assert_text 'metadatafield1' + assert_text 'value1' + assert_text 'metadatafield2' + assert_text 'value2' + end + end + + test 'update metadata key' do + visit namespace_project_sample_url(@group12a, @project29, @sample32) + + click_on I18n.t('projects.samples.show.tabs.metadata') + + within %(turbo-frame[id="table-listing"]) do + assert_text 'metadatafield1' + assert_text 'value1' + within('tbody tr:first-child td:last-child') do + click_on I18n.t('projects.samples.show.metadata.actions.dropdown.update') + end + end + + within %(turbo-frame[id="sample_modal"]) do + assert_text I18n.t('projects.samples.show.metadata.update.update_metadata') + assert_selector 'input#sample_update_field_key_metadatafield1', count: 1 + assert_selector 'input#sample_update_field_value_value1', count: 1 + find('input#sample_update_field_key_metadatafield1').fill_in with: 'newMetadataKey' + click_on I18n.t('projects.samples.show.metadata.update.update') + end + + assert_text I18n.t('projects.samples.metadata.fields.update.success') + assert_no_text 'metadatafield1' + assert_text 'newmetadatakey' # NOTE: downcase + assert_text 'value1' + end + + test 'update metadata value' do + visit namespace_project_sample_url(@group12a, @project29, @sample32) + + click_on I18n.t('projects.samples.show.tabs.metadata') + + within %(turbo-frame[id="table-listing"]) do + assert_text 'metadatafield1' + assert_text 'value1' + within('tbody tr:first-child td:last-child') do + click_on I18n.t('projects.samples.show.metadata.actions.dropdown.update') + end + end + + within %(turbo-frame[id="sample_modal"]) do + assert_text I18n.t('projects.samples.show.metadata.update.update_metadata') + assert_selector 'input#sample_update_field_key_metadatafield1', count: 1 + assert_selector 'input#sample_update_field_value_value1', count: 1 + find('input#sample_update_field_value_value1').fill_in with: 'newMetadataValue' + click_on I18n.t('projects.samples.show.metadata.update.update') + end + + assert_text I18n.t('projects.samples.metadata.fields.update.success') + assert_no_text 'value1' + assert_text 'metadatafield1' + assert_text 'newMetadataValue' + end + + test 'update both metadata key and value at same time' do + visit namespace_project_sample_url(@group12a, @project29, @sample32) + + click_on I18n.t('projects.samples.show.tabs.metadata') + + within %(turbo-frame[id="table-listing"]) do + assert_text 'metadatafield1' + assert_text 'value1' + within('tbody tr:first-child td:last-child') do + click_on I18n.t('projects.samples.show.metadata.actions.dropdown.update') + end + end + + within %(turbo-frame[id="sample_modal"]) do + assert_text I18n.t('projects.samples.show.metadata.update.update_metadata') + assert_selector 'input#sample_update_field_key_metadatafield1', count: 1 + assert_selector 'input#sample_update_field_value_value1', count: 1 + find('input#sample_update_field_key_metadatafield1').fill_in with: 'newMetadataKey' + find('input#sample_update_field_value_value1').fill_in with: 'newMetadataValue' + click_on I18n.t('projects.samples.show.metadata.update.update') + end + + assert_text I18n.t('projects.samples.metadata.fields.update.success') + assert_no_text 'metadatafield1' + assert_no_text 'value1' + assert_text 'newmetadatakey' # NOTE: downcase + assert_text 'newMetadataValue' + end + + test 'cannot update metadata key with key that already exists' do + visit namespace_project_sample_url(@group12a, @project29, @sample32) + + click_on I18n.t('projects.samples.show.tabs.metadata') + + within %(turbo-frame[id="table-listing"]) do + assert_text 'metadatafield1' + assert_text 'metadatafield2' + within('tbody tr:first-child td:last-child') do + click_on I18n.t('projects.samples.show.metadata.actions.dropdown.update') + end + end + + within %(turbo-frame[id="sample_modal"]) do + assert_text I18n.t('projects.samples.show.metadata.update.update_metadata') + assert_selector 'input#sample_update_field_key_metadatafield1', count: 1 + assert_selector 'input#sample_update_field_value_value1', count: 1 + find('input#sample_update_field_key_metadatafield1').fill_in with: 'metadatafield2' + click_on I18n.t('projects.samples.show.metadata.update.update') + end + + assert_text I18n.t('services.samples.metadata.update_fields.key_exists', key: 'metadatafield2') + end + + test 'user with access level < Maintainer cannot view update action' do + sign_in users(:jane_doe) + visit namespace_project_sample_url(@group12a, @project29, @sample32) + + click_on I18n.t('projects.samples.show.tabs.metadata') + + within %(turbo-frame[id="table-listing"]) do + assert_no_text I18n.t('projects.samples.show.table_header.action').upcase + assert_text 'metadatafield1' + assert_text 'value1' + assert_text 'metadatafield2' + assert_text 'value2' + end + end + + test 'user cannot update metadata added by an analysis' do + @subgroup12aa = groups(:subgroup_twelve_a_a) + @project31 = projects(:project31) + @sample34 = samples(:sample34) + + visit namespace_project_sample_url(@subgroup12aa, @project31, @sample34) + + click_on I18n.t('projects.samples.show.tabs.metadata') + + within %(turbo-frame[id="table-listing"]) do + assert_text 'metadatafield1' + assert_text "#{I18n.t('models.sample.analysis')} 1" + within('tbody tr:first-child td:last-child') do + assert_no_text I18n.t('projects.samples.show.metadata.actions.dropdown.update') + end + end + end + + test 'add single new metadata' do + visit namespace_project_sample_url(@group12a, @project29, @sample32) + + click_on I18n.t('projects.samples.show.tabs.metadata') + click_on I18n.t('projects.samples.show.add_metadata') + + within %(turbo-frame[id="sample_modal"]) do + find('input.keyInput').fill_in with: 'metadatafield3' + find('input.valueInput').fill_in with: 'value3' + click_on I18n.t('projects.samples.metadata.form.submit_button') + end + + assert_text I18n.t('projects.samples.metadata.fields.create.single_success', key: 'metadatafield3') + + within %(turbo-frame[id="table-listing"]) do + assert_selector 'tr#metadatafield3_field' + + within %(tr#metadatafield3_field) do + assert_text 'metadatafield3' + assert_text 'value3' + end + end + end + + test 'add multiple new metadata' do + visit namespace_project_sample_url(@group12a, @project29, @sample32) + + click_on I18n.t('projects.samples.show.tabs.metadata') + click_on I18n.t('projects.samples.show.add_metadata') + + within %(turbo-frame[id="sample_modal"]) do + click_on I18n.t('projects.samples.metadata.form.create_field_button') + all('input.keyInput')[0].fill_in with: 'metadatafield3' + all('input.valueInput')[0].fill_in with: 'value3' + + all('input.keyInput')[1].fill_in with: 'metadatafield4' + all('input.valueInput')[1].fill_in with: 'value4' + click_on I18n.t('projects.samples.metadata.form.submit_button') + end + + assert_text I18n.t('projects.samples.metadata.fields.create.multi_success', + keys: %w[metadatafield3 metadatafield4].join(', ')) + + within %(turbo-frame[id="table-listing"]) do + assert_selector 'tr#metadatafield3_field' + assert_selector 'tr#metadatafield4_field' + + within %(tr#metadatafield3_field) do + assert_text 'metadatafield3' + assert_text 'value3' + end + + within %(tr#metadatafield4_field) do + assert_text 'metadatafield4' + assert_text 'value4' + end + end + end + + test 'add single existing metadata' do + visit namespace_project_sample_url(@group12a, @project29, @sample32) + + click_on I18n.t('projects.samples.show.tabs.metadata') + + within %(turbo-frame[id="table-listing"]) do + assert_selector 'tr#metadatafield1_field' + + within %(tr#metadatafield1_field) do + assert_text 'metadatafield1' + assert_text 'value1' + end + end + + click_on I18n.t('projects.samples.show.add_metadata') + + within %(turbo-frame[id="sample_modal"]) do + find('input.keyInput').fill_in with: 'metadatafield1' + find('input.valueInput').fill_in with: 'newValue1' + click_on I18n.t('projects.samples.metadata.form.submit_button') + end + + assert_text I18n.t('services.samples.metadata.fields.single_all_keys_exist', key: 'metadatafield1') + end + + test 'add multiple existing metadata' do + visit namespace_project_sample_url(@group12a, @project29, @sample32) + + click_on I18n.t('projects.samples.show.tabs.metadata') + + within %(turbo-frame[id="table-listing"]) do + assert_selector 'tr#metadatafield1_field' + + within %(tr#metadatafield1_field) do + assert_text 'metadatafield1' + assert_text 'value1' + end + + assert_selector 'tr#metadatafield2_field' + + within %(tr#metadatafield2_field) do + assert_text 'metadatafield2' + assert_text 'value2' + end + end + + click_on I18n.t('projects.samples.show.add_metadata') + + within %(turbo-frame[id="sample_modal"]) do + click_on I18n.t('projects.samples.metadata.form.create_field_button') + all('input.keyInput')[0].fill_in with: 'metadatafield1' + all('input.valueInput')[0].fill_in with: 'newValue1' + + all('input.keyInput')[1].fill_in with: 'metadatafield2' + all('input.valueInput')[1].fill_in with: 'newValue2' + click_on I18n.t('projects.samples.metadata.form.submit_button') + end + + assert_text I18n.t('services.samples.metadata.fields.multi_all_keys_exist', + keys: %w[metadatafield1 metadatafield2].join(', ')) + end + + test 'add both new and existing metadata' do + visit namespace_project_sample_url(@group12a, @project29, @sample32) + + click_on I18n.t('projects.samples.show.tabs.metadata') + + within %(turbo-frame[id="table-listing"]) do + assert_selector 'tr#metadatafield1_field' + assert_no_selector 'tr#metadatafield3_field' + assert_no_text 'metadatafield3' + + within %(tr#metadatafield1_field) do + assert_text 'metadatafield1' + assert_text 'value1' + end + end + click_on I18n.t('projects.samples.show.add_metadata') + + within %(turbo-frame[id="sample_modal"]) do + click_on I18n.t('projects.samples.metadata.form.create_field_button') + all('input.keyInput')[0].fill_in with: 'metadatafield1' + all('input.valueInput')[0].fill_in with: 'newValue1' + + all('input.keyInput')[1].fill_in with: 'metadatafield3' + all('input.valueInput')[1].fill_in with: 'value3' + click_on I18n.t('projects.samples.metadata.form.submit_button') + end + + assert_text I18n.t('projects.samples.metadata.fields.create.single_success', key: 'metadatafield3') + assert_text I18n.t('projects.samples.metadata.fields.create.single_key_exists', key: 'metadatafield1') + + within %(turbo-frame[id="table-listing"]) do + assert_selector 'tr#metadatafield3_field' + within %(tr#metadatafield3_field) do + assert_text 'metadatafield3' + assert_text 'value3' + end + end + end + + test 'add new metadata after deleting fields' do + visit namespace_project_sample_url(@group12a, @project29, @sample32) + + click_on I18n.t('projects.samples.show.tabs.metadata') + click_on I18n.t('projects.samples.show.add_metadata') + + within %(turbo-frame[id="sample_modal"]) do + click_on I18n.t('projects.samples.metadata.form.create_field_button') + click_on I18n.t('projects.samples.metadata.form.create_field_button') + click_on I18n.t('projects.samples.metadata.form.create_field_button') + all('input.keyInput')[0].fill_in with: 'metadatafield3' + all('input.valueInput')[0].fill_in with: 'value3' + all('input.keyInput')[1].fill_in with: 'metadatafield4' + all('input.valueInput')[1].fill_in with: 'value4' + all('input.keyInput')[2].fill_in with: 'metadatafield5' + all('input.valueInput')[2].fill_in with: 'value5' + all('input.keyInput')[3].fill_in with: 'metadatafield6' + all('input.valueInput')[3].fill_in with: 'value6' + + all('button[data-action="projects--samples--metadata--create#removeField"]')[2].click + all('button[data-action="projects--samples--metadata--create#removeField"]')[1].click + + click_on I18n.t('projects.samples.metadata.form.submit_button') + end + + assert_text I18n.t('projects.samples.metadata.fields.create.multi_success', + keys: %w[metadatafield3 metadatafield6].join(', ')) + + within %(turbo-frame[id="table-listing"]) do + assert_no_text 'metadatafield4' + assert_no_text 'value4' + assert_no_text 'metadatafield5' + assert_no_text 'value5' + + assert_selector 'tr#metadatafield3_field' + within %(tr#metadatafield3_field) do + assert_text 'metadatafield3' + assert_text 'value3' + end + + assert_selector 'tr#metadatafield6_field' + within %(tr#metadatafield6_field) do + assert_text 'metadatafield6' + assert_text 'value6' + end + end + end + + test 'clicking remove button in add modal with one metadata field clears inputs but doesn\'t delete field' do + visit namespace_project_sample_url(@group12a, @project29, @sample32) + + click_on I18n.t('projects.samples.show.tabs.metadata') + click_on I18n.t('projects.samples.show.add_metadata') + + within %(turbo-frame[id="sample_modal"]) do + assert_selector 'input.keyInput', count: 1 + assert_selector 'input.valueInput', count: 1 + + all('button[data-action="projects--samples--metadata--create#removeField"]')[0].click + + assert_selector 'input.keyInput', count: 1 + assert_selector 'input.valueInput', count: 1 + end + end + + test 'user with access < Maintainer cannot see add metadata' do + sign_in users(:jane_doe) + visit namespace_project_sample_url(@group12a, @project29, @sample32) + + click_on I18n.t('projects.samples.show.tabs.metadata') + assert_no_text I18n.t('projects.samples.show.add_metadata') + end + + test 'delete metadata key added by user' do + visit namespace_project_sample_url(@group12a, @project29, @sample32) + + click_on I18n.t('projects.samples.show.tabs.metadata') + + within %(turbo-frame[id="table-listing"]) do + assert_text 'metadatafield1' + assert_text 'value1' + within('tbody tr:first-child td:last-child') do + click_on I18n.t('projects.samples.show.metadata.actions.dropdown.delete') + end + end + + within('#turbo-confirm[open]') do + assert_text I18n.t('projects.samples.show.metadata.actions.delete_confirm', deleted_key: 'metadatafield1') + click_button I18n.t(:'components.confirmation.confirm') + end + + assert_text I18n.t('projects.samples.metadata.destroy.success', deleted_key: 'metadatafield1') + within %(turbo-frame[id="table-listing"]) do + assert_no_text 'metadatafield1' + assert_no_text 'value1' + end + end + + test 'delete metadata key added by anaylsis' do + @subgroup12aa = groups(:subgroup_twelve_a_a) + @project31 = projects(:project31) + @sample34 = samples(:sample34) + + visit namespace_project_sample_url(@subgroup12aa, @project31, @sample34) + + click_on I18n.t('projects.samples.show.tabs.metadata') + + within %(turbo-frame[id="table-listing"]) do + assert_text 'metadatafield1' + assert_text 'value1' + within('tbody tr:first-child td:last-child') do + click_on I18n.t('projects.samples.show.metadata.actions.dropdown.delete') + end + end + + within('#turbo-confirm[open]') do + assert_text I18n.t('projects.samples.show.metadata.actions.delete_confirm', deleted_key: 'metadatafield1') + click_button I18n.t(:'components.confirmation.confirm') + end + + assert_text I18n.t('projects.samples.metadata.destroy.success', deleted_key: 'metadatafield1') + within %(turbo-frame[id="table-listing"]) do + assert_no_text 'metadatafield1' + assert_no_text 'value1' + end + end + + test 'delete one metadata key by delete metadata modal' do + visit namespace_project_sample_url(@group12a, @project29, @sample32) + + click_on I18n.t('projects.samples.show.tabs.metadata') + + within %(turbo-frame[id="table-listing"]) do + assert_text 'metadatafield1' + assert_text 'value1' + find('input#metadatafield1').click + end + + click_on I18n.t('projects.samples.show.delete_metadata_button') + + within %(turbo-frame[id="sample_modal"]) do + assert_text 'metadatafield1' + assert_text 'value1' + click_on I18n.t('projects.samples.metadata.deletions.modal.submit_button') + end + + assert_text I18n.t('projects.samples.metadata.deletions.destroy.single_success', deleted_key: 'metadatafield1') + within %(turbo-frame[id="table-listing"]) do + assert_no_text 'metadatafield1' + assert_no_text 'value1' + end + end + + test 'delete multiple metadata keys by delete metadata modal' do + visit namespace_project_sample_url(@group12a, @project29, @sample32) + + click_on I18n.t('projects.samples.show.tabs.metadata') + + within %(turbo-frame[id="table-listing"]) do + assert_text 'metadatafield1' + assert_text 'value1' + assert_text 'metadatafield2' + assert_text 'value2' + find('input#metadatafield1').click + find('input#metadatafield2').click + end + + click_on I18n.t('projects.samples.show.delete_metadata_button') + + within %(turbo-frame[id="sample_modal"]) do + assert_text 'metadatafield1' + assert_text 'value1' + assert_text 'metadatafield2' + assert_text 'value2' + click_on I18n.t('projects.samples.metadata.deletions.modal.submit_button') + end + + assert_text I18n.t('projects.samples.metadata.deletions.destroy.multi_success', + deleted_keys: 'metadatafield1, metadatafield2') + within %(turbo-frame[id="table-listing"]) do + assert_no_text 'metadatafield1' + assert_no_text 'value1' + assert_no_text 'metadatafield2' + assert_no_text 'value2' + assert_text I18n.t('projects.samples.show.no_metadata') + assert_text I18n.t('projects.samples.show.no_associated_metadata') + end + end + + test 'user with access < Maintainer cannot view delete checkboxes, delete action or delete metadata button' do + sign_in users(:jane_doe) + visit namespace_project_sample_url(@group12a, @project29, @sample32) + + click_on I18n.t('projects.samples.show.tabs.metadata') + + within %(turbo-frame[id="table-listing"]) do + assert_text 'metadatafield1' + assert_text 'value1' + assert_text 'metadatafield2' + assert_text 'value2' + assert_no_selector 'input[type="checkbox"]' + assert_no_text I18n.t('projects.samples.show.table_header.action').upcase + end + + assert_no_selector I18n.t('projects.samples.show.delete_metadata_button') + end + end + end +end diff --git a/test/system/projects/samples_test.rb b/test/system/projects/samples_test.rb index 4f11e63366..d844be715b 100644 --- a/test/system/projects/samples_test.rb +++ b/test/system/projects/samples_test.rb @@ -12,15 +12,10 @@ class SamplesTest < ApplicationSystemTestCase @sample1 = samples(:sample1) @sample2 = samples(:sample2) @sample3 = samples(:sample30) - @sample32 = samples(:sample32) @project = projects(:project1) - @project2 = projects(:projectA) - @project29 = projects(:project29) @namespace = groups(:group_one) - @group12a = groups(:subgroup_twelve_a) Project.reset_counters(@project.id, :samples_count) - Project.reset_counters(@project29.id, :samples_count) end test 'visiting the index' do @@ -67,161 +62,6 @@ class SamplesTest < ApplicationSystemTestCase assert_text @sample1.description end - test 'user with role >= Maintainer should be able to see upload, concatenate and delete files buttons' do - visit namespace_project_sample_url(@namespace, @project, @sample2) - assert_selector 'a', text: I18n.t('projects.samples.show.new_attachment_button'), count: 1 - assert_selector 'a', text: I18n.t('projects.samples.show.concatenate_button'), count: 1 - assert_selector 'a', text: I18n.t('projects.samples.show.delete_files_button'), count: 1 - end - - test 'user with role < Maintainer should not be able to see upload, concatenate and delete files buttons' do - user = users(:ryan_doe) - login_as user - visit namespace_project_sample_url(@namespace, @project, @sample2) - assert_selector 'a', text: I18n.t('projects.samples.show.new_attachment_button'), count: 0 - assert_selector 'a', text: I18n.t('projects.samples.show.concatenate_button'), count: 0 - assert_selector 'a', text: I18n.t('projects.samples.show.delete_files_button'), count: 0 - end - - test 'user with role >= Maintainer should be able to attach a file to a Sample' do - visit namespace_project_sample_url(@namespace, @project, @sample2) - assert_selector 'a', text: I18n.t('projects.samples.show.new_attachment_button'), count: 1 - within('#table-listing') do - assert_text I18n.t('projects.samples.show.no_files') - assert_text I18n.t('projects.samples.show.no_associated_files') - assert_no_text 'test_file_2.fastq.gz' - end - click_on I18n.t('projects.samples.show.upload_files') - - within('dialog') do - attach_file 'attachment[files][]', Rails.root.join('test/fixtures/files/data_export_1.zip') - # check that button goes from being enabled to disabled when clicked - assert_selector 'input[type=submit]:not(:disabled)' - click_on I18n.t('projects.samples.show.upload') - assert_selector 'input[type=submit]:disabled' - end - - assert_text I18n.t('projects.samples.attachments.create.success', filename: 'data_export_1.zip') - within('#table-listing') do - assert_no_text I18n.t('projects.samples.show.no_files') - assert_no_text I18n.t('projects.samples.show.no_associated_files') - assert_text 'data_export_1.zip' - end - end - - test 'user with role >= Maintainer should not be able to attach a duplicate file to a Sample' do - visit namespace_project_sample_url(@namespace, @project, @sample1) - assert_selector 'a', text: I18n.t('projects.samples.show.new_attachment_button'), count: 1 - click_on I18n.t('projects.samples.show.upload_files') - - within('dialog') do - attach_file 'attachment[files][]', Rails.root.join('test/fixtures/files/test_file_2.fastq.gz') - click_on I18n.t('projects.samples.show.upload') - end - click_on I18n.t('projects.samples.show.upload_files') - - within('dialog') do - attach_file 'attachment[files][]', Rails.root.join('test/fixtures/files/test_file_2.fastq.gz') - click_on I18n.t('projects.samples.show.upload') - end - - assert_text 'checksum matches existing file' - end - - test 'user with role >= Maintainer not be able to upload uncompressed files to a Sample' do - visit namespace_project_sample_url(@namespace, @project, @sample1) - assert_selector 'a', text: I18n.t('projects.samples.show.new_attachment_button'), count: 1 - click_on I18n.t('projects.samples.show.upload_files') - - within('dialog') do - attach_file 'attachment[files][]', [Rails.root.join('test/fixtures/files/TestSample_S1_L001_R1_001.fastq.gz'), - Rails.root.join('test/fixtures/files/TestSample_S1_L001_R2_001.fastq.gz'), - Rails.root.join('test/fixtures/files/test_file.fastq')] - assert_text I18n.t('projects.samples.show.files_ignored') - assert_text 'test_file.fastq' - - click_on I18n.t('projects.samples.show.upload') - end - - assert_text I18n.t('projects.samples.attachments.create.success', filename: 'TestSample_S1_L001_R1_001.fastq.gz') - assert_text I18n.t('projects.samples.attachments.create.success', filename: 'TestSample_S1_L001_R2_001.fastq.gz') - assert_no_text I18n.t('projects.samples.attachments.create.success', filename: 'test_file.fastq') - - # View paired files - within('#table-listing') do - assert_text 'TestSample_S1_L001_R1_001.fastq.gz' - assert_text 'TestSample_S1_L001_R2_001.fastq.gz' - end - end - - test 'user with role >= Maintainer should be able to delete a file from a Sample' do - visit namespace_project_sample_url(@namespace, @project, @sample1) - - within('#attachments-table-body') do - assert_link text: I18n.t('projects.samples.attachments.attachment.delete'), count: 2 - click_on I18n.t('projects.samples.attachments.attachment.delete'), match: :first - end - - within('dialog') do - assert_accessible - assert_text I18n.t('projects.samples.attachments.delete_attachment_modal.description') - click_button I18n.t('projects.samples.attachments.delete_attachment_modal.submit_button') - end - - assert_text I18n.t('projects.samples.attachments.destroy.success', filename: 'test_file_A.fastq') - within('#table-listing') do - assert_no_text 'test_file_A.fastq' - end - end - - test 'user with role >= Maintainer should be able to attach, view, and destroy paired files to a Sample' do - visit namespace_project_sample_url(@namespace, @project, @sample2) - # Initial View - assert_selector 'a', text: I18n.t('projects.samples.show.new_attachment_button'), count: 1 - within('#table-listing') do - assert_text I18n.t('projects.samples.show.no_files') - assert_text I18n.t('projects.samples.show.no_associated_files') - assert_selector 'button', text: I18n.t('projects.samples.attachments.attachment.delete'), count: 0 - end - click_on I18n.t('projects.samples.show.upload_files') - - # Attach paired files - within('dialog') do - attach_file 'attachment[files][]', - [Rails.root.join('test/fixtures/files/TestSample_S1_L001_R1_001.fastq.gz'), - Rails.root.join('test/fixtures/files/TestSample_S1_L001_R2_001.fastq.gz')] - click_on I18n.t('projects.samples.show.upload') - end - - assert_text I18n.t('projects.samples.attachments.create.success', filename: 'TestSample_S1_L001_R1_001.fastq.gz') - assert_text I18n.t('projects.samples.attachments.create.success', filename: 'TestSample_S1_L001_R2_001.fastq.gz') - - # View paired files - within('#table-listing') do - assert_text 'TestSample_S1_L001_R1_001.fastq.gz' - assert_text 'TestSample_S1_L001_R2_001.fastq.gz' - assert_link text: I18n.t('projects.samples.attachments.attachment.delete'), count: 1 - end - - # Destroy paired files - within('#attachments-table-body') do - click_on I18n.t('projects.samples.attachments.attachment.delete'), match: :first - end - - within('dialog') do - click_button I18n.t('projects.samples.attachments.delete_attachment_modal.submit_button') - end - - assert_text I18n.t('projects.samples.attachments.destroy.success', filename: 'TestSample_S1_L001_R1_001.fastq.gz') - assert_text I18n.t('projects.samples.attachments.destroy.success', filename: 'TestSample_S1_L001_R2_001.fastq.gz') - within('#table-listing') do - assert_no_text 'TestSample_S1_L001_R1_001.fastq.gz' - assert_no_text 'TestSample_S1_L001_R2_001.fastq.gz' - assert_text I18n.t('projects.samples.show.no_files') - assert_text I18n.t('projects.samples.show.no_associated_files') - end - end - test 'should destroy Sample from sample show page' do visit namespace_project_sample_url(@namespace, @project, @sample1) assert_link text: I18n.t('projects.samples.index.remove_button'), count: 1 @@ -603,15 +443,6 @@ class SamplesTest < ApplicationSystemTestCase assert_selector 'a', text: I18n.t('projects.samples.index.remove_button'), count: 0 end - test 'user should not be able to see the upload file button for the sample' do - user = users(:ryan_doe) - login_as user - - visit namespace_project_sample_url(@namespace, @project, @sample1) - - assert_selector 'a', text: I18n.t('projects.samples.index.upload_file'), count: 0 - end - test 'visiting the index should not allow the current user only edit action' do user = users(:joan_doe) login_as user @@ -970,485 +801,6 @@ class SamplesTest < ApplicationSystemTestCase assert_no_text @sample3.name end - test 'should concatenate single end attachment files and keep originals' do - visit namespace_project_sample_url(@namespace, @project, @sample1) - within %(turbo-frame[id="table-listing"]) do - assert_selector 'table #attachments-table-body tr', count: 2 - all('input[type=checkbox]').each { |checkbox| checkbox.click unless checkbox.checked? } - end - click_link I18n.t('projects.samples.show.concatenate_button'), match: :first - within('span[data-controller-connected="true"] dialog') do - assert_text 'test_file_A.fastq' - assert_text 'test_file_B.fastq' - fill_in I18n.t('projects.samples.attachments.concatenations.modal.basename'), with: 'concatenated_file' - click_on I18n.t('projects.samples.attachments.concatenations.modal.submit_button') - assert_html5_inputs_valid - end - within %(turbo-frame[id="table-listing"]) do - assert_text 'concatenated_file' - assert_selector 'table #attachments-table-body tr', count: 3 - end - end - - test 'should concatenate paired end attachment files and keep originals' do - login_as users(:jeff_doe) - project = projects(:projectA) - sample = samples(:sampleB) - namespace = namespaces_user_namespaces(:jeff_doe_namespace) - visit namespace_project_sample_url(namespace, project, sample) - within %(turbo-frame[id="table-listing"]) do - assert_selector 'table #attachments-table-body tr', count: 6 - find('table #attachments-table-body tr', text: 'test_file_fwd_1.fastq').find('input').click - find('table #attachments-table-body tr', text: 'test_file_fwd_2.fastq').find('input').click - find('table #attachments-table-body tr', text: 'test_file_fwd_3.fastq').find('input').click - end - click_link I18n.t('projects.samples.show.concatenate_button'), match: :first - within('span[data-controller-connected="true"] dialog') do - assert_text 'test_file_fwd_1.fastq' - assert_text 'test_file_rev_1.fastq' - assert_text 'test_file_fwd_2.fastq' - assert_text 'test_file_rev_2.fastq' - assert_text 'test_file_fwd_3.fastq' - assert_text 'test_file_rev_3.fastq' - fill_in I18n.t('projects.samples.attachments.concatenations.modal.basename'), with: 'concatenated_file' - click_on I18n.t('projects.samples.attachments.concatenations.modal.submit_button') - assert_html5_inputs_valid - end - within %(turbo-frame[id="table-listing"]) do - assert_text 'concatenated_file' - assert_selector 'table #attachments-table-body tr', count: 7 - end - end - - test 'should concatenate single end attachment files and remove originals' do - visit namespace_project_sample_url(@namespace, @project, @sample1) - within %(turbo-frame[id="table-listing"]) do - assert_selector 'table #attachments-table-body tr', count: 2 - all('input[type=checkbox]').each { |checkbox| checkbox.click unless checkbox.checked? } - end - click_link I18n.t('projects.samples.show.concatenate_button'), match: :first - within('span[data-controller-connected="true"] dialog') do - assert_text 'test_file_A.fastq' - assert_text 'test_file_B.fastq' - fill_in I18n.t('projects.samples.attachments.concatenations.modal.basename'), with: 'concatenated_file' - check 'Delete originals' - click_on I18n.t('projects.samples.attachments.concatenations.modal.submit_button') - assert_html5_inputs_valid - end - within %(turbo-frame[id="table-listing"]) do - assert_text 'concatenated_file' - assert_selector 'table #attachments-table-body tr', count: 1 - end - end - - test 'should concatenate paired end attachment files and remove originals' do - login_as users(:jeff_doe) - project = projects(:projectA) - sample = samples(:sampleB) - namespace = namespaces_user_namespaces(:jeff_doe_namespace) - visit namespace_project_sample_url(namespace, project, sample) - within %(turbo-frame[id="table-listing"]) do - assert_selector 'table #attachments-table-body tr', count: 6 - find('table #attachments-table-body tr', text: 'test_file_fwd_1.fastq').find('input').click - find('table #attachments-table-body tr', text: 'test_file_fwd_2.fastq').find('input').click - find('table #attachments-table-body tr', text: 'test_file_fwd_3.fastq').find('input').click - end - click_link I18n.t('projects.samples.show.concatenate_button'), match: :first - within('span[data-controller-connected="true"] dialog') do - assert_text 'test_file_fwd_1.fastq' - assert_text 'test_file_rev_1.fastq' - assert_text 'test_file_fwd_2.fastq' - assert_text 'test_file_rev_2.fastq' - assert_text 'test_file_fwd_3.fastq' - assert_text 'test_file_rev_3.fastq' - fill_in I18n.t('projects.samples.attachments.concatenations.modal.basename'), with: 'concatenated_file' - check 'Delete originals' - click_on I18n.t('projects.samples.attachments.concatenations.modal.submit_button') - assert_html5_inputs_valid - end - within %(turbo-frame[id="table-listing"]) do - assert_text 'concatenated_file_1.fastq' - assert_text 'concatenated_file_2.fastq' - assert_selector 'table #attachments-table-body tr', count: 4 - end - end - - test 'should not concatenate single and paired end attachment files' do - login_as users(:jeff_doe) - project = projects(:projectA) - sample = samples(:sampleB) - namespace = namespaces_user_namespaces(:jeff_doe_namespace) - visit namespace_project_sample_url(namespace, project, sample) - within %(turbo-frame[id="table-listing"]) do - assert_selector 'table #attachments-table-body tr', count: 6 - find('table #attachments-table-body tr', text: 'test_file_fwd_1.fastq').find('input').click - find('table #attachments-table-body tr', text: 'test_file_fwd_2.fastq').find('input').click - find('table #attachments-table-body tr', text: 'test_file_fwd_3.fastq').find('input').click - find('table #attachments-table-body tr', text: 'test_file_D.fastq').find('input').click - end - click_link I18n.t('projects.samples.show.concatenate_button'), match: :first - within('span[data-controller-connected="true"] dialog') do - assert_text 'test_file_fwd_1.fastq' - assert_text 'test_file_rev_1.fastq' - assert_text 'test_file_fwd_2.fastq' - assert_text 'test_file_rev_2.fastq' - assert_text 'test_file_fwd_3.fastq' - assert_text 'test_file_rev_3.fastq' - assert_text 'test_file_D.fastq' - fill_in I18n.t('projects.samples.attachments.concatenations.modal.basename'), with: 'concatenated_file' - click_on I18n.t('projects.samples.attachments.concatenations.modal.submit_button') - assert_html5_inputs_valid - end - within %(turbo-frame[id="concatenation-alert"]) do - assert_text I18n.t('services.attachments.concatenation.incorrect_file_types') - end - end - - test 'should not concatenate compressed and uncompressed attachment files' do - login_as users(:jeff_doe) - project = projects(:projectA) - sample = samples(:sampleB) - namespace = namespaces_user_namespaces(:jeff_doe_namespace) - visit namespace_project_sample_url(namespace, project, sample) - within %(turbo-frame[id="table-listing"]) do - assert_selector 'table #attachments-table-body tr', count: 6 - find('table #attachments-table-body tr', text: 'test_file_D.fastq').find('input').click - find('table #attachments-table-body tr', text: 'test_file_2.fastq').find('input').click - end - click_link I18n.t('projects.samples.show.concatenate_button'), match: :first - within('span[data-controller-connected="true"] dialog') do - assert_text 'test_file_D.fastq' - assert_text 'test_file_2.fastq.gz' - fill_in I18n.t('projects.samples.attachments.concatenations.modal.basename'), with: 'concatenated_file' - click_on I18n.t('projects.samples.attachments.concatenations.modal.submit_button') - assert_html5_inputs_valid - end - within %(turbo-frame[id="concatenation-alert"]) do - assert_text I18n.t('services.attachments.concatenation.incorrect_fastq_file_types') - end - end - - test 'user with guest access should not be able to see the concatenate attachment files button' do - user = users(:ryan_doe) - login_as user - - visit namespace_project_sample_url(@namespace, @project, @sample1) - - assert_selector 'a', text: I18n.t('projects.samples.show.concatenate_button'), count: 0 - end - - test 'shouldn\'t concatenate files as the basename provided is not in the correct format' do - login_as users(:jeff_doe) - project = projects(:projectA) - sample = samples(:sampleB) - namespace = namespaces_user_namespaces(:jeff_doe_namespace) - visit namespace_project_sample_url(namespace, project, sample) - within %(turbo-frame[id="table-listing"]) do - assert_selector 'table #attachments-table-body tr', count: 6 - find('table #attachments-table-body tr', text: 'test_file_fwd_1.fastq').find('input').click - find('table #attachments-table-body tr', text: 'test_file_fwd_2.fastq').find('input').click - find('table #attachments-table-body tr', text: 'test_file_fwd_3.fastq').find('input').click - end - click_link I18n.t('projects.samples.show.concatenate_button'), match: :first - within('span[data-controller-connected="true"] dialog') do - assert_text 'test_file_fwd_1.fastq' - assert_text 'test_file_rev_1.fastq' - assert_text 'test_file_fwd_2.fastq' - assert_text 'test_file_rev_2.fastq' - assert_text 'test_file_fwd_3.fastq' - assert_text 'test_file_rev_3.fastq' - fill_in I18n.t('projects.samples.attachments.concatenations.modal.basename'), with: 'concatenated file' - check 'Delete originals' - click_on I18n.t('projects.samples.attachments.concatenations.modal.submit_button') - !assert_html5_inputs_valid - end - end - - test 'should concatenate files as the basename provided is not in the correct format but fixed after error' do - login_as users(:jeff_doe) - project = projects(:projectA) - sample = samples(:sampleB) - namespace = namespaces_user_namespaces(:jeff_doe_namespace) - visit namespace_project_sample_url(namespace, project, sample) - within %(turbo-frame[id="table-listing"]) do - assert_selector 'table #attachments-table-body tr', count: 6 - find('table #attachments-table-body tr', text: 'test_file_fwd_1.fastq').find('input').click - find('table #attachments-table-body tr', text: 'test_file_fwd_2.fastq').find('input').click - find('table #attachments-table-body tr', text: 'test_file_fwd_3.fastq').find('input').click - end - click_link I18n.t('projects.samples.show.concatenate_button'), match: :first - within('span[data-controller-connected="true"] dialog') do - assert_text 'test_file_fwd_1.fastq' - assert_text 'test_file_rev_1.fastq' - assert_text 'test_file_fwd_2.fastq' - assert_text 'test_file_rev_2.fastq' - assert_text 'test_file_fwd_3.fastq' - assert_text 'test_file_rev_3.fastq' - fill_in I18n.t('projects.samples.attachments.concatenations.modal.basename'), with: 'concatenated file' - check 'Delete originals' - click_on I18n.t('projects.samples.attachments.concatenations.modal.submit_button') - fill_in I18n.t('projects.samples.attachments.concatenations.modal.basename'), with: 'concatenated_file' - click_on I18n.t('projects.samples.attachments.concatenations.modal.submit_button') - assert_html5_inputs_valid - end - within %(turbo-frame[id="table-listing"]) do - assert_text 'concatenated_file_1.fastq' - assert_text 'concatenated_file_2.fastq' - assert_selector 'table #attachments-table-body tr', count: 4 - end - end - - test 'should be able to delete multiple attachments' do - visit namespace_project_sample_url(@namespace, @project, @sample1) - within %(turbo-frame[id="table-listing"]) do - assert_selector 'table #attachments-table-body tr', count: 2 - find('table #attachments-table-body tr', text: 'test_file_A.fastq').find('input').click - find('table #attachments-table-body tr', text: 'test_file_B.fastq').find('input').click - end - click_link I18n.t('projects.samples.show.delete_files_button'), match: :first - within('span[data-controller-connected="true"] dialog') do - assert_text 'test_file_A.fastq' - assert_text 'test_file_B.fastq' - click_on I18n.t('projects.samples.attachments.deletions.modal.submit_button') - assert_html5_inputs_valid - end - assert_text I18n.t('projects.samples.attachments.deletions.destroy.success') - within %(turbo-frame[id="table-listing"]) do - assert_selector 'table #attachments-table-body tr', count: 0 - assert_no_text 'test_file_A.fastq' - assert_no_text 'test_file_B.fastq' - assert_text I18n.t('projects.samples.show.no_files') - assert_text I18n.t('projects.samples.show.no_associated_files') - end - end - - test 'should be able to delete multiple attachments including paired files' do - login_as users(:jeff_doe) - project = projects(:projectA) - sample = samples(:sampleB) - namespace = namespaces_user_namespaces(:jeff_doe_namespace) - visit namespace_project_sample_url(namespace, project, sample) - within %(turbo-frame[id="table-listing"]) do - assert_selector 'table #attachments-table-body tr', count: 6 - find('table #attachments-table-body tr', text: 'test_file_fwd_1.fastq').find('input').click - find('table #attachments-table-body tr', text: 'test_file_fwd_2.fastq').find('input').click - find('table #attachments-table-body tr', text: 'test_file_fwd_3.fastq').find('input').click - find('table #attachments-table-body tr', text: 'test_file_D.fastq').find('input').click - end - click_link I18n.t('projects.samples.show.delete_files_button'), match: :first - within('span[data-controller-connected="true"] dialog') do - assert_text 'test_file_fwd_1.fastq' - assert_text 'test_file_rev_1.fastq' - assert_text 'test_file_fwd_2.fastq' - assert_text 'test_file_rev_2.fastq' - assert_text 'test_file_fwd_3.fastq' - assert_text 'test_file_rev_3.fastq' - assert_text 'test_file_D.fastq' - click_on I18n.t('projects.samples.attachments.deletions.modal.submit_button') - end - assert_text I18n.t('projects.samples.attachments.deletions.destroy.success') - within %(turbo-frame[id="table-listing"]) do - assert_selector 'table #attachments-table-body tr', count: 2 - assert_no_text 'test_file_fwd_1.fastq' - assert_no_text 'test_file_rev_1.fastq' - assert_no_text 'test_file_fwd_2.fastq' - assert_no_text 'test_file_rev_2.fastq' - assert_no_text 'test_file_fwd_3.fastq' - assert_no_text 'test_file_rev_3.fastq' - assert_no_text 'test_file_D.fastq' - end - end - - test 'user can see delete buttons as owner' do - visit namespace_project_sample_url(@namespace, @project, @sample1) - assert_text I18n.t('projects.samples.show.delete_files_button'), count: 1 - within %(turbo-frame[id="table-listing"]) do - assert_selector 'table #attachments-table-body tr', count: 2 - assert_text I18n.t('projects.samples.attachments.attachment.delete'), count: 2 - end - end - - test 'user should not see sample attachment delete buttons if they are non-owner' do - login_as users(:ryan_doe) - visit namespace_project_sample_url(@namespace, @project, @sample1) - assert_text I18n.t('projects.samples.show.delete_files_button'), count: 0 - within %(turbo-frame[id="table-listing"]) do - assert_selector 'table #attachments-table-body tr', count: 2 - assert_text I18n.t('projects.samples.attachments.attachment.delete'), count: 0 - end - end - - test 'user with role >= Maintainer can see attachment checkboxes' do - visit namespace_project_sample_url(@namespace, @project, @sample1) - within %(turbo-frame[id="table-listing"]) do - assert_selector 'table #attachments-table-body input[type=checkbox]', count: 2 - end - end - - test 'user with role < Maintainer should not see checkboxes' do - login_as users(:ryan_doe) - visit namespace_project_sample_url(@namespace, @project, @sample1) - within %(turbo-frame[id="table-listing"]) do - assert_selector 'table #attachments-table-body input[type=checkbox]', count: 0 - end - end - - test 'view sample metadata' do - visit namespace_project_sample_url(@group12a, @project29, @sample32) - - assert_text I18n.t('projects.samples.show.tabs.metadata') - click_on I18n.t('projects.samples.show.tabs.metadata') - - within %(turbo-frame[id="table-listing"]) do - assert_text I18n.t('projects.samples.show.table_header.key').upcase - assert_selector 'table#metadata-table tbody tr', count: 2 - assert_text 'metadatafield1' - assert_text 'value1' - assert_text 'metadatafield2' - assert_text 'value2' - end - end - - test 'update metadata key' do - visit namespace_project_sample_url(@group12a, @project29, @sample32) - - click_on I18n.t('projects.samples.show.tabs.metadata') - - within %(turbo-frame[id="table-listing"]) do - assert_text 'metadatafield1' - assert_text 'value1' - within('tbody tr:first-child td:last-child') do - click_on I18n.t('projects.samples.show.metadata.actions.dropdown.update') - end - end - - within %(turbo-frame[id="sample_modal"]) do - assert_text I18n.t('projects.samples.show.metadata.update.update_metadata') - assert_selector 'input#sample_update_field_key_metadatafield1', count: 1 - assert_selector 'input#sample_update_field_value_value1', count: 1 - find('input#sample_update_field_key_metadatafield1').fill_in with: 'newMetadataKey' - click_on I18n.t('projects.samples.show.metadata.update.update') - end - - assert_text I18n.t('projects.samples.metadata.fields.update.success') - assert_no_text 'metadatafield1' - assert_text 'newmetadatakey' # NOTE: downcase - assert_text 'value1' - end - - test 'update metadata value' do - visit namespace_project_sample_url(@group12a, @project29, @sample32) - - click_on I18n.t('projects.samples.show.tabs.metadata') - - within %(turbo-frame[id="table-listing"]) do - assert_text 'metadatafield1' - assert_text 'value1' - within('tbody tr:first-child td:last-child') do - click_on I18n.t('projects.samples.show.metadata.actions.dropdown.update') - end - end - - within %(turbo-frame[id="sample_modal"]) do - assert_text I18n.t('projects.samples.show.metadata.update.update_metadata') - assert_selector 'input#sample_update_field_key_metadatafield1', count: 1 - assert_selector 'input#sample_update_field_value_value1', count: 1 - find('input#sample_update_field_value_value1').fill_in with: 'newMetadataValue' - click_on I18n.t('projects.samples.show.metadata.update.update') - end - - assert_text I18n.t('projects.samples.metadata.fields.update.success') - assert_no_text 'value1' - assert_text 'metadatafield1' - assert_text 'newMetadataValue' - end - - test 'update both metadata key and value at same time' do - visit namespace_project_sample_url(@group12a, @project29, @sample32) - - click_on I18n.t('projects.samples.show.tabs.metadata') - - within %(turbo-frame[id="table-listing"]) do - assert_text 'metadatafield1' - assert_text 'value1' - within('tbody tr:first-child td:last-child') do - click_on I18n.t('projects.samples.show.metadata.actions.dropdown.update') - end - end - - within %(turbo-frame[id="sample_modal"]) do - assert_text I18n.t('projects.samples.show.metadata.update.update_metadata') - assert_selector 'input#sample_update_field_key_metadatafield1', count: 1 - assert_selector 'input#sample_update_field_value_value1', count: 1 - find('input#sample_update_field_key_metadatafield1').fill_in with: 'newMetadataKey' - find('input#sample_update_field_value_value1').fill_in with: 'newMetadataValue' - click_on I18n.t('projects.samples.show.metadata.update.update') - end - - assert_text I18n.t('projects.samples.metadata.fields.update.success') - assert_no_text 'metadatafield1' - assert_no_text 'value1' - assert_text 'newmetadatakey' # NOTE: downcase - assert_text 'newMetadataValue' - end - - test 'cannot update metadata key with key that already exists' do - visit namespace_project_sample_url(@group12a, @project29, @sample32) - - click_on I18n.t('projects.samples.show.tabs.metadata') - - within %(turbo-frame[id="table-listing"]) do - assert_text 'metadatafield1' - assert_text 'metadatafield2' - within('tbody tr:first-child td:last-child') do - click_on I18n.t('projects.samples.show.metadata.actions.dropdown.update') - end - end - - within %(turbo-frame[id="sample_modal"]) do - assert_text I18n.t('projects.samples.show.metadata.update.update_metadata') - assert_selector 'input#sample_update_field_key_metadatafield1', count: 1 - assert_selector 'input#sample_update_field_value_value1', count: 1 - find('input#sample_update_field_key_metadatafield1').fill_in with: 'metadatafield2' - click_on I18n.t('projects.samples.show.metadata.update.update') - end - - assert_text I18n.t('services.samples.metadata.update_fields.key_exists', key: 'metadatafield2') - end - - test 'user with access level < Maintainer cannot view update action' do - sign_in users(:jane_doe) - visit namespace_project_sample_url(@group12a, @project29, @sample32) - - click_on I18n.t('projects.samples.show.tabs.metadata') - - within %(turbo-frame[id="table-listing"]) do - assert_no_text I18n.t('projects.samples.show.table_header.action').upcase - assert_text 'metadatafield1' - assert_text 'value1' - assert_text 'metadatafield2' - assert_text 'value2' - end - end - - test 'user cannot update metadata added by an analysis' do - @subgroup12aa = groups(:subgroup_twelve_a_a) - @project31 = projects(:project31) - @sample34 = samples(:sample34) - - visit namespace_project_sample_url(@subgroup12aa, @project31, @sample34) - - click_on I18n.t('projects.samples.show.tabs.metadata') - - within %(turbo-frame[id="table-listing"]) do - assert_text 'metadatafield1' - assert_text "#{I18n.t('models.sample.analysis')} 1" - within('tbody tr:first-child td:last-child') do - assert_no_text I18n.t('projects.samples.show.metadata.actions.dropdown.update') - end - end - end - test 'should be able to toggle metadata' do visit namespace_project_samples_url(@namespace, @project) @@ -1712,441 +1064,6 @@ class SamplesTest < ApplicationSystemTestCase end end - test 'add single new metadata' do - visit namespace_project_sample_url(@group12a, @project29, @sample32) - - click_on I18n.t('projects.samples.show.tabs.metadata') - click_on I18n.t('projects.samples.show.add_metadata') - - within %(turbo-frame[id="sample_modal"]) do - find('input.keyInput').fill_in with: 'metadatafield3' - find('input.valueInput').fill_in with: 'value3' - click_on I18n.t('projects.samples.metadata.form.submit_button') - end - - assert_text I18n.t('projects.samples.metadata.fields.create.single_success', key: 'metadatafield3') - - within %(turbo-frame[id="table-listing"]) do - assert_selector 'tr#metadatafield3_field' - - within %(tr#metadatafield3_field) do - assert_text 'metadatafield3' - assert_text 'value3' - end - end - end - - test 'add multiple new metadata' do - visit namespace_project_sample_url(@group12a, @project29, @sample32) - - click_on I18n.t('projects.samples.show.tabs.metadata') - click_on I18n.t('projects.samples.show.add_metadata') - - within %(turbo-frame[id="sample_modal"]) do - click_on I18n.t('projects.samples.metadata.form.create_field_button') - all('input.keyInput')[0].fill_in with: 'metadatafield3' - all('input.valueInput')[0].fill_in with: 'value3' - - all('input.keyInput')[1].fill_in with: 'metadatafield4' - all('input.valueInput')[1].fill_in with: 'value4' - click_on I18n.t('projects.samples.metadata.form.submit_button') - end - - assert_text I18n.t('projects.samples.metadata.fields.create.multi_success', - keys: %w[metadatafield3 metadatafield4].join(', ')) - - within %(turbo-frame[id="table-listing"]) do - assert_selector 'tr#metadatafield3_field' - assert_selector 'tr#metadatafield4_field' - - within %(tr#metadatafield3_field) do - assert_text 'metadatafield3' - assert_text 'value3' - end - - within %(tr#metadatafield4_field) do - assert_text 'metadatafield4' - assert_text 'value4' - end - end - end - - test 'add single existing metadata' do - visit namespace_project_sample_url(@group12a, @project29, @sample32) - - click_on I18n.t('projects.samples.show.tabs.metadata') - - within %(turbo-frame[id="table-listing"]) do - assert_selector 'tr#metadatafield1_field' - - within %(tr#metadatafield1_field) do - assert_text 'metadatafield1' - assert_text 'value1' - end - end - - click_on I18n.t('projects.samples.show.add_metadata') - - within %(turbo-frame[id="sample_modal"]) do - find('input.keyInput').fill_in with: 'metadatafield1' - find('input.valueInput').fill_in with: 'newValue1' - click_on I18n.t('projects.samples.metadata.form.submit_button') - end - - assert_text I18n.t('services.samples.metadata.fields.single_all_keys_exist', key: 'metadatafield1') - end - - test 'add multiple existing metadata' do - visit namespace_project_sample_url(@group12a, @project29, @sample32) - - click_on I18n.t('projects.samples.show.tabs.metadata') - - within %(turbo-frame[id="table-listing"]) do - assert_selector 'tr#metadatafield1_field' - - within %(tr#metadatafield1_field) do - assert_text 'metadatafield1' - assert_text 'value1' - end - - assert_selector 'tr#metadatafield2_field' - - within %(tr#metadatafield2_field) do - assert_text 'metadatafield2' - assert_text 'value2' - end - end - - click_on I18n.t('projects.samples.show.add_metadata') - - within %(turbo-frame[id="sample_modal"]) do - click_on I18n.t('projects.samples.metadata.form.create_field_button') - all('input.keyInput')[0].fill_in with: 'metadatafield1' - all('input.valueInput')[0].fill_in with: 'newValue1' - - all('input.keyInput')[1].fill_in with: 'metadatafield2' - all('input.valueInput')[1].fill_in with: 'newValue2' - click_on I18n.t('projects.samples.metadata.form.submit_button') - end - - assert_text I18n.t('services.samples.metadata.fields.multi_all_keys_exist', - keys: %w[metadatafield1 metadatafield2].join(', ')) - end - - test 'add both new and existing metadata' do - visit namespace_project_sample_url(@group12a, @project29, @sample32) - - click_on I18n.t('projects.samples.show.tabs.metadata') - - within %(turbo-frame[id="table-listing"]) do - assert_selector 'tr#metadatafield1_field' - assert_no_selector 'tr#metadatafield3_field' - assert_no_text 'metadatafield3' - - within %(tr#metadatafield1_field) do - assert_text 'metadatafield1' - assert_text 'value1' - end - end - click_on I18n.t('projects.samples.show.add_metadata') - - within %(turbo-frame[id="sample_modal"]) do - click_on I18n.t('projects.samples.metadata.form.create_field_button') - all('input.keyInput')[0].fill_in with: 'metadatafield1' - all('input.valueInput')[0].fill_in with: 'newValue1' - - all('input.keyInput')[1].fill_in with: 'metadatafield3' - all('input.valueInput')[1].fill_in with: 'value3' - click_on I18n.t('projects.samples.metadata.form.submit_button') - end - - assert_text I18n.t('projects.samples.metadata.fields.create.single_success', key: 'metadatafield3') - assert_text I18n.t('projects.samples.metadata.fields.create.single_key_exists', key: 'metadatafield1') - - within %(turbo-frame[id="table-listing"]) do - assert_selector 'tr#metadatafield3_field' - within %(tr#metadatafield3_field) do - assert_text 'metadatafield3' - assert_text 'value3' - end - end - end - - test 'add new metadata after deleting fields' do - visit namespace_project_sample_url(@group12a, @project29, @sample32) - - click_on I18n.t('projects.samples.show.tabs.metadata') - click_on I18n.t('projects.samples.show.add_metadata') - - within %(turbo-frame[id="sample_modal"]) do - click_on I18n.t('projects.samples.metadata.form.create_field_button') - click_on I18n.t('projects.samples.metadata.form.create_field_button') - click_on I18n.t('projects.samples.metadata.form.create_field_button') - all('input.keyInput')[0].fill_in with: 'metadatafield3' - all('input.valueInput')[0].fill_in with: 'value3' - all('input.keyInput')[1].fill_in with: 'metadatafield4' - all('input.valueInput')[1].fill_in with: 'value4' - all('input.keyInput')[2].fill_in with: 'metadatafield5' - all('input.valueInput')[2].fill_in with: 'value5' - all('input.keyInput')[3].fill_in with: 'metadatafield6' - all('input.valueInput')[3].fill_in with: 'value6' - - all('button[data-action="projects--samples--metadata--create#removeField"]')[2].click - all('button[data-action="projects--samples--metadata--create#removeField"]')[1].click - - click_on I18n.t('projects.samples.metadata.form.submit_button') - end - - assert_text I18n.t('projects.samples.metadata.fields.create.multi_success', - keys: %w[metadatafield3 metadatafield6].join(', ')) - - within %(turbo-frame[id="table-listing"]) do - assert_no_text 'metadatafield4' - assert_no_text 'value4' - assert_no_text 'metadatafield5' - assert_no_text 'value5' - - assert_selector 'tr#metadatafield3_field' - within %(tr#metadatafield3_field) do - assert_text 'metadatafield3' - assert_text 'value3' - end - - assert_selector 'tr#metadatafield6_field' - within %(tr#metadatafield6_field) do - assert_text 'metadatafield6' - assert_text 'value6' - end - end - end - - test 'clicking remove button in add modal with one metadata field clears inputs but doesn\'t delete field' do - visit namespace_project_sample_url(@group12a, @project29, @sample32) - - click_on I18n.t('projects.samples.show.tabs.metadata') - click_on I18n.t('projects.samples.show.add_metadata') - - within %(turbo-frame[id="sample_modal"]) do - assert_selector 'input.keyInput', count: 1 - assert_selector 'input.valueInput', count: 1 - - all('button[data-action="projects--samples--metadata--create#removeField"]')[0].click - - assert_selector 'input.keyInput', count: 1 - assert_selector 'input.valueInput', count: 1 - end - end - - test 'user with access < Maintainer cannot see add metadata' do - sign_in users(:jane_doe) - visit namespace_project_sample_url(@group12a, @project29, @sample32) - - click_on I18n.t('projects.samples.show.tabs.metadata') - assert_no_text I18n.t('projects.samples.show.add_metadata') - end - - test 'can see the list of sample change versions' do - @sample1.create_logidze_snapshot! - visit namespace_project_sample_path(@namespace, @project, @sample1, tab: 'history') - - within('#table-listing') do - assert_selector 'ol', count: 1 - assert_selector 'li', count: 1 - - assert_selector 'h2', text: I18n.t(:'components.history.link_text', version: 1) - - assert_selector 'p', text: I18n.t(:'components.history.created_by', type: 'Sample', user: 'System') - end - end - - test 'can see sample history version changes' do - @sample1.create_logidze_snapshot! - visit namespace_project_sample_path(@namespace, @project, @sample1, tab: 'history') - click_on 'Version 1' - - within('#sample_modal') do - assert_selector 'h1', text: I18n.t(:'components.history.link_text', version: 1) - assert_selector 'p', text: I18n.t(:'projects.samples.show.history.modal.created_by', - user: 'System') - - assert_no_text I18n.t(:'components.history_version.previous_version') - assert_text I18n.t(:'components.history_version.current_version', version: 1) - - assert_selector 'dt', text: 'name' - assert_selector 'dt', text: 'description' - assert_selector 'dt', text: 'puid' - assert_selector 'dt', text: 'project_id' - - assert_selector 'dd', text: 'Project 1 Sample 1' - assert_selector 'dd', text: 'Sample 1 description.' - assert_selector 'dd', text: @sample1.puid - assert_selector 'dd', text: @sample1.project.id - end - end - - test 'delete metadata key added by user' do - visit namespace_project_sample_url(@group12a, @project29, @sample32) - - click_on I18n.t('projects.samples.show.tabs.metadata') - - within %(turbo-frame[id="table-listing"]) do - assert_text 'metadatafield1' - assert_text 'value1' - within('tbody tr:first-child td:last-child') do - click_on I18n.t('projects.samples.show.metadata.actions.dropdown.delete') - end - end - - within('#turbo-confirm[open]') do - assert_text I18n.t('projects.samples.show.metadata.actions.delete_confirm', deleted_key: 'metadatafield1') - click_button I18n.t(:'components.confirmation.confirm') - end - - assert_text I18n.t('projects.samples.metadata.destroy.success', deleted_key: 'metadatafield1') - within %(turbo-frame[id="table-listing"]) do - assert_no_text 'metadatafield1' - assert_no_text 'value1' - end - end - - test 'delete metadata key added by anaylsis' do - @subgroup12aa = groups(:subgroup_twelve_a_a) - @project31 = projects(:project31) - @sample34 = samples(:sample34) - - visit namespace_project_sample_url(@subgroup12aa, @project31, @sample34) - - click_on I18n.t('projects.samples.show.tabs.metadata') - - within %(turbo-frame[id="table-listing"]) do - assert_text 'metadatafield1' - assert_text 'value1' - within('tbody tr:first-child td:last-child') do - click_on I18n.t('projects.samples.show.metadata.actions.dropdown.delete') - end - end - - within('#turbo-confirm[open]') do - assert_text I18n.t('projects.samples.show.metadata.actions.delete_confirm', deleted_key: 'metadatafield1') - click_button I18n.t(:'components.confirmation.confirm') - end - - assert_text I18n.t('projects.samples.metadata.destroy.success', deleted_key: 'metadatafield1') - within %(turbo-frame[id="table-listing"]) do - assert_no_text 'metadatafield1' - assert_no_text 'value1' - end - end - - test 'delete one metadata key by delete metadata modal' do - visit namespace_project_sample_url(@group12a, @project29, @sample32) - - click_on I18n.t('projects.samples.show.tabs.metadata') - - within %(turbo-frame[id="table-listing"]) do - assert_text 'metadatafield1' - assert_text 'value1' - find('input#metadatafield1').click - end - - click_on I18n.t('projects.samples.show.delete_metadata_button') - - within %(turbo-frame[id="sample_modal"]) do - assert_text 'metadatafield1' - assert_text 'value1' - click_on I18n.t('projects.samples.metadata.deletions.modal.submit_button') - end - - assert_text I18n.t('projects.samples.metadata.deletions.destroy.single_success', deleted_key: 'metadatafield1') - within %(turbo-frame[id="table-listing"]) do - assert_no_text 'metadatafield1' - assert_no_text 'value1' - end - end - - test 'delete multiple metadata keys by delete metadata modal' do - visit namespace_project_sample_url(@group12a, @project29, @sample32) - - click_on I18n.t('projects.samples.show.tabs.metadata') - - within %(turbo-frame[id="table-listing"]) do - assert_text 'metadatafield1' - assert_text 'value1' - assert_text 'metadatafield2' - assert_text 'value2' - find('input#metadatafield1').click - find('input#metadatafield2').click - end - - click_on I18n.t('projects.samples.show.delete_metadata_button') - - within %(turbo-frame[id="sample_modal"]) do - assert_text 'metadatafield1' - assert_text 'value1' - assert_text 'metadatafield2' - assert_text 'value2' - click_on I18n.t('projects.samples.metadata.deletions.modal.submit_button') - end - - assert_text I18n.t('projects.samples.metadata.deletions.destroy.multi_success', - deleted_keys: 'metadatafield1, metadatafield2') - within %(turbo-frame[id="table-listing"]) do - assert_no_text 'metadatafield1' - assert_no_text 'value1' - assert_no_text 'metadatafield2' - assert_no_text 'value2' - assert_text I18n.t('projects.samples.show.no_metadata') - assert_text I18n.t('projects.samples.show.no_associated_metadata') - end - end - - test 'user with access < Maintainer cannot view delete checkboxes, delete action or delete metadata button' do - sign_in users(:jane_doe) - visit namespace_project_sample_url(@group12a, @project29, @sample32) - - click_on I18n.t('projects.samples.show.tabs.metadata') - - within %(turbo-frame[id="table-listing"]) do - assert_text 'metadatafield1' - assert_text 'value1' - assert_text 'metadatafield2' - assert_text 'value2' - assert_no_selector 'input[type="checkbox"]' - assert_no_text I18n.t('projects.samples.show.table_header.action').upcase - end - - assert_no_selector I18n.t('projects.samples.show.delete_metadata_button') - end - - test 'initially checking off files and click files tab will still have same files checked' do - login_as users(:jeff_doe) - project = projects(:projectA) - sample = samples(:sampleB) - namespace = namespaces_user_namespaces(:jeff_doe_namespace) - visit namespace_project_sample_url(namespace, project, sample) - within %(turbo-frame[id="table-listing"]) do - assert_selector 'table #attachments-table-body tr', count: 6 - all('input[type="checkbox"]')[0].click - all('input[type="checkbox"]')[2].click - all('input[type="checkbox"]')[4].click - end - - click_on I18n.t('projects.samples.show.tabs.metadata') - - within %(#sample-tabs) do - click_on I18n.t('projects.samples.show.tabs.files') - end - - within %(turbo-frame[id="table-listing"]) do - assert all('input[type="checkbox"]')[0].checked? - assert all('input[type="checkbox"]')[2].checked? - assert all('input[type="checkbox"]')[4].checked? - assert_not all('input[type="checkbox"]')[1].checked? - assert_not all('input[type="checkbox"]')[3].checked? - assert_not all('input[type="checkbox"]')[5].checked? - end - end - test 'user with maintainer access should be able to see the clone samples button' do user = users(:joan_doe) login_as user @@ -2590,41 +1507,6 @@ def retrieve_puids assert_selector 'button.cursor-not-allowed.pointer-events-none', count: 1 end - test 'delete single attachment with remove link while all attachments selected followed by multiple deletion' do - visit namespace_project_sample_url(@namespace, @project, @sample1) - - within('#attachments-table-body') do - assert_link text: I18n.t('projects.samples.attachments.attachment.delete'), count: 2 - all('input[type=checkbox]').each { |checkbox| checkbox.click unless checkbox.checked? } - click_on I18n.t('projects.samples.attachments.attachment.delete'), match: :first - end - - within('dialog') do - assert_text I18n.t('projects.samples.attachments.delete_attachment_modal.description') - click_button I18n.t('projects.samples.attachments.delete_attachment_modal.submit_button') - end - - assert_text I18n.t('projects.samples.attachments.destroy.success', filename: 'test_file_A.fastq') - within('#table-listing') do - assert_no_text 'test_file_A.fastq' - assert_text 'test_file_B.fastq' - end - - click_link I18n.t('projects.samples.show.delete_files_button'), match: :first - - within('dialog') do - assert_text 'test_file_B.fastq' - assert_no_text 'test_file_A.fastq' - click_button I18n.t('projects.samples.attachments.deletions.modal.submit_button') - end - - assert_text I18n.t('projects.samples.attachments.deletions.destroy.success') - assert_no_text 'test_file_A.fastq' - assert_no_text 'test_file_B.fastq' - assert_text I18n.t('projects.samples.show.no_files') - assert_selector 'a.cursor-not-allowed.pointer-events-none', count: 2 - end - test 'can filter by large list of sample names or ids' do visit namespace_project_samples_url(@namespace, @project) within '#samples-table table tbody' do