Skip to content

Commit

Permalink
Feature/607 readd projects (#663)
Browse files Browse the repository at this point in the history
* Rewrite education tests for activities

* Add spec that tests the deleting of activities

* Make click_link utilize link text instead of href

* Revert unwanted changes in capybara.rb

* Fix activity specs to not be flaky anymore

* Move code to savely open person_relation create field to helper method and use helper method in specs

* Rewrite logic to open person relation new form and move code to open person relation edit form to helper method

* add default structure

* add structure of old project view and edit

* add tests for projects

* clean up rebase

* use same edit method

---------

Co-authored-by: Jannik Pulfer <[email protected]>
Co-authored-by: Yanick Minder <[email protected]>
  • Loading branch information
3 people authored Apr 18, 2024
1 parent bf5f200 commit bdce658
Show file tree
Hide file tree
Showing 8 changed files with 195 additions and 2 deletions.
6 changes: 6 additions & 0 deletions app/controllers/projects_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# frozen_string_literal: true

class ProjectsController < People::PersonRelationsController
self.permitted_attrs = %i[description title role technology
month_from year_from month_to year_to person_id]
end
3 changes: 2 additions & 1 deletion app/views/people/_cv.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
= render('core_competences')
= render('people/person_relations/index', list: @person.advanced_trainings.list)
= render('people/person_relations/index', list: @person.educations.list)
= render('people/person_relations/index', list: @person.activities.list)
= render('people/person_relations/index', list: @person.activities.list)
= render('people/person_relations/index', list: @person.projects.list)
11 changes: 11 additions & 0 deletions app/views/projects/_form.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
= form_with model: ([entry.person, entry]) do |f|
= render('people/person_relations/form', form: f) do
- content_for :input do
= t "activerecord.attributes.project.title"
= f.text_field :title, placeholder: "Title", class: "form-control w-100"
= t "activerecord.attributes.project.description"
= f.text_area :description, placeholder: "Description", class: "form-control w-100"
= t "activerecord.attributes.project.technology"
= f.text_area :technology, placeholder: "Description", class: "form-control w-100"
= t "activerecord.attributes.project.role"
= f.text_area :role, placeholder: "Description", class: "form-control w-100"
23 changes: 23 additions & 0 deletions app/views/projects/_project.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
%div.border-top
%turbo-frame{id: dom_id(project)}
= link_to edit_person_project_path(project.person, project), data:{turbo_prefetch: :false, turbo_frame: dom_id(project)}, class: "text-decoration-none text-dark bg-hover-gray d-block" do
%div.border.border-secondary-subtle.border-1.d-flex.flex-column
%div.profile-header.mw-100.border-bottom
= "#{date_range_label project} | #{project.title}"
%div.d-flex.flex-column.ms-5.mt-3.mb-3
%div.d-flex.gap-1.flex-column
%div.row
%span.fw-bold.col-12.col-lg-2
= t "activerecord.attributes.project.description"
%span.col
= project.description
%div.row
%span.fw-bold.col-12.col-lg-2
= t "activerecord.attributes.project.role"
%span.col
= project.role
%div.row
%span.fw-bold.col-12.col-lg-2
= t "activerecord.attributes.project.technology"
%span.col
= project.technology
9 changes: 8 additions & 1 deletion config/locales/de.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ de:
cancel: Abbrechen
delete: Löschen
save-and-new: Speichern & Neu
button:
edit: Bearbeiten

attributes:
year_from: Jahr von
Expand All @@ -15,6 +17,7 @@ de:
advanced_training: Weiterbildung
education: Ausbildung
activity: Station
project: Projekt
attributes:
advanced_training:
description: Beschreibung
Expand All @@ -24,7 +27,11 @@ de:
activity:
role: Rolle
description: Firmenangaben und Beschreibung der Tätigkeit

project:
title: Projekt
description: Beschreibung
role: Rolle und Aufgaben
technology: Eingesetzte Technologien
skills:
table:
skill: Skill
Expand Down
1 change: 1 addition & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ en:
cancel: Cancel
delete: Delete
save-and-new: Save & new
edit: Edit
skills:
table:
skill: Skill
Expand Down
2 changes: 2 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
resources :advanced_trainings
resources :educations
resources :activities
resources :projects

member do
get 'export-cv', to: 'people/export_cv#show'
put 'picture', to: 'people/picture#update'
Expand Down
142 changes: 142 additions & 0 deletions spec/features/projects_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
require 'rails_helper'

describe 'Projects', type: :feature, js:true do
let(:person) { people(:bob) }

before(:each) do
sign_in auth_users(:admin)
visit person_path(person)
end

describe 'Crud actions' do
it 'shows all' do
within('turbo-frame#project') do
person.projects.each do |project|
expect(page).to have_content(project.role)
expect(page).to have_content(project.description)
expect(page).to have_content(project.title)
expect(page).to have_content(project.technology)
end
end
end

it 'creates and saves new project' do
role = 'Pressure-washer dealer'
description = 'Deals with pressure-washers'
title = 'new title'
technology = 'This technology'

open_create_form(Project)

within('turbo-frame#new_project') do
select '2024', from: 'project_year_from'
fill_in 'project_role', with: role
fill_in 'project_description', with: description
fill_in 'project_title', with: title
fill_in 'project_technology', with: technology
click_default_submit
end


expect(page).to have_content(role)
expect(page).to have_content(description)
expect(page).to have_content(title)
expect(page).to have_content(technology)
end

it 'Create new with save & new' do
role = "This is a new project with a role created by the save & new functionality"
description = "This is a new project with a description created by the save & new functionality"
title = "This is a new project with a title created by the save & new functionality"
technology = "This is a new project with a technology created by the save & new functionality"

open_create_form(Project)

within('turbo-frame#new_project') do
fill_in 'project_role', with: role
fill_in 'project_description', with: description
fill_in 'project_title', with: title
fill_in 'project_technology', with: technology
select 'Januar', from: 'project_month_from'
select '2020', from: 'project_year_from'

click_save_and_new_submit
end
expect(page).to have_content(role)
expect(page).to have_content(description)
expect(page).to have_content(title)
expect(page).to have_content(technology)

expect(page).to have_select('project_year_from', selected: "")
expect(page).to have_select('project_month_from', selected: "-")
expect(page).to have_field('project_role', with: "")
expect(page).to have_field('project_description', with: "")
expect(page).to have_field('project_title', with: "")
expect(page).to have_field('project_technology', with: "")
end

it 'updates project' do
updated_description = 'I am an updated description'
project = person.projects.first

open_edit_form(project)
within("turbo-frame##{dom_id project}") do
fill_in 'project_description', with: updated_description
click_default_submit
end
expect(page).to have_content(updated_description)
end

it 'cancels without saving' do
project = person.projects.first
old_description = project.description
updated_description = 'I like long descriptions'

open_edit_form(project)
within("turbo-frame##{dom_id project}") do
fill_in 'project_description', with: updated_description
find('a', text: 'Abbrechen').click
end
expect(page).to have_content(old_description)
end

it 'deletes project' do
project = person.projects.first
role = project.role
open_edit_form(project)
within("turbo-frame##{dom_id project}") do
click_link("Löschen")
end
expect(page).not_to have_content(role)
end
end

describe 'Error handling' do
it 'create new project without role' do
open_create_form(Project)

within("turbo-frame##{dom_id Project.new}") do
click_default_submit
end
expect(page).to have_css(".alert.alert-danger", text: "Rolle und Aufgaben muss ausgefüllt werden")
end

it 'Update entry and clear role' do
project = person.projects.first
open_edit_form(project)
within("turbo-frame#project_#{project.id}") do
fill_in 'project_role', with: ""
click_default_submit
end
expect(page).to have_css(".alert.alert-danger", text: "Rolle und Aufgaben muss ausgefüllt werden")
end
end

def click_default_submit
find("button[type='submit'][name='save']").click
end

def click_save_and_new_submit
find("button[type='submit'][name='render_new_after_save']").click
end
end

0 comments on commit bdce658

Please sign in to comment.