Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TESTING Feature/590 add skill #611

Merged
merged 16 commits into from
Mar 15, 2024
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -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'
5 changes: 5 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -513,6 +517,7 @@ DEPENDENCIES
puma
rack
rails (= 7.0.4.2)
rails-controller-testing (~> 1.0)
rails-erd
rails-i18n
rb-readline
Expand Down
29 changes: 28 additions & 1 deletion spec/controllers/skills_controller_spec.rb
Original file line number Diff line number Diff line change
@@ -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
41 changes: 41 additions & 0 deletions spec/features/skills_form_spec.rb
Original file line number Diff line number Diff line change
@@ -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)
kcinay055679 marked this conversation as resolved.
Show resolved Hide resolved
@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