workarea-reviews 3.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (190) hide show
  1. checksums.yaml +7 -0
  2. data/.editorconfig +20 -0
  3. data/.eslintignore +2 -0
  4. data/.eslintrc +24 -0
  5. data/.eslintrc.json +35 -0
  6. data/.github/ISSUE_TEMPLATE/bug_report.md +37 -0
  7. data/.github/ISSUE_TEMPLATE/documentation-request.md +17 -0
  8. data/.github/ISSUE_TEMPLATE/feature_request.md +20 -0
  9. data/.github/workflows/ci.yml +60 -0
  10. data/.gitignore +15 -0
  11. data/.rubocop.yml +3 -0
  12. data/.scss-lint.yml +188 -0
  13. data/.stylelintrc.json +8 -0
  14. data/.yardopts +1 -0
  15. data/CHANGELOG.md +745 -0
  16. data/CODE_OF_CONDUCT.md +3 -0
  17. data/CONTRIBUTING.md +3 -0
  18. data/Gemfile +8 -0
  19. data/LICENSE +52 -0
  20. data/README.md +107 -0
  21. data/Rakefile +53 -0
  22. data/app/assets/images/workarea/admin/icons/star.svg +1 -0
  23. data/app/assets/images/workarea/storefront/icons/empty_star.svg +1 -0
  24. data/app/assets/images/workarea/storefront/icons/half_star.svg +1 -0
  25. data/app/assets/images/workarea/storefront/icons/star.svg +1 -0
  26. data/app/assets/javascripts/workarea/storefront/reviews/modules/product_review_ajax_submit.js +39 -0
  27. data/app/assets/javascripts/workarea/storefront/reviews/modules/product_reviews_sort_menus.js +82 -0
  28. data/app/assets/javascripts/workarea/storefront/reviews/modules/rating_buttons.js +103 -0
  29. data/app/assets/javascripts/workarea/storefront/reviews/templates/sort_by_property.jst.ejs +11 -0
  30. data/app/assets/stylesheets/workarea/storefront/reviews/components/_rating.scss +28 -0
  31. data/app/assets/stylesheets/workarea/storefront/reviews/components/_reviews.scss +59 -0
  32. data/app/assets/stylesheets/workarea/storefront/reviews/components/_reviews_aggregate.scss +38 -0
  33. data/app/assets/stylesheets/workarea/storefront/reviews/components/_write_review.scss +63 -0
  34. data/app/controllers/workarea/admin/catalog_products_controller.decorator +9 -0
  35. data/app/controllers/workarea/admin/reports_controller.decorator +10 -0
  36. data/app/controllers/workarea/admin/reviews_controller.rb +51 -0
  37. data/app/controllers/workarea/storefront/review_requests_controller.rb +50 -0
  38. data/app/controllers/workarea/storefront/reviews_controller.rb +53 -0
  39. data/app/helpers/workarea/admin/reviews_helper.rb +13 -0
  40. data/app/helpers/workarea/storefront/reviews_helper.rb +22 -0
  41. data/app/helpers/workarea/storefront/reviews_schema_org_helper.rb +34 -0
  42. data/app/mailers/workarea/admin/status_report_mailer.decorator +8 -0
  43. data/app/mailers/workarea/storefront/review_mailer.rb +23 -0
  44. data/app/models/workarea/catalog/product.decorator +15 -0
  45. data/app/models/workarea/fulfillment.decorator +11 -0
  46. data/app/models/workarea/insights/most_active_reviewers.rb +34 -0
  47. data/app/models/workarea/insights/most_reviewed_products.rb +33 -0
  48. data/app/models/workarea/insights/top_rated_products.rb +33 -0
  49. data/app/models/workarea/review.rb +124 -0
  50. data/app/models/workarea/review/request.rb +62 -0
  51. data/app/models/workarea/search/admin/review.rb +72 -0
  52. data/app/models/workarea/search/storefront/product.decorator +9 -0
  53. data/app/models/workarea/sort.decorator +17 -0
  54. data/app/queries/workarea/reports/reviews_by_product.rb +86 -0
  55. data/app/queries/workarea/reports/reviews_by_user.rb +71 -0
  56. data/app/queries/workarea/review_request_params.rb +47 -0
  57. data/app/queries/workarea/review_summary.rb +11 -0
  58. data/app/queries/workarea/search/admin_reviews.rb +40 -0
  59. data/app/queries/workarea/search/category_browse.decorator +9 -0
  60. data/app/queries/workarea/search/product_search.decorator +9 -0
  61. data/app/seeds/workarea/review_seeds.rb +49 -0
  62. data/app/services/workarea/create_review.rb +99 -0
  63. data/app/view_models/workarea/admin/dashboards/reports_view_model.decorator +11 -0
  64. data/app/view_models/workarea/admin/product_view_model.decorator +7 -0
  65. data/app/view_models/workarea/admin/reports/reviews_by_product_view_model.rb +27 -0
  66. data/app/view_models/workarea/admin/review_view_model.rb +23 -0
  67. data/app/view_models/workarea/admin/reviews_search_view_model.rb +46 -0
  68. data/app/view_models/workarea/storefront/product_view_model.decorator +13 -0
  69. data/app/view_models/workarea/storefront/review_view_model.rb +14 -0
  70. data/app/views/workarea/admin/activities/_review_create.html.haml +12 -0
  71. data/app/views/workarea/admin/activities/_review_destroy.html.haml +10 -0
  72. data/app/views/workarea/admin/activities/_review_update.html.haml +10 -0
  73. data/app/views/workarea/admin/dashboards/_reviews_by_product_card.html.haml +17 -0
  74. data/app/views/workarea/admin/insights/_most_active_reviewers.html.haml +22 -0
  75. data/app/views/workarea/admin/insights/_most_reviewed_products.html.haml +22 -0
  76. data/app/views/workarea/admin/insights/_top_rated_products.html.haml +22 -0
  77. data/app/views/workarea/admin/reports/reviews_by_product.html.haml +44 -0
  78. data/app/views/workarea/admin/reviews/_aux_navigation.html.haml +5 -0
  79. data/app/views/workarea/admin/reviews/_catalog_products_aux_link.html.haml +5 -0
  80. data/app/views/workarea/admin/reviews/_dashboard_navigation.html.haml +1 -0
  81. data/app/views/workarea/admin/reviews/_menu.html.haml +3 -0
  82. data/app/views/workarea/admin/reviews/_summary.html.haml +12 -0
  83. data/app/views/workarea/admin/reviews/edit.html.haml +77 -0
  84. data/app/views/workarea/admin/reviews/index.html.haml +74 -0
  85. data/app/views/workarea/admin/status_report_mailer/_reviews.html.haml +5 -0
  86. data/app/views/workarea/storefront/products/_rating.html.haml +9 -0
  87. data/app/views/workarea/storefront/products/_reviews.html.haml +23 -0
  88. data/app/views/workarea/storefront/products/_reviews_aggregate.html.haml +22 -0
  89. data/app/views/workarea/storefront/products/_reviews_summary.html.haml +2 -0
  90. data/app/views/workarea/storefront/review_mailer/review_request.html.haml +24 -0
  91. data/app/views/workarea/storefront/review_requests/show.html.haml +45 -0
  92. data/app/views/workarea/storefront/reviews/new.html.haml +68 -0
  93. data/app/views/workarea/storefront/style_guides/_reviews_product_summary_docs.html.haml +13 -0
  94. data/app/views/workarea/storefront/style_guides/components/_reviews.html.haml +17 -0
  95. data/app/workers/workarea/create_review_requests.rb +33 -0
  96. data/app/workers/workarea/schedule_review_requests.rb +44 -0
  97. data/app/workers/workarea/send_review_requests.rb +12 -0
  98. data/app/workers/workarea/update_product_review_data.rb +26 -0
  99. data/bin/rails +18 -0
  100. data/config/initializers/append_points.rb +75 -0
  101. data/config/initializers/assets.rb +1 -0
  102. data/config/initializers/configuration.rb +31 -0
  103. data/config/initializers/rack_attack.rb +11 -0
  104. data/config/initializers/recaptcha.rb +19 -0
  105. data/config/initializers/scheduled_jobs.rb +8 -0
  106. data/config/locales/en.yml +150 -0
  107. data/config/routes.rb +25 -0
  108. data/lib/tasks/verify.rake +16 -0
  109. data/lib/workarea/mailer_previews/storefront/review_mailer_preview.rb +10 -0
  110. data/lib/workarea/reviews.rb +13 -0
  111. data/lib/workarea/reviews/engine.rb +16 -0
  112. data/lib/workarea/reviews/version.rb +5 -0
  113. data/package.json +9 -0
  114. data/test/dummy/Rakefile +6 -0
  115. data/test/dummy/app/assets/config/manifest.js +4 -0
  116. data/test/dummy/app/assets/images/.keep +0 -0
  117. data/test/dummy/app/assets/javascripts/application.js +13 -0
  118. data/test/dummy/app/assets/stylesheets/application.css +15 -0
  119. data/test/dummy/app/controllers/application_controller.rb +3 -0
  120. data/test/dummy/app/controllers/concerns/.keep +0 -0
  121. data/test/dummy/app/helpers/application_helper.rb +2 -0
  122. data/test/dummy/app/jobs/application_job.rb +2 -0
  123. data/test/dummy/app/mailers/application_mailer.rb +4 -0
  124. data/test/dummy/app/models/concerns/.keep +0 -0
  125. data/test/dummy/app/views/layouts/application.html.erb +14 -0
  126. data/test/dummy/app/views/layouts/mailer.html.erb +13 -0
  127. data/test/dummy/app/views/layouts/mailer.text.erb +1 -0
  128. data/test/dummy/bin/bundle +3 -0
  129. data/test/dummy/bin/rails +4 -0
  130. data/test/dummy/bin/rake +4 -0
  131. data/test/dummy/bin/setup +34 -0
  132. data/test/dummy/bin/update +29 -0
  133. data/test/dummy/config.ru +5 -0
  134. data/test/dummy/config/application.rb +25 -0
  135. data/test/dummy/config/boot.rb +5 -0
  136. data/test/dummy/config/cable.yml +9 -0
  137. data/test/dummy/config/environment.rb +5 -0
  138. data/test/dummy/config/environments/development.rb +55 -0
  139. data/test/dummy/config/environments/production.rb +86 -0
  140. data/test/dummy/config/environments/test.rb +43 -0
  141. data/test/dummy/config/initializers/application_controller_renderer.rb +6 -0
  142. data/test/dummy/config/initializers/assets.rb +11 -0
  143. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  144. data/test/dummy/config/initializers/cookies_serializer.rb +5 -0
  145. data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  146. data/test/dummy/config/initializers/inflections.rb +16 -0
  147. data/test/dummy/config/initializers/mime_types.rb +4 -0
  148. data/test/dummy/config/initializers/new_framework_defaults.rb +21 -0
  149. data/test/dummy/config/initializers/session_store.rb +5 -0
  150. data/test/dummy/config/initializers/workarea.rb +5 -0
  151. data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
  152. data/test/dummy/config/locales/en.yml +23 -0
  153. data/test/dummy/config/puma.rb +47 -0
  154. data/test/dummy/config/routes.rb +5 -0
  155. data/test/dummy/config/secrets.yml +22 -0
  156. data/test/dummy/config/spring.rb +6 -0
  157. data/test/dummy/db/seeds.rb +2 -0
  158. data/test/dummy/lib/assets/.keep +0 -0
  159. data/test/dummy/log/.keep +0 -0
  160. data/test/factories/reviews.rb +32 -0
  161. data/test/fixtures/reviews.csv +5 -0
  162. data/test/helpers/workarea/storefront/reviews_helper_test.rb +20 -0
  163. data/test/integration/workarea/admin/reviews_integration_test.rb +37 -0
  164. data/test/integration/workarea/storefront/review_requests_integration_test.rb +63 -0
  165. data/test/integration/workarea/storefront/reviews_integration_test.rb +82 -0
  166. data/test/javascripts/fixtures/product_review_ajax_submit.html.haml +4 -0
  167. data/test/javascripts/product_review_ajax_submit_spec.js +28 -0
  168. data/test/javascripts/spec_helper.js +23 -0
  169. data/test/models/workarea/insights/most_active_reviewers_test.rb +32 -0
  170. data/test/models/workarea/insights/most_reviewed_products_test.rb +32 -0
  171. data/test/models/workarea/insights/top_rated_products_test.rb +49 -0
  172. data/test/models/workarea/review/request_test.rb +18 -0
  173. data/test/models/workarea/review_test.rb +105 -0
  174. data/test/models/workarea/search/storefront/product_test.decorator +14 -0
  175. data/test/queries/workarea/reports/reviews_by_product_test.rb +104 -0
  176. data/test/queries/workarea/reports/reviews_by_user_test.rb +102 -0
  177. data/test/queries/workarea/review_request_params_test.rb +64 -0
  178. data/test/services/workarea/create_review_test.rb +131 -0
  179. data/test/system/workarea/admin/review_system_test.rb +96 -0
  180. data/test/system/workarea/admin/reviews_by_product_system_test.rb +60 -0
  181. data/test/system/workarea/storefront/review_request_system_test.rb +34 -0
  182. data/test/system/workarea/storefront/review_system_test.rb +113 -0
  183. data/test/teaspoon_env.rb +10 -0
  184. data/test/test_helper.rb +11 -0
  185. data/test/workers/workarea/create_review_requests_test.rb +38 -0
  186. data/test/workers/workarea/schedule_review_requests_test.rb +115 -0
  187. data/test/workers/workarea/send_review_requests_test.rb +30 -0
  188. data/workarea-reviews.gemspec +22 -0
  189. data/yarn.lock +3265 -0
  190. metadata +265 -0
@@ -0,0 +1,131 @@
1
+ require 'test_helper'
2
+
3
+ module Workarea
4
+ class CreateReviewTest < TestCase
5
+ setup :user, :product
6
+
7
+ def user
8
+ @user ||= create_user
9
+ end
10
+
11
+ def product
12
+ @product ||= create_product
13
+ end
14
+
15
+ def test_for
16
+ create = CreateReview.for(user: user, product: product)
17
+
18
+ assert_equal(user.id.to_s, create.review.user_id)
19
+ assert_equal(product.id.to_s, create.review.product_id)
20
+ assert(create.user.present?)
21
+ end
22
+
23
+ def test_save
24
+ create = CreateReview.for(user: user, product: product)
25
+ refute(create.save)
26
+ assert(create.errors[:body].present?)
27
+ assert(create.errors[:rating].present?)
28
+
29
+ create = CreateReview.for(
30
+ user: user,
31
+ product: product,
32
+ params: { body: 'foo bar', rating: 3 }
33
+ )
34
+ assert(create.save)
35
+
36
+ create = CreateReview.for(
37
+ product: product,
38
+ params: { body: 'foo bar', rating: 3 }
39
+ )
40
+ refute(create.save)
41
+ assert(create.errors[:first_name].present?)
42
+ assert(create.errors[:last_name].present?)
43
+
44
+ create = CreateReview.for(
45
+ product: product,
46
+ params: {
47
+ body: 'foo bar',
48
+ rating: 3,
49
+ first_name: 'Bob',
50
+ last_name: 'Clams'
51
+ }
52
+ )
53
+ assert(create.save)
54
+ end
55
+
56
+ def test_verified?
57
+ create_order(
58
+ user_id: user.id,
59
+ email: user.email,
60
+ placed_at: Time.now,
61
+ items: [{ product_id: product.id, sku: product.skus.first, quantity: 1 }]
62
+ )
63
+
64
+ create = CreateReview.for(
65
+ user: user,
66
+ product: product,
67
+ params: { body: 'foobar', rating: 4 }
68
+ )
69
+
70
+ assert(create.verified?)
71
+ assert(create.save)
72
+ assert(create.review.verified?)
73
+ end
74
+
75
+ def test_canceling_review_requests
76
+ order = create_order(
77
+ user_id: user.id,
78
+ email: user.email,
79
+ placed_at: Time.now,
80
+ items: [{ product_id: product.id, sku: product.skus.first, quantity: 1 }]
81
+ )
82
+
83
+ review_request = create_review_request(
84
+ user_id: user.id,
85
+ product_id: product.id,
86
+ order_id: order.id
87
+ )
88
+
89
+ CreateReview.for(user: user, product: product, params: {}).save
90
+ refute(review_request.reload.canceled?)
91
+
92
+ CreateReview.for(
93
+ user: user,
94
+ product: product,
95
+ params: { body: 'foobar', rating: 4 }
96
+ ).save
97
+
98
+ assert(review_request.reload.canceled?)
99
+ end
100
+
101
+ def test_title
102
+ create_with_title = CreateReview.for(
103
+ product: product,
104
+ params: {
105
+ title: 'Baz',
106
+ body: 'foo bar',
107
+ rating: 3,
108
+ first_name: 'Bob',
109
+ last_name: 'Clams'
110
+ }
111
+ )
112
+ create_without_title = CreateReview.for(
113
+ product: product,
114
+ params: {
115
+ body: 'foo bar',
116
+ rating: 3,
117
+ first_name: 'Bob',
118
+ last_name: 'Clams'
119
+ }
120
+ )
121
+
122
+ assert(create_with_title.save)
123
+ assert_equal('Baz', create_with_title.review.title)
124
+ assert_equal('foo bar', create_with_title.review.body)
125
+
126
+ assert(create_without_title.save)
127
+ assert_equal('foo bar', create_without_title.review.title)
128
+ assert_equal('foo bar', create_without_title.review.body)
129
+ end
130
+ end
131
+ end
@@ -0,0 +1,96 @@
1
+ require 'test_helper'
2
+
3
+ module Workarea
4
+ module Admin
5
+ class ReviewSystemTest < SystemTest
6
+ include Admin::IntegrationTest
7
+
8
+ setup :review
9
+
10
+ def review
11
+ @review ||= create_review(
12
+ product_id: product.id,
13
+ user_id: user.id,
14
+ rating: 3,
15
+ title: 'Integration Review',
16
+ approved: false
17
+ )
18
+ end
19
+
20
+ def user
21
+ @user ||= create_user
22
+ end
23
+
24
+ def product
25
+ @product ||= create_product
26
+ end
27
+
28
+ def test_managing_reviews
29
+ visit admin.reviews_path
30
+ click_link t('workarea.storefront.reviews.review_for', product: product.name)
31
+
32
+ click_button 'save_review'
33
+ assert(page.has_content?('Success'))
34
+
35
+ assert(page.has_current_path?(admin.reviews_path))
36
+
37
+ click_link t('workarea.storefront.reviews.review_for', product: product.name)
38
+ click_link t('workarea.admin.actions.delete')
39
+
40
+ assert(page.has_current_path?(admin.reviews_path))
41
+ refute(page.has_content?('Integration Review'))
42
+
43
+ visit admin.activity_path
44
+ assert(
45
+ page.has_content?(
46
+ t('workarea.admin.activities.review_destroy_html', name: 'Integration Review')
47
+ )
48
+ )
49
+ end
50
+
51
+ def test_sorting_by_rating
52
+ reviews = Array.new(3) do |i|
53
+ create_review(
54
+ rating: 5 - i,
55
+ product_id: create_product(name: "Test #{i}").id
56
+ )
57
+ end
58
+
59
+ visit admin.reviews_path
60
+ assert(page.has_ordered_text?('Test 2', 'Test 1', 'Test 0'))
61
+
62
+ select 'Highest Rating', from: :sort
63
+ assert(page.has_ordered_text?('Test 0', 'Test 1', 'Test 2'))
64
+
65
+ select 'Lowest Rating', from: :sort
66
+ assert(page.has_ordered_text?('Test 2', 'Test 1', 'Test 0'))
67
+ end
68
+
69
+ def test_importing_and_exporting
70
+ reviews = Array.new(2) { |i| create_review(product_id: create_product.id) }
71
+ file = create_tempfile(DataFile::Csv.new.serialize(reviews), extension: 'csv')
72
+
73
+ visit admin.reviews_path
74
+ click_link t('workarea.admin.shared.bulk_actions.import')
75
+ attach_file 'import[file]', file.path
76
+ click_button 'create_import'
77
+
78
+ assert_current_path(admin.reviews_path)
79
+ assert(page.has_content?('Success'))
80
+
81
+ click_button t('workarea.admin.shared.bulk_actions.export')
82
+
83
+ Workarea.config.data_file_formats[1..-1].each do |format|
84
+ click_link format.upcase
85
+ assert(page.has_content?(format.upcase))
86
+ end
87
+
88
+ fill_in 'export[emails_list]', with: 'bcrouse@weblinc.com'
89
+ click_button 'create_export'
90
+
91
+ assert_current_path(admin.reviews_path)
92
+ assert(page.has_content?('Success'))
93
+ end
94
+ end
95
+ end
96
+ end
@@ -0,0 +1,60 @@
1
+ require 'test_helper'
2
+
3
+ module Workarea
4
+ module Admin
5
+ class ReviewsByProductSystemTest < Workarea::SystemTest
6
+ include Admin::IntegrationTest
7
+
8
+ def test_report
9
+ create_product(id: 'foo', name: 'Foo')
10
+
11
+ create_review(product_id: 'foo', rating: 4, approved: false)
12
+ create_review(product_id: 'foo', rating: 3)
13
+ create_review(product_id: 'bar', rating: 1, approved: false)
14
+ create_review(product_id: 'bar', rating: 1, approved: false)
15
+ create_review(product_id: 'bar', rating: 2)
16
+ create_review(product_id: 'bar', rating: 2, approved: false)
17
+
18
+ visit admin.reviews_by_product_report_path
19
+ assert(page.has_content?('Foo'))
20
+ assert(page.has_content?('bar'))
21
+ assert(page.has_content?('2'))
22
+ assert(page.has_content?('3.5'))
23
+ assert(page.has_content?('3.08'))
24
+ assert(page.has_content?('4'))
25
+ assert(page.has_content?('1.5'))
26
+ assert(page.has_content?('2.5'))
27
+
28
+ click_link t('workarea.admin.fields.average_rating')
29
+ assert(page.has_content?("#{t('workarea.admin.fields.average_rating')} ↓"))
30
+ assert(page.has_ordered_text?('Foo', 'bar'))
31
+
32
+ click_link t('workarea.admin.fields.reviews')
33
+ assert(page.has_content?("#{t('workarea.admin.fields.reviews')} ↓"))
34
+ assert(page.has_ordered_text?('bar', 'Foo'))
35
+
36
+ click_link t('workarea.admin.fields.reviews')
37
+ assert(page.has_content?("#{t('workarea.admin.fields.reviews')} ↑"))
38
+ assert(page.has_ordered_text?('Foo', 'bar'))
39
+
40
+ select t('workarea.admin.reports.reviews_by_product.filters.unapproved'), from: :results_filter
41
+
42
+ assert(page.has_content?('Foo'))
43
+ assert(page.has_content?('1'))
44
+ assert(page.has_content?('4'))
45
+ assert(page.has_content?('bar'))
46
+ assert(page.has_content?('3'))
47
+ assert(page.has_content?('1.33'))
48
+
49
+ select t('workarea.admin.reports.reviews_by_product.filters.approved'), from: :results_filter
50
+
51
+ assert(page.has_content?('Foo'))
52
+ assert(page.has_content?('1'))
53
+ assert(page.has_content?('3'))
54
+ assert(page.has_content?('bar'))
55
+ assert(page.has_content?('1'))
56
+ assert(page.has_content?('2'))
57
+ end
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,34 @@
1
+ require 'test_helper'
2
+
3
+ module Workarea
4
+ module Storefront
5
+ class ReviewRequestSystemTest < Workarea::SystemTest
6
+ def test_completing_a_review_request
7
+ order = create_placed_order
8
+ product = create_product
9
+ user = create_user(first_name: 'Bob', last_name: 'Clams')
10
+
11
+ review_request = create_review_request(
12
+ product_id: product.id,
13
+ order_id: order.id,
14
+ email: order.email,
15
+ user_id: user.id
16
+ )
17
+
18
+ visit storefront.review_request_path(review_request.token)
19
+
20
+ assert(page.has_content?(product.name))
21
+
22
+ within '#review_request_form' do
23
+ execute_script("$('#review_rating_4').trigger('click')")
24
+ fill_in 'review[title]', with: 'Pretty decent product'
25
+ fill_in 'review[body]', with: 'It works well.'
26
+ click_button 'submit_review'
27
+ end
28
+
29
+ assert_current_path(storefront.product_path(product))
30
+ assert(page.has_content?('Success'))
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,113 @@
1
+ require 'test_helper'
2
+
3
+ module Workarea
4
+ module Storefront
5
+ class ReviewSystemTest < Workarea::SystemTest
6
+ def product
7
+ @product ||= create_product(name: 'Test')
8
+ end
9
+
10
+ def test_showing_reviews_on_browse_page
11
+ create_review(product_id: product.id, rating: 4)
12
+ category = create_category(product_ids: [product.id])
13
+
14
+ visit storefront.category_path(category)
15
+ assert_includes(page.html, '4.0 out of 5 stars')
16
+ end
17
+
18
+ def test_showing_reviews_on_search_results
19
+ create_product(name: 'Another Test')
20
+ create_review(product_id: product.id, rating: 4)
21
+
22
+ visit storefront.search_path(q: 'test')
23
+ assert_includes(page.html, '4.0 out of 5 stars')
24
+ end
25
+
26
+ def test_showing_reviews_on_a_product_detail_page
27
+ create_review(product_id: product.id, rating: 3)
28
+ create_review(
29
+ product_id: product.id,
30
+ rating: 3,
31
+ title: 'Integration Review First'
32
+ )
33
+ create_review(
34
+ product_id: product.id,
35
+ rating: 3,
36
+ title: 'Integration Review Second'
37
+ )
38
+
39
+ visit storefront.product_path(product)
40
+
41
+ assert_includes(page.html, '3.0')
42
+ assert(page.has_content?('(3)'))
43
+ assert(
44
+ page.has_ordered_text?(
45
+ 'Integration Review Second',
46
+ 'Integration Review First'
47
+ )
48
+ )
49
+ end
50
+
51
+ def test_showing_review_from_verified_purchaser
52
+ create_review(
53
+ product_id: product.id,
54
+ rating: 3,
55
+ title: 'Integration Review',
56
+ verified: true
57
+ )
58
+
59
+ visit storefront.product_path(product)
60
+ assert(page.has_content?('Integration Review'))
61
+ assert(page.has_content?(t('workarea.storefront.reviews.verified_purchaser')))
62
+ end
63
+
64
+ def test_writing_a_product_review
65
+ create_user(
66
+ email: 'test@workarea.com',
67
+ password: 'w3bl1nc',
68
+ name: 'Ben Crouse'
69
+ )
70
+
71
+ visit storefront.login_path
72
+
73
+ within '#login_form' do
74
+ fill_in 'email', with: 'test@workarea.com'
75
+ fill_in 'password', with: 'w3bl1nc'
76
+ click_button 'login'
77
+ end
78
+
79
+ visit storefront.product_path(product)
80
+ click_link 'Write a Review'
81
+
82
+ within '#review_form' do
83
+ # svg blocks input
84
+ execute_script("$('#review_rating_4').trigger('click')")
85
+ fill_in 'review[title]', with: 'Pretty decent product'
86
+ fill_in 'review[body]', with: 'It works well.'
87
+ click_button 'submit_review'
88
+ end
89
+
90
+ assert(page.has_content?('Success'))
91
+ assert_no_selector('#review_form')
92
+ end
93
+
94
+ def test_writing_a_product_review_as_a_guest
95
+ visit storefront.product_path(product)
96
+ click_link 'Write a Review'
97
+
98
+ within '#review_form' do
99
+ # svg blocks input
100
+ execute_script("$('#review_rating_4').trigger('click')")
101
+ fill_in 'review[title]', with: 'Pretty decent product'
102
+ fill_in 'review[body]', with: 'It works well.'
103
+ fill_in 'review[first_name]', with: 'Ben'
104
+ fill_in 'review[last_name]', with: 'Crouse'
105
+ click_button 'submit_review'
106
+ end
107
+
108
+ assert(page.has_content?('Success'))
109
+ assert_no_selector('#review_form')
110
+ end
111
+ end
112
+ end
113
+ end
@@ -0,0 +1,10 @@
1
+ require 'workarea/testing/teaspoon'
2
+
3
+ Teaspoon.configure do |config|
4
+ config.root = Workarea::Reviews::Engine.root
5
+ Workarea::Teaspoon.apply(config)
6
+
7
+ config.suite do |suite|
8
+ suite.stylesheets += ['workarea/storefront/application']
9
+ end
10
+ end