From 2c6c7930a190d56efe4b60c13546dfd18a842560 Mon Sep 17 00:00:00 2001 From: jacobperia Date: Thu, 12 Oct 2023 16:24:31 -0400 Subject: [PATCH] tests for new activity and new users components --- spec/matey/new_activity_component_spec.rb | 28 +++++++++++++++++++++++ spec/matey/new_users_component_spec.rb | 28 +++++++++++++++++++++++ 2 files changed, 56 insertions(+) create mode 100644 spec/matey/new_activity_component_spec.rb create mode 100644 spec/matey/new_users_component_spec.rb diff --git a/spec/matey/new_activity_component_spec.rb b/spec/matey/new_activity_component_spec.rb new file mode 100644 index 0000000..6029130 --- /dev/null +++ b/spec/matey/new_activity_component_spec.rb @@ -0,0 +1,28 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Matey::NewActivityComponent, type: :component do + context 'when ahoy events are present' do + let(:color_scheme) { 'bg-light text-dark border-dark' } + it 'renders the card element' do + subject = render_inline(Matey::NewActivityComponent.new(events: Ahoy::Event.all)) + + expect(subject.css("div[class='card #{color_scheme}']").to_html).not_to be_empty + end + end + + context 'raises an exception when' do + it 'events are missing' do + expect { Matey::NewActivityComponent.new }.to raise_error(ArgumentError) + end + + it 'events are invalid' do + expect { Matey::NewActivityComponent.new(events: nil) }.to raise_error(ArgumentError) + end + + it 'time_window is invalid' do + expect { Matey::NewActivityComponent.new(events: [], time_window: nil) }.to raise_error(ArgumentError) + end + end +end diff --git a/spec/matey/new_users_component_spec.rb b/spec/matey/new_users_component_spec.rb new file mode 100644 index 0000000..2dbc8d7 --- /dev/null +++ b/spec/matey/new_users_component_spec.rb @@ -0,0 +1,28 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Matey::NewUsersComponent, type: :component do + context 'renders component' do + let(:color_scheme) { 'bg-light text-dark border-dark' } + it 'with a card element' do + subject = render_inline(Matey::NewUsersComponent.new(users: User.all)) + + expect(subject.css("div[class='card #{color_scheme}']").to_html).not_to be_empty + end + end + + context 'raises an exception when' do + it 'users are missing' do + expect { Matey::NewUsersComponent.new }.to raise_error(ArgumentError) + end + + it 'users are invalid' do + expect { Matey::NewUsersComponent.new(users: nil) }.to raise_error(ArgumentError) + end + + it 'time_window is invalid' do + expect { Matey::NewUsersComponent.new(users: [], time_window: nil) }.to raise_error(ArgumentError) + end + end +end