From cd04f6d84137829d23ed252d3cf56a7a2a4c528a Mon Sep 17 00:00:00 2001 From: Till Prochaska Date: Sat, 21 May 2022 13:51:29 +0200 Subject: [PATCH] Add component spec for `ImageInput` --- spec/components/image_input_spec.rb | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/spec/components/image_input_spec.rb b/spec/components/image_input_spec.rb index 710909c82..38faa609a 100644 --- a/spec/components/image_input_spec.rb +++ b/spec/components/image_input_spec.rb @@ -4,7 +4,27 @@ RSpec.describe ImageInput::ImageInput, type: :component do subject { render_inline(described_class.new(**params)) } + let(:params) { { id: :logo } } - let(:params) { {} } it { should have_css('.ImageInput') } + it { should have_css('input[type="file"][id="logo"][name="logo"][hidden]', visible: :all) } + + context 'without existing upload' do + it { should have_text('Noch kein Bild hochgeladen') } + it { should have_css('svg.Icon') } + it { should have_button('Bild hochladen') } + it { should_not have_css('.ImageInput-selectedImage') } + end + + context 'with existing upload' do + let(:file) { fixture_file_upload('example-image.png') } + let(:blob) { ActiveStorage::Blob.create_and_upload!(io: file, filename: file.original_filename) } + + let(:params) { { id: :logo, value: blob } } + + it { should have_text('example-image.png') } + it { should have_css('img[src$="/example-image.png"]') } + it { should have_button('Bild ersetzen') } + it { should_not have_css('.ImageInput-emptyState') } + end end