-
Notifications
You must be signed in to change notification settings - Fork 118
Expand file tree
/
Copy pathannotations_editing_spec.rb
More file actions
104 lines (88 loc) · 4.03 KB
/
annotations_editing_spec.rb
File metadata and controls
104 lines (88 loc) · 4.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# frozen_string_literal: true
require 'rails_helper'
RSpec.feature 'Annotations::Editing', type: :feature do
let!(:funder) { create(:org, :funder) }
let!(:org) { create(:org, :school, :organisation) }
let!(:template) { create(:template, :published, :publicly_visible, org: funder) }
let!(:phase) { create(:phase, template: template) }
let!(:section) { create(:section, phase: phase) }
let!(:question) { create(:question, section: section) }
let!(:annotation) do
create(:annotation, question: question, org: org,
text: 'Foo bar', type: 'example_answer')
end
let!(:user) { create(:user, org: org) }
before do
create(:template, :default, :published)
user.perms << create(:perm, :modify_templates)
user.perms << create(:perm, :add_organisations)
sign_in user
visit org_admin_templates_path
end
scenario 'Admin changes an Annotation of a draft Template', :js do
click_link 'Customisable Templates'
within("#template_#{template.id}") do
click_button 'Actions'
end
expect do
click_link 'Customise'
# `org_admin_template_path(Template.last)` would be preferred over %r{#{org_admin_templates_path}/\d+}
# However, the test is currently evaluating Template.count prior to the new Template being created
expect(page).to have_current_path(%r{#{org_admin_templates_path}/\d+})
end.to change { Template.count }.by(1)
# New Template created
template = Template.last
click_link 'Customise phase'
click_link section.title
within("fieldset#fields_annotation_#{template.annotation_ids.last}") do
id = "question_annotations_attributes_annotation_#{template.annotation_ids.last}_text"
tinymce_fill_in(id, with: 'Noo bar')
end
# NOTE: This is question 2, since Annotation was copied upon clicking "Customise"
within("#edit_question_#{template.question_ids.last}") do
# Expect it to destroy the newly cleared Annotation
expect do
click_button 'Save'
current_path = org_admin_template_phase_path(template,
template.phases.first) +
"?section=#{template.phases.first.sections.first.id}"
expect(page).to have_current_path(current_path)
end.not_to change { Annotation.count }
end
expect(annotation.text).to eql('Foo bar')
expect(Annotation.order('created_at').last.text).to eql('<p>Noo bar</p>')
expect(page).not_to have_errors
end
scenario "Admin sets a Template's question annotation to blank string", :js do
click_link 'Customisable Templates'
within("#template_#{template.id}") do
click_button 'Actions'
end
expect do
click_link 'Customise'
# `org_admin_template_path(Template.last)` would be preferred over %r{#{org_admin_templates_path}/\d+}
# However, the test is currently evaluating Template.count prior to the new Template being created
expect(page).to have_current_path(%r{#{org_admin_templates_path}/\d+})
end.to change { Template.count }.by(1)
template = Template.last
click_link 'Customise phase'
click_link section.title
# NOTE: This is annotation 2, since Annotation was copied upon clicking "Customise"
within("fieldset#fields_annotation_#{template.annotation_ids.last}") do
id = "question_annotations_attributes_annotation_#{template.annotation_ids.last}_text"
tinymce_fill_in(:"#{id}", with: ' ')
end
# NOTE: This is question 2, since Annotation was copied upon clicking "Customise"
within("#edit_question_#{template.question_ids.last}") do
# Expect it to destroy the newly cleared Annotation
expect do
click_button 'Save'
current_path = org_admin_template_phase_path(template,
template.phases.first) +
"?section=#{template.phases.first.sections.first.id}"
expect(page).to have_current_path(current_path)
end.to change { Annotation.count }.by(-1)
end
expect(page).not_to have_errors
end
end