Skip to content

Commit

Permalink
wip: refine print template (publiclab#8337)
Browse files Browse the repository at this point in the history
* refine print template

* add tests
  • Loading branch information
Tlazypanda authored and wichanart committed Oct 26, 2021
1 parent 42f3e07 commit cecb4d5
Show file tree
Hide file tree
Showing 9 changed files with 83 additions and 13 deletions.
1 change: 1 addition & 0 deletions app/controllers/notes_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ def print

if @node
impressionist(@node, 'print', unique: [:ip_address])
render layout: false

else
page_not_found
Expand Down
1 change: 1 addition & 0 deletions app/controllers/wiki_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ def print

if @node
impressionist(@node, 'print', unique: [:ip_address])
render layout: false

else
page_not_found
Expand Down
10 changes: 8 additions & 2 deletions app/views/like/_like.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -177,11 +177,17 @@
var node_type = '<%= node.type %>';
if (node_type == 'page'){
<% if @revision %>
window.location.href = "/wikis/print/<%= @node.id %>";
window.open(
"/wikis/print/<%= @node.id %>",
'_blank' // <- This is what makes it open in a new window.
);
<% end %>
}
else if (node_type == 'note'){
window.location.href = "/notes/print/" + <%= node.id %>;
window.open(
"/notes/print/" + <%= node.id %>,
'_blank' // <- This is what makes it open in a new window.
);
}
}
// Event listner on CLICK on links
Expand Down
8 changes: 4 additions & 4 deletions app/views/notes/print.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -141,22 +141,22 @@ html, body{
}
h1 {
font-family: Arial;
font-family: 'Junction Light';
font-size: 180%;
}

h2 {
font-family: Arial;
font-family: 'Junction Light';
font-size: 160%;
}

h3 {
font-family: Arial;
font-family: 'Junction Light';
font-size: 140%;
}

h4 {
font-family: Arial;
font-family: 'Junction Light';
font-size: 120%;
}

Expand Down
8 changes: 4 additions & 4 deletions app/views/wiki/print.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -163,22 +163,22 @@ html, body{
}
h1 {
font-family: Arial;
font-family: 'Junction Light';
font-size: 180%;
}

h2 {
font-family: Arial;
font-family: 'Junction Light';
font-size: 160%;
}

h3 {
font-family: Arial;
font-family: 'Junction Light';
font-size: 140%;
}

h4 {
font-family: Arial;
font-family: 'Junction Light';
font-size: 120%;
}

Expand Down
16 changes: 15 additions & 1 deletion test/fixtures/revisions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,21 @@ sunny_day_note:
nid: 34
uid: 2
title: "Note tagged with sunny-day"
body: "This is the body"
body: |
This is the body. Testing out print using
| | col0 | col1 | col2 | col3 |
| |------|------|------|------|
| | cell | cell | cell | cell |
| | cell | cell | cell | cell |
| | cell | cell | cell | cell |
| | cell | cell | cell | cell |
```
code goes here
```
> But my knees were far too weak To stand in your arms Without falling to your feet
<iframe width='560' height='315' src='https://www.youtube.com/embed/pt-9qPCBbQE' frameborder='0' allow='accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture' allowfullscreen\=''></iframe>
timestamp: <%= DateTime.new(2020,2,12).to_i %>
status: 1

Expand Down
9 changes: 9 additions & 0 deletions test/functional/notes_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,15 @@ def teardown
}

assert_template 'print'
assert_select '#header', false
assert_select 'footer', false
assert_select '#content', false
selector = css_select '#note-title'
assert_equal note.title, selector.text.strip
selector = css_select '#content-window'
assert_equal note.body, selector.text.strip
selector = css_select '.info-date a'
assert_equal note.latest.author.name, selector.text
assert_response :success
end

Expand Down
15 changes: 13 additions & 2 deletions test/functional/wiki_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ def teardown
assert_equal flash[:notice], "Please post a question or other content before editing the wiki. Click <a href='https://publiclab.org/notes/tester/04-23-2016/new-moderation-system-for-first-time-posters'>here</a> to learn why."
assert_redirected_to nodes(:place).path
end

test 'updating wiki' do
wiki = nodes(:organizers)
newtitle = 'New Title'
Expand Down Expand Up @@ -678,12 +678,23 @@ def teardown
end

test "print wiki template" do
node = nodes(:about)
node = nodes(:wiki_page)

get :print, params: { id: node.nid }

assert_template 'print'
assert_response :success
assert_select '#header', false
assert_select 'footer', false
assert_select '#content', false
selector = css_select '.title'
assert_equal node.latest.title, selector.text
selector = css_select '.info-revision'
assert_equal node.revisions.length.to_s + " revisions ", selector.text
selector = css_select '.wi-author'
assert_equal node.author.username, selector.text.strip
selector = css_select '.info-date a'
assert_equal node.latest.author.name, selector.text
assert_select 'div#content-window', auto_link(insert_extras(node.latest.render_body), sanitize: false)[3..-6]
end
end
28 changes: 28 additions & 0 deletions test/system/print_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
require "application_system_test_case"

class PrintTest < ApplicationSystemTestCase

test "open print in new tab for note" do
visit nodes(:one).path
find('#menu-btn').click()
find("#print-new").click()
assert page.driver.browser.window_handles.size == 2
end

test "open print in new tab for wiki" do
visit nodes(:wiki_page).path
find('#menu-btn').click()
find("#print-new").click()
assert page.driver.browser.window_handles.size == 2
end

test "check different elements in print for note" do
visit "/notes/print/#{nodes(:sunny_day_note).nid}"
take_screenshot
assert_selector('#content-window blockquote p', text: "But my knees were far too weak To stand in your arms Without falling to your feet")
assert_selector('#content-window table', text: "col0 col1 col2 col3\ncell cell cell cell\ncell cell cell cell\ncell cell cell cell\ncell cell cell cell")
assert_selector('#content-window code', text: "code goes here")
assert_selector('#content-window iframe', visible: true)
end

end

0 comments on commit cecb4d5

Please sign in to comment.