diff --git a/Gemfile b/Gemfile index 5df1cb378..5faa9c8af 100644 --- a/Gemfile +++ b/Gemfile @@ -79,3 +79,5 @@ group :test do end # Windows does not include zoneinfo files, so bundle the tzinfo-data gem gem 'tzinfo-data', platforms: %i[mingw mswin x64_mingw jruby] + +gem 'rails-controller-testing', '~> 1.0' diff --git a/Gemfile.lock b/Gemfile.lock index 6dfdfbaef..6d00734f1 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -328,6 +328,10 @@ GEM activesupport (= 7.0.4.2) bundler (>= 1.15.0) railties (= 7.0.4.2) + rails-controller-testing (1.0.5) + actionpack (>= 5.0.1.rc1) + actionview (>= 5.0.1.rc1) + activesupport (>= 5.0.1.rc1) rails-dom-testing (2.2.0) activesupport (>= 5.0.0) minitest @@ -513,6 +517,7 @@ DEPENDENCIES puma rack rails (= 7.0.4.2) + rails-controller-testing (~> 1.0) rails-erd rails-i18n rb-readline diff --git a/app/views/skills/form_update.turbo_stream.erb b/app/views/skills/new.turbo_stream.erb similarity index 100% rename from app/views/skills/form_update.turbo_stream.erb rename to app/views/skills/new.turbo_stream.erb diff --git a/spec/controllers/skills_controller_spec.rb b/spec/controllers/skills_controller_spec.rb index 4922b6b08..13e9147ff 100644 --- a/spec/controllers/skills_controller_spec.rb +++ b/spec/controllers/skills_controller_spec.rb @@ -1,19 +1,46 @@ require 'rails_helper' describe SkillsController do - describe 'Update Skill' do + describe 'SkillsController as user' do + before(:each) do + load_pictures sign_in(auth_users(:admin)) end render_views + let(:edited_skill) { {"id" => skills(:rails).id, "category_parent" => categories('system-engineering').id, "title" => "UpdatedSkill", "radar" => "adopt", "portfolio" => "passiv", "default_set" => false, "category_id" => categories(:ruby).id} } + let(:bob) { people(:bob) } + + + it 'index returns all skills ' do + get :index + skills = assigns(:skills) + expect(skills.sort).to eq skills().sort + expect(response).to render_template("index") + end it 'should switch category' do patch :update, params: {id: edited_skill["id"], skill: edited_skill, validate_only: true} expect(response.body).to have_select("skill_category_id", with_options: ['Linux-Engineering']) end + + it 'post returns all skills ' do + title = 'new skill' + category_id = categories(:java).id + radar = "hold" + portfolio = "passiv" + + post :create , params: { skill: { title: title, category_id: category_id, radar: radar, portfolio: portfolio} } + skill = assigns(:skill) + expect(skill.title).to eq title + expect(skill.category_id).to eq category_id + expect(skill.radar).to eq radar + expect(skill.portfolio).to eq portfolio + expect(response).to redirect_to(skills_path) + end end end diff --git a/spec/features/skills_form_spec.rb b/spec/features/skills_form_spec.rb new file mode 100644 index 000000000..fd0c938de --- /dev/null +++ b/spec/features/skills_form_spec.rb @@ -0,0 +1,41 @@ +require 'rails_helper' + + +describe 'Skill Form', type: :feature, js:true do + + before(:each) do + sign_in auth_users(:admin), scope: :auth_user + visit skills_path + click_link(href: new_skill_path) + @category = categories(:ruby) + @radar = "hold" + @portfolio = "passiv" + end + + it 'creates the skill when the form is submitted' do + fill_in 'skill_title', with: 'New Skill Title' + select @category.title, from: 'skill_category_id' + select @radar, from: 'skill_radar' + select @portfolio, from: 'skill_portfolio' + click_button 'Skill erstellen' + # Check for the skill names instead of the amount + expect(page).to have_content('Bash') + expect(page).to have_content('cunit') + expect(page).to have_content('ember') + expect(page).to have_content('JUnit') + expect(page).to have_content('Rails') + expect(page).to have_content('New Skill Title') + end + + it 'displays error messages when present' do + fill_in 'skill_title', with: '' + click_button 'Skill erstellen' + + expect(page).to have_css('.alert.alert-danger') + end + + it 'redirects to the skills index when the cancel button is clicked' do + click_link(href:skills_path, text: "Cancel") + all 'turbo-frame[id^="skill"]', count: 5 + end +end