From cecb4d5e5b98aebb10920a8d0e2703c466afdc83 Mon Sep 17 00:00:00 2001
From: Sneha Mishra <33183263+Tlazypanda@users.noreply.github.com>
Date: Tue, 8 Sep 2020 07:57:56 -0700
Subject: [PATCH] wip: refine print template (#8337)
* refine print template
* add tests
---
app/controllers/notes_controller.rb | 1 +
app/controllers/wiki_controller.rb | 1 +
app/views/like/_like.html.erb | 10 +++++++--
app/views/notes/print.html.erb | 8 +++----
app/views/wiki/print.html.erb | 8 +++----
test/fixtures/revisions.yml | 16 +++++++++++++-
test/functional/notes_controller_test.rb | 9 ++++++++
test/functional/wiki_controller_test.rb | 15 +++++++++++--
test/system/print_test.rb | 28 ++++++++++++++++++++++++
9 files changed, 83 insertions(+), 13 deletions(-)
create mode 100644 test/system/print_test.rb
diff --git a/app/controllers/notes_controller.rb b/app/controllers/notes_controller.rb
index 178e4a4811..47134833a2 100644
--- a/app/controllers/notes_controller.rb
+++ b/app/controllers/notes_controller.rb
@@ -75,6 +75,7 @@ def print
if @node
impressionist(@node, 'print', unique: [:ip_address])
+ render layout: false
else
page_not_found
diff --git a/app/controllers/wiki_controller.rb b/app/controllers/wiki_controller.rb
index 22b00a09b9..916e19e1e4 100644
--- a/app/controllers/wiki_controller.rb
+++ b/app/controllers/wiki_controller.rb
@@ -99,6 +99,7 @@ def print
if @node
impressionist(@node, 'print', unique: [:ip_address])
+ render layout: false
else
page_not_found
diff --git a/app/views/like/_like.html.erb b/app/views/like/_like.html.erb
index b0293fcd27..05075b18f8 100644
--- a/app/views/like/_like.html.erb
+++ b/app/views/like/_like.html.erb
@@ -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
diff --git a/app/views/notes/print.html.erb b/app/views/notes/print.html.erb
index 35b4c115ab..465db0a571 100644
--- a/app/views/notes/print.html.erb
+++ b/app/views/notes/print.html.erb
@@ -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%;
}
diff --git a/app/views/wiki/print.html.erb b/app/views/wiki/print.html.erb
index 241f99332c..7fe1e5c440 100644
--- a/app/views/wiki/print.html.erb
+++ b/app/views/wiki/print.html.erb
@@ -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%;
}
diff --git a/test/fixtures/revisions.yml b/test/fixtures/revisions.yml
index 3132efcb8d..2ce8d95f45 100644
--- a/test/fixtures/revisions.yml
+++ b/test/fixtures/revisions.yml
@@ -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
+
timestamp: <%= DateTime.new(2020,2,12).to_i %>
status: 1
diff --git a/test/functional/notes_controller_test.rb b/test/functional/notes_controller_test.rb
index 42dd0ebed3..f99fd43426 100644
--- a/test/functional/notes_controller_test.rb
+++ b/test/functional/notes_controller_test.rb
@@ -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
diff --git a/test/functional/wiki_controller_test.rb b/test/functional/wiki_controller_test.rb
index 0cf8f8292c..79e3d1298e 100644
--- a/test/functional/wiki_controller_test.rb
+++ b/test/functional/wiki_controller_test.rb
@@ -167,7 +167,7 @@ def teardown
assert_equal flash[:notice], "Please post a question or other content before editing the wiki. Click here to learn why."
assert_redirected_to nodes(:place).path
end
-
+
test 'updating wiki' do
wiki = nodes(:organizers)
newtitle = 'New Title'
@@ -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
diff --git a/test/system/print_test.rb b/test/system/print_test.rb
new file mode 100644
index 0000000000..5367fc36c4
--- /dev/null
+++ b/test/system/print_test.rb
@@ -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