@ -9,87 +9,114 @@ RSpec.describe BulkUploadErrorSummaryTableComponent, type: :component do
stub_const ( " BulkUploadErrorSummaryTableComponent::DISPLAY_THRESHOLD " , 0 )
stub_const ( " BulkUploadErrorSummaryTableComponent::DISPLAY_THRESHOLD " , 0 )
end
end
context " when no errors " do
describe " # sorted_errors " do
it " does not renders any tables " do
context " when no errors " do
result = render_inline ( component )
it " does not renders any tables " do
expect ( result ) . not_to have_selector ( " table " )
result = render_inline ( component )
expect ( result ) . not_to have_selector ( " table " )
end
end
end
end
context " when below threshold " do
context " when below threshold " do
before do
before do
stub_const ( " BulkUploadErrorSummaryTableComponent::DISPLAY_THRESHOLD " , 16 )
stub_const ( " BulkUploadErrorSummaryTableComponent::DISPLAY_THRESHOLD " , 16 )
create ( :bulk_upload_error , bulk_upload : , col : " A " , row : 1 )
create ( :bulk_upload_error , bulk_upload : , col : " A " , row : 1 )
end
end
it " does not render tables " do
it " does not render tables " do
result = render_inline ( component )
result = render_inline ( component )
expect ( result ) . to have_selector ( " table " , count : 0 )
expect ( result ) . to have_selector ( " table " , count : 0 )
end
end
end
end
context " when there are 2 independent errors " do
context " when there are 2 independent errors " do
let! ( :error_2 ) { create ( :bulk_upload_error , bulk_upload : , col : " B " , row : 2 ) }
let! ( :error_2 ) { create ( :bulk_upload_error , bulk_upload : , col : " B " , row : 2 ) }
let! ( :error_1 ) { create ( :bulk_upload_error , bulk_upload : , col : " A " , row : 1 ) }
let! ( :error_1 ) { create ( :bulk_upload_error , bulk_upload : , col : " A " , row : 1 ) }
it " renders table for each error " do
it " renders table for each error " do
result = render_inline ( component )
result = render_inline ( component )
expect ( result ) . to have_selector ( " table " , count : 2 )
expect ( result ) . to have_selector ( " table " , count : 2 )
end
end
it " renders by col order " do
it " renders by col order " do
result = render_inline ( component )
result = render_inline ( component )
order = result . css ( " table thead th:nth-of-type(2) " ) . map ( & :content )
order = result . css ( " table thead th:nth-of-type(2) " ) . map ( & :content )
expect ( order ) . to eql ( [ " Column A " , " Column B " ] )
expect ( order ) . to eql ( [ " Column A " , " Column B " ] )
end
end
it " render correct data " do
it " render correct data " do
result = render_inline ( component )
result = render_inline ( component )
table_1 = result . css ( " table " ) . first . css ( " th, td " ) . map ( & :content )
table_1 = result . css ( " table " ) . first . css ( " th, td " ) . map ( & :content )
expect ( table_1 ) . to eql ( [
expect ( table_1 ) . to eql ( [
bulk_upload . prefix_namespace :: RowParser . question_for_field ( error_1 . field . to_sym ) . to_s ,
bulk_upload . prefix_namespace :: RowParser . question_for_field ( error_1 . field . to_sym ) . to_s ,
" Column A " ,
" Column A " ,
error_1 . error ,
error_1 . error ,
" 1 error " ,
" 1 error " ,
] )
] )
table_2 = result . css ( " table " ) [ 1 ] . css ( " th, td " ) . map ( & :content )
table_2 = result . css ( " table " ) [ 1 ] . css ( " th, td " ) . map ( & :content )
expect ( table_2 ) . to eql ( [
expect ( table_2 ) . to eql ( [
bulk_upload . prefix_namespace :: RowParser . question_for_field ( error_2 . field . to_sym ) . to_s ,
bulk_upload . prefix_namespace :: RowParser . question_for_field ( error_2 . field . to_sym ) . to_s ,
" Column B " ,
" Column B " ,
error_2 . error ,
error_2 . error ,
" 1 error " ,
" 1 error " ,
] )
] )
end
end
end
end
context " when there are 2 grouped errors " do
context " when there are 2 grouped errors " do
let! ( :error_1 ) { create ( :bulk_upload_error , bulk_upload : , col : " A " , row : 1 , field : " field_1 " ) }
let! ( :error_1 ) { create ( :bulk_upload_error , bulk_upload : , col : " A " , row : 1 , field : " field_1 " ) }
before do
before do
create ( :bulk_upload_error , bulk_upload : , col : " A " , row : 2 , field : " field_1 " )
create ( :bulk_upload_error , bulk_upload : , col : " A " , row : 2 , field : " field_1 " )
end
end
it " renders 1 table combining the errors " do
result = render_inline ( component )
expect ( result ) . to have_selector ( " table " , count : 1 )
end
it " renders 1 table combining the errors " do
it " render correct data " do
result = render_inline ( component )
result = render_inline ( component )
expect ( result ) . to have_selector ( " table " , count : 1 )
table_1 = result . css ( " table " ) . css ( " th, td " ) . map ( & :content )
expect ( table_1 ) . to eql ( [
bulk_upload . prefix_namespace :: RowParser . question_for_field ( error_1 . field . to_sym ) . to_s ,
" Column A " ,
error_1 . error ,
" 2 errors " ,
] )
end
end
end
it " render correct data " do
context " when mix of setup and other errors " do
result = render_inline ( component )
let! ( :error_1 ) { create ( :bulk_upload_error , bulk_upload : , col : " A " , row : 1 , category : " setup " ) }
table_1 = result . css ( " table " ) . css ( " th, td " ) . map ( & :content )
before do
create ( :bulk_upload_error , bulk_upload : , col : " B " , row : 2 , category : nil )
end
it " only returns the setup errors " do
result = render_inline ( component )
tables = result . css ( " table " )
expect ( table_1 ) . to eql ( [
expect ( tables . size ) . to be ( 1 )
bulk_upload . prefix_namespace :: RowParser . question_for_field ( error_1 . field . to_sym ) . to_s ,
" Column A " ,
table = result . css ( " table " ) . css ( " th, td " ) . map ( & :content )
error_1 . error ,
" 2 errors " ,
expect ( table ) . to eql ( [
] )
bulk_upload . prefix_namespace :: RowParser . question_for_field ( error_1 . field . to_sym ) . to_s ,
" Column A " ,
error_1 . error ,
" 1 error " ,
] )
end
end
end
end
end