<%= _('Add a new section') %>
diff --git a/app/views/phases/_overview.html.erb b/app/views/phases/_overview.html.erb
index f216c85..c89d151 100644
--- a/app/views/phases/_overview.html.erb
+++ b/app/views/phases/_overview.html.erb
@@ -1,5 +1,5 @@
<%# locals: { phase } %>
-
+
<%= _('Instructions') %>
@@ -9,8 +9,7 @@
<%= raw(phase.description) %>
-
-
+
<% phase.sections.each do |s| %>
@@ -25,4 +24,4 @@
<% end %>
-
\ No newline at end of file
+
diff --git a/spec/factories/perms.rb b/spec/factories/perms.rb
index a54255a..8138a87 100644
--- a/spec/factories/perms.rb
+++ b/spec/factories/perms.rb
@@ -11,5 +11,45 @@
FactoryBot.define do
factory :perm do
name { Faker::Company.catch_phrase }
+
+ trait :add_organisations do
+ name 'add_organisations'
+ initialize_with { Perm.find_or_create_by(name: name) }
+ end
+
+ trait :change_org_affiliation do
+ name 'change_org_affiliation'
+ initialize_with { Perm.find_or_create_by(name: name) }
+ end
+
+ trait :grant_permissions do
+ name 'grant_permissions'
+ initialize_with { Perm.find_or_create_by(name: name) }
+ end
+
+ trait :modify_templates do
+ name 'modify_templates'
+ initialize_with { Perm.find_or_create_by(name: name) }
+ end
+
+ trait :modify_guidance do
+ name 'modify_guidance'
+ initialize_with { Perm.find_or_create_by(name: name) }
+ end
+
+ trait :use_api do
+ name 'use_api'
+ initialize_with { Perm.find_or_create_by(name: name) }
+ end
+
+ trait :change_org_details do
+ name 'change_org_details'
+ initialize_with { Perm.find_or_create_by(name: name) }
+ end
+
+ trait :grant_api_to_orgs do
+ name 'grant_api_to_orgs'
+ initialize_with { Perm.find_or_create_by(name: name) }
+ end
end
end
diff --git a/spec/features/templates_spec.rb b/spec/features/templates_spec.rb
new file mode 100644
index 0000000..baa081b
--- /dev/null
+++ b/spec/features/templates_spec.rb
@@ -0,0 +1,57 @@
+require "rails_helper"
+
+RSpec.describe "Templates", type: :feature do
+
+ before do
+ @org = create(:org)
+ @template = create(:template, org: @org, phases: 2)
+ @template.phases.each { |phase| create_list(:section, 2, phase: phase) }
+ @user = create(:user, org: @org)
+ @user.perms << create(:perm, :modify_templates)
+ sign_in(@user)
+ end
+
+ scenario "Org admin edits a template", :js do
+ # Action
+ click_link "Admin"
+ click_link "Templates"
+
+ # Expectations
+ expect(current_path).to eql(organisational_org_admin_templates_path)
+
+ # Action
+ click_button "Actions"
+ click_link "Edit"
+
+ # Expectations
+ expect(current_path).to eql(edit_org_admin_template_path(@template))
+
+ # Action
+ within '#phase_1' do
+ click_link "Edit phase"
+ end
+
+ # Expectations
+ path = edit_org_admin_template_phase_path(@template, @template.phases.first)
+ expect(current_path).to eql(path)
+
+ # Action
+ # Open the panel for a new Section
+ find("a[href='#new_section']").click
+
+ within "#collapseSectionNew" do
+ fill_in :new_section_section_title, with: "My new section"
+ tinymce_fill_in :new_section_section_description,
+ "This is the description of my new section"
+ click_button "Save"
+ end
+
+ # Expectations
+ last_section = Section.last
+ expect(@template.sections.count).to eql(5)
+ expect(last_section.title).to eql("My new section")
+ expect(last_section.description).to match("This is the description of my new section")
+ expect(last_section.description).to match("
")
+ end
+
+end