-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* 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
1 parent
2ea60d6
commit bf5f200
Showing
14 changed files
with
203 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
app/views/people/person_relations/refresh_after_new.turbo_stream.haml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |