Skip to content

Commit

Permalink
Feature/606 readd stationen (#661)
Browse files Browse the repository at this point in the history
* Implement routes, translations, controller and views for activities in the same way as educations are implemented (ticket #659)

* Rewrite education tests for activities

* Replace hard coded date formating with date range label helper and remove unneeded self.nesting from controller

* Correct name of describe in activities_spec and implement correct turbo-stream method in person relation refresh after new turbostream

* Add test that tests the save new functionality of 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

* Scroll save button of people edit spec into view before clicking it

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

* Add data_turbo_frame parameter to education and activity links

* Remove unnecessary check from advanced trainings spec

* Rewrite comments in person_relations_helper

* Rename method in person relations helpers to match naming conventions
  • Loading branch information
RandomTannenbaum authored Apr 18, 2024
1 parent 2ea60d6 commit bf5f200
Show file tree
Hide file tree
Showing 14 changed files with 203 additions and 16 deletions.
5 changes: 5 additions & 0 deletions app/controllers/activities_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# frozen_string_literal: true

class ActivitiesController < People::PersonRelationsController
self.permitted_attrs = %i[description role month_to year_to month_from year_from person_id]
end
10 changes: 10 additions & 0 deletions app/views/activities/_activity.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
%div.border-top
%turbo-frame{id: dom_id(activity)}
= link_to edit_person_activity_path(@person, activity), data:{turbo_prefetch: :false, turbo_frame: dom_id(activity)}, class: "text-decoration-none text-dark bg-hover-gray d-block" do
%div.d-flex.row.pt-3.pb-5
%span.col-3.ps-5
= date_range_label activity
%span.col.d-flex.flex-column
%span.fw-bolder
= activity.role
= activity.description
7 changes: 7 additions & 0 deletions app/views/activities/_form.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
= form_with model: ([entry.person, entry]) do |f|
= render('people/person_relations/form', form: f) do
- content_for :input do
= t "activerecord.attributes.activity.role"
= f.text_area :role, placeholder: "Rolle", class: "form-control w-100"
= t "activerecord.attributes.activity.description"
= f.text_area :description, placeholder: "Beschreibung", class: "form-control w-100"
2 changes: 1 addition & 1 deletion app/views/educations/_education.html.haml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
%div.border-top
%turbo-frame{id: dom_id(education)}
= link_to edit_person_education_path(@person, education), data:{turbo_prefetch: :false}, class: "text-decoration-none text-dark bg-hover-gray d-block" do
= link_to edit_person_education_path(@person, education), data:{turbo_prefetch: :false, turbo_frame: dom_id(education)}, class: "text-decoration-none text-dark bg-hover-gray d-block" do
%div.d-flex.row.pt-3.pb-5
%span.col-3.ps-5
= date_range_label education
Expand Down
1 change: 1 addition & 0 deletions app/views/people/_cv.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
= 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)
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
= turbo_stream.remove dom_id(entry.class.new)
= turbo_stream.update dom_id(entry.class.new)

= turbo_stream.update name_of_obj(entry) do
= render entries
5 changes: 5 additions & 0 deletions config/locales/de.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,17 @@ de:
models:
advanced_training: Weiterbildung
education: Ausbildung
activity: Station
attributes:
advanced_training:
description: Beschreibung
education:
title: Ausbildung
location: Ausbildungsort
activity:
role: Rolle
description: Firmenangaben und Beschreibung der Tätigkeit

skills:
table:
skill: Skill
Expand Down
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
resources :people do
resources :advanced_trainings
resources :educations
resources :activities
member do
get 'export-cv', to: 'people/export_cv#show'
put 'picture', to: 'people/picture#update'
Expand Down
125 changes: 125 additions & 0 deletions spec/features/activities_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
require 'rails_helper'

describe 'Activities', 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#activity') do
person.activities.each do |activity|
expect(page).to have_content(activity.role)
expect(page).to have_content(activity.description)
end
end
end

it 'creates and saves new activity' do
role = 'Pressure-washer dealer'
description = 'Deals with pressure-washers'

open_create_form(Activity)

within('turbo-frame#new_activity') do
select '2024', from: 'activity_year_from'
fill_in 'activity_role', with: role
fill_in 'activity_description', with: description
click_default_submit
end


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

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

open_create_form(Activity)

within('turbo-frame#new_activity') do
fill_in 'activity_role', with: role
fill_in 'activity_description', with: description
select 'Januar', from: 'activity_month_from'
select '2020', from: 'activity_year_from'

click_save_and_new_submit
end
expect(page).to have_content(role)
expect(page).to have_content(description)
expect(page).to have_select('activity_year_from', selected: "")
expect(page).to have_select('activity_month_from', selected: "-")
expect(page).to have_field('activity_role', with: "")
expect(page).to have_field('activity_description', with: "")
end

it 'updates activity' do
updated_description = 'I am an updated description'

activity = person.activities.first
open_edit_form(activity)
within("turbo-frame#activity_#{activity.id}") do
fill_in 'activity_description', with: updated_description
click_default_submit
end
expect(page).to have_content(updated_description)
end

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

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

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

describe 'Error handling' do
it 'create new activity without role' do
open_create_form(Activity)

within('turbo-frame#new_activity') do
click_default_submit
end
expect(page).to have_css(".alert.alert-danger", text: "Rolle muss ausgefüllt werden")
end

it 'Update entry and clear role' do
activity = person.activities.first
open_edit_form(activity)
within("turbo-frame#activity_#{activity.id}") do
fill_in 'activity_role', with: ""
click_default_submit
end
expect(page).to have_css(".alert.alert-danger", text: "Rolle 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
19 changes: 11 additions & 8 deletions spec/features/advanced_trainings_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@

it 'Create new' do
description = "new description"
click_link(href: new_person_advanced_training_path(person))

open_create_form(AdvancedTraining)

within('turbo-frame#new_advanced_training') do
fill_in 'advanced_training_description', with: description
select '2020', from: 'advanced_training_year_from'
Expand All @@ -29,7 +31,7 @@

it 'Create new with save & new' do
description = "This is a new description created by the save & new functionallity"
click_link(href: new_person_advanced_training_path(person))
open_create_form(AdvancedTraining)

within('turbo-frame#new_advanced_training') do
fill_in 'advanced_training_description', with: description
Expand All @@ -47,8 +49,8 @@
it 'Update entry' do
description = "updated description"
at = person.advanced_trainings.first
open_edit_form(at)
within("turbo-frame#advanced_training_#{at.id}") do
find("[href=\"#{edit_person_advanced_training_path(person, at)}\"]").all("*").first.click
fill_in 'advanced_training_description', with: description
click_default_submit
expect(page).to have_content(description)
Expand All @@ -61,7 +63,7 @@
let(:at) { person.advanced_trainings.first }

before(:each) do
find("[href=\"#{edit_person_advanced_training_path(person, at)}\"]").all("*").first.click
open_edit_form(at)
fill_in 'advanced_training_description', with: "This description"
end

Expand All @@ -84,7 +86,7 @@
describe 'Error handling' do

it 'Create new without description' do
click_link(href: new_person_advanced_training_path(person))
open_create_form(AdvancedTraining)
within('turbo-frame#new_advanced_training') do
select '2020', from: 'advanced_training_year_from'

Expand All @@ -94,7 +96,7 @@
end

it 'year_from cant be empty' do
click_link(href: new_person_advanced_training_path(person))
open_create_form(AdvancedTraining)
within('turbo-frame#new_advanced_training') do
fill_in 'advanced_training_description', with: "This description"

Expand All @@ -105,8 +107,9 @@

it 'Update entry and clear description' do
at = person.advanced_trainings.first

open_edit_form(at)
within("turbo-frame#advanced_training_#{at.id}") do
find("[href=\"#{edit_person_advanced_training_path(person, at)}\"]").all("*").first.click
fill_in 'advanced_training_description', with: ""
click_default_submit
end
Expand All @@ -115,8 +118,8 @@

it 'Update entry and clear description' do
at = person.advanced_trainings.first
open_edit_form(at)
within("turbo-frame#advanced_training_#{at.id}") do
find("[href=\"#{edit_person_advanced_training_path(person, at)}\"]").all("*").first.click
fill_in 'advanced_training_description', with: "This is a test"
select '2020', from: 'advanced_training_year_from'
select '2010', from: 'advanced_training_year_to'
Expand Down
11 changes: 6 additions & 5 deletions spec/features/educations_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
title = 'Döner-Verkäufer'
new_location = 'Dönerbude'

click_link(href: new_person_education_path(person))
open_create_form(Education)

within('turbo-frame#new_education') do
select '2024', from: 'education_year_from'
Expand All @@ -39,8 +39,8 @@
updated_location = 'Dönerbude des Vertrauens'

education = person.educations.first
open_edit_form(education)
within("turbo-frame#education_#{education.id}") do
find("[href=\"#{edit_person_education_path(person, education)}\"]").all("*").first.click
fill_in 'education_location', with: updated_location
click_default_submit
end
Expand All @@ -52,8 +52,9 @@
old_location = education.location
updated_location = 'Dönerbude des Vertrauens'

open_edit_form(education)

within("turbo-frame#education_#{education.id}") do
find("[href=\"#{edit_person_education_path(person, education)}\"]").all("*").first.click
fill_in 'education_location', with: updated_location
find('a', text: 'Abbrechen').click
end
Expand All @@ -63,7 +64,7 @@

describe 'Error handling' do
it 'create new education without title and location' do
click_link(href: new_person_education_path(person))
open_create_form(Education)

within('turbo-frame#new_education') do
click_default_submit
Expand All @@ -74,8 +75,8 @@

it 'Update entry and clear title & description' do
education = person.educations.first
open_edit_form(education)
within("turbo-frame#education_#{education.id}") do
find("[href=\"#{edit_person_education_path(person, education)}\"]").all("*").first.click
fill_in 'education_title', with: ""
fill_in 'education_location', with: ""
click_default_submit
Expand Down
4 changes: 3 additions & 1 deletion spec/features/people_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,9 @@ def add_language(language)
visit person_path(bob)
page.find('#edit-button').click
fill_out_person_form
page.find("#save-button").click
save_button = find_button("Speichern")
scroll_to(save_button, align: :center)
save_button.click
assert_form_persisted(old_number_of_roles)
end

Expand Down
2 changes: 2 additions & 0 deletions spec/rails_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,10 @@
config.include(JsonMacros, type: :controller)
config.include(JsonAssertion, type: :controller)
config.include(ControllerHelpers, type: :controller)
config.include(PersonRelationsHelpers)
config.include(Devise::Test::IntegrationHelpers, type: :feature)
config.include(Devise::Test::ControllerHelpers, type: :controller)
config.include(ActionView::RecordIdentifier, type: :feature)

config.infer_spec_type_from_file_location!
config.filter_rails_from_backtrace!
Expand Down
25 changes: 25 additions & 0 deletions spec/support/person_relations_helpers.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
module PersonRelationsHelpers
#obj_class -> The class of the specific person_relation you want to open the create form for
def open_create_form(obj_class)
element_id = dom_id(obj_class.new)
link = find_by_turbo_frame_id(element_id)
scroll_to(link, align: :center)
link.click
n_children = find("##{element_id}").all("*").count
expect(n_children).to be > 0
end

#element -> The element for which you want to open the edit form (e.g. person.activities.first)
def open_edit_form(element)
element_id = dom_id(element)
html_element = find_by_turbo_frame_id(element_id)
scroll_to(html_element, align: :center)
html_element.click
n_children = find("##{element_id}").all("*").count
expect(n_children).to be > 0
end

def find_by_turbo_frame_id(id)
find("a[data-turbo-frame='#{id}']")
end
end

0 comments on commit bf5f200

Please sign in to comment.