-
Notifications
You must be signed in to change notification settings - Fork 120
/
Copy pathflow_registration_presenter_with_erb_renderer_test.rb
124 lines (104 loc) · 3.53 KB
/
flow_registration_presenter_with_erb_renderer_test.rb
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
require_relative "../test_helper"
require_relative "../helpers/fixture_flows_helper"
require File.expand_path('../../fixtures/smart_answer_flows/flow-sample', __FILE__)
class FlowRegistrationPresenterWithErbRendererTest < ActiveSupport::TestCase
include FixtureFlowsHelper
def setup
setup_fixture_flows
@flow = SmartAnswer::FlowSampleFlow.new
@flow.use_erb_templates_for_questions
@flow.define
@presenter = FlowRegistrationPresenter.new(@flow)
end
def teardown
teardown_fixture_flows
end
context "slug" do
should "use the flow name" do
assert_equal "flow-sample", @presenter.slug
end
end
context "content_id" do
should "use the flow content_id" do
assert_equal "f26e566e-2557-4921-b944-9373c32255f1", @presenter.content_id
end
end
context "title" do
should "should use the title from the start node template" do
assert_equal "FLOW_TITLE", @presenter.title
end
end
context "need_id" do
should "use the flow's need_id" do
assert_equal 4242, @presenter.need_id
end
end
context "paths" do
should "generate and /flow.name.json" do
assert_equal ["/flow-sample.json"], @presenter.paths
end
end
context "prefixes" do
should "generate /flow.name" do
assert_equal ["/flow-sample"], @presenter.prefixes
end
end
context "description" do
should "use the meta_description from the start node template" do
assert_equal "FLOW_DESCRIPTION", @presenter.description
end
end
context "indexable_content" do
should "include all question node titles" do
@content = @presenter.indexable_content
assert_match %r{QUESTION_1_TITLE}, @content
assert_match %r{QUESTION_2_TITLE}, @content
end
should "not include any outcome node titles" do
@content = @presenter.indexable_content
assert_no_match %r{OUTCOME_1_TITLE}, @content
assert_no_match %r{OUTCOME_2_TITLE}, @content
assert_no_match %r{OUTCOME_3_TITLE}, @content
end
should "include the flow body and question node bodies" do
@content = @presenter.indexable_content
assert_match %r{FLOW_BODY}, @content
assert_match %r{QUESTION_1_BODY}, @content
assert_match %r{QUESTION_2_BODY}, @content
end
should "not include outcome node bodies" do
@content = @presenter.indexable_content
assert_no_match %r{OUTCOME_1_BODY}, @content
assert_no_match %r{OUTCOME_2_BODY}, @content
assert_no_match %r{OUTCOME_3_BODY}, @content
end
should "include all question hints" do
@content = @presenter.indexable_content
assert_match %r{QUESTION_1_HINT}, @content
assert_match %r{QUESTION_2_HINT}, @content
end
should "omit HTML" do
@content = @presenter.indexable_content
assert_no_match %r{<}, @content
assert_match %r{LINK TEXT}, @content
end
should "decode HTML entities" do
@content = @presenter.indexable_content
assert_no_match %r{→}, @content
assert_match %r{→}, @content
end
should "ignore any interpolation errors" do
@flow.multiple_choice(:question_with_interpolation)
@content = @presenter.indexable_content
assert_match %r{FLOW_BODY}, @content
assert_match %r{QUESTION_1_BODY}, @content
assert_match %r{QUESTION_2_BODY}, @content
assert_match %r{QUESTION_WITH_INTERPOLATION_BODY}, @content
end
end
context "state" do
should "always return live, because the FlowRegistry decides what to register" do
assert_equal 'live', @presenter.state
end
end
end