Skip to content

Commit

Permalink
WIP: Checkboxes publiclab#2452 (publiclab#2800)
Browse files Browse the repository at this point in the history
* initial setup commit

* working on 2452 github-style checkboxes to nodes

* removed quotes from regex for CHECKBOX, added tests for checkbox regex

* WIP: still have questions regarding implementation and testing for markdown styles checkboxes

* [WIP] updated checkbox code, revised tests

* updated from fontawesome to traditional checkboxes in model and tests, adjusted number of test posts to reflect new checkboxes
  • Loading branch information
cheneyshreve01 authored and jywarren committed Jun 21, 2018
1 parent b9b410d commit 8dca2fe
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 6 deletions.
2 changes: 2 additions & 0 deletions app/models/revision.rb
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ def render_body
body = body.gsub(Callouts.const_get(:FINDER), Callouts.const_get(:PRETTYLINKHTML))
body = body.gsub(Callouts.const_get(:HASHTAGNUMBER), Callouts.const_get(:NODELINKHTML))
body = body.gsub(Callouts.const_get(:HASHTAG), Callouts.const_get(:HASHLINKHTML))
body = body.gsub(/(\d+\. |\* )\K\[(x|X)\]/, %(<input type="checkbox" editable="false" checked="checked" />)).gsub(/(\d+\. |\* )\K\[ \]/, %(<input type="checkbox" editable="false" />))
ApplicationController.helpers.emojify(body_extras(body)).to_s
end

Expand All @@ -107,6 +108,7 @@ def render_body_raw
body = body.gsub(Callouts.const_get(:FINDER), Callouts.const_get(:PRETTYLINKHTML))
body = body.gsub(Callouts.const_get(:HASHTAGNUMBER), Callouts.const_get(:NODELINKHTML))
body = body.gsub(Callouts.const_get(:HASHTAG), Callouts.const_get(:HASHLINKHTML))
body = body.gsub(/(\d+\. |\* )\K\[(x|X)\]/, %(<input type="checkbox" editable="false" checked="checked" />)).gsub(/(\d+\. |\* )\K\[ \]/, %(<input type="checkbox" editable="false" />))
insert_extras(body_extras(body))
end

Expand Down
22 changes: 20 additions & 2 deletions test/fixtures/revisions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ hashtag_in_header:
uid: 1
title: grabs hashtags in headers
body: |+
# Heading 1 is about #hashtags
# Heading 1 is about #hashtags
Here is the message
subheader:
Expand Down Expand Up @@ -251,4 +251,22 @@ draft:
nid: 21
uid: 2
title: "Draft note"
body: This is draft note.
body: This is draft note.

checkbox_one:
nid: 1
uid: 1
title: Should render an unchecked checkbox
body: |+
# Heading 1
List of things
* [ ]
checkbox_two:
nid: 1
uid: 1
title: Should render a checked checkbox
body: |+
# Heading 1
List of things
* [x]
6 changes: 3 additions & 3 deletions test/functional/notes_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ def teardown

assert_response :success
selector = css_select 'div.note'
assert_equal selector.size, 15
assert_equal selector.size, 17
assert_select "div p", 'Pending approval by community moderators. Please be patient!'
end

Expand Down Expand Up @@ -342,7 +342,7 @@ def teardown

assert_response :success
selector = css_select 'div.note'
assert_equal selector.size, 15
assert_equal selector.size, 17
assert_select "p", "Moderate first-time post: \n Approve\n Spam"
end

Expand Down Expand Up @@ -450,7 +450,7 @@ def teardown
test 'should display an icon for users with streak longer than 7 days' do
node = nodes(:one)
User.any_instance.stubs(:note_streak).returns([8, 10])
User.any_instance.stubs(:wiki_edit_streak).returns([9, 15])
User.any_instance.stubs(:wiki_edit_streak).returns([9, 17])
User.any_instance.stubs(:comment_streak).returns([10, 30])
get :show,
params: {
Expand Down
3 changes: 2 additions & 1 deletion test/unit/constants_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,11 @@ class ConstantsTest < ActiveSupport::TestCase
assert string.scan(Callouts.const_get(:HASHTAG)).length == 3
end

test 'hashtagnumber regex should match non-initial hash' do
test 'hashtagnumber regex should match non-initial hash' do
string = "hello #123 #hello " ;
assert string.scan(Callouts.const_get(:HASHTAGNUMBER)).length == 1
expect = "hello REPLACE #hello " ;
assert_equal expect, string.gsub(Callouts.const_get(:HASHTAGNUMBER), ' REPLACE') ;
end

end
12 changes: 12 additions & 0 deletions test/unit/revision_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -202,4 +202,16 @@ class RevisionsTest < ActiveSupport::TestCase
tag_names = associated_tags.map(&:name)
assert_not tag_names.include?('1234')
end

test 'should recognize unmarked markdown style checkboxes and convert them into unchecked checkbox' do
revision = revisions(:checkbox_one)
assert_includes revision.render_body, %(* <input type="checkbox" editable="false" />)
end

test 'should recognize marked markdown style checkboxes and convert them into checked checkbox' do
revision = revisions(:checkbox_two)
assert_includes revision.render_body, %(* <input type="checkbox" editable="false" checked="checked" />)
end


end

0 comments on commit 8dca2fe

Please sign in to comment.