diff --git a/CHANGELOG.md b/CHANGELOG.md index eb8803d..1a027b2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +v4.13.0 (Month 2024) + - Prevent selecting multiple Issue ID columns + v4.12.0 (May 2024) - Update Dradis links in README diff --git a/app/assets/javascripts/dradis/plugins/csv/upload.js b/app/assets/javascripts/dradis/plugins/csv/upload.js index f1d8353..b9abacd 100644 --- a/app/assets/javascripts/dradis/plugins/csv/upload.js +++ b/app/assets/javascripts/dradis/plugins/csv/upload.js @@ -17,7 +17,8 @@ window.addEventListener('job-done', function () { document.addEventListener('turbolinks:load', function () { if ($('body.upload.new').length) { $('[data-behavior=type-select]').on('change', function () { - var $nodeSelect = $('select option[value="node"]:selected').parent(); + const $nodeSelect = $('select option[value="node"]:selected').parent(), + $idSelect = $('select option[value="identifier"]:selected').parent(); // Disable Node Label option if ($nodeSelect.length) { @@ -31,6 +32,18 @@ document.addEventListener('turbolinks:load', function () { .removeAttr('disabled'); } + // Disable Issue ID Label option + if ($idSelect.length) { + $('[data-behavior=type-select]') + .not($idSelect) + .find('option[value="identifier"]') + .attr('disabled', 'disabled'); + } else { + $('[data-behavior=type-select]') + .find('option[value="identifier"]') + .removeAttr('disabled'); + } + $(this) .parents('tr') .toggleClass('issue-type', $(this).val() == 'issue'); diff --git a/spec/features/upload_spec.rb b/spec/features/upload_spec.rb index ede6fc2..108f38d 100644 --- a/spec/features/upload_spec.rb +++ b/spec/features/upload_spec.rb @@ -1,7 +1,7 @@ require 'rails_helper' # To run, execute from Dradis main app folder: -# bin/rspec [dradis-plugins path]/spec/features/upload_spec.rb +# bin/rspec [dradis-csv path]/spec/features/upload_spec.rb describe 'upload feature', js: true do before do @@ -16,9 +16,7 @@ select 'Dradis::Plugins::CSV', from: 'uploader' - within('.custom-file') do - page.find('#file', visible: false).attach_file(file_path) - end + page.find('#file', visible: false).attach_file(file_path) find('body.upload.new', wait: 30) end @@ -36,7 +34,7 @@ end context 'mapping CSV columns' do - context 'when identifier not selected' do + context 'when the identifier not selected' do it 'shows a validation message on the page' do within all('tbody tr')[3] do select 'Evidence Field' @@ -47,6 +45,18 @@ end end + context 'when the identifier is selected' do + it 'disables all the other identifier option' do + within all('tbody tr')[0] do + select 'Issue ID' + end + + within all('tbody tr')[1] do + expect(find('option', text: 'Issue ID')[:disabled]).to eq('true') + end + end + end + context 'when there are evidence type but no node type selected' do it 'shows a validation message on the page' do within all('tbody tr')[2] do @@ -241,9 +251,7 @@ before do select 'Dradis::Plugins::CSV', from: 'uploader' - within('.custom-file') do - page.find('#file', visible: false).attach_file(file_path) - end + page.find('#file', visible: false).attach_file(file_path) end context 'uploading a malformed CSV file' do