Sha256: fcfc309a021f74594d7f48c1c677af6bd252a2e6e55043dbce7709c674559021

Contents?: true

Size: 1.49 KB

Versions: 6

Compression:

Stored size: 1.49 KB

Contents

require 'test_helper'

class ViewerTest < ActionDispatch::IntegrationTest
  setup do
    @time_to_render = 2
  end

  test "Full viewer" do
    visit "/"
    output = capture(:stdout) do
      click_on "full viewer"
      assert_equal 1, all("#pdfjs_viewer-full").size
      sleep @time_to_render
    end

    assert_rendered_pdf output, screenshot: SANDBOX_PATH + "full_viewer.png"
  end

  test "Minimal viewer" do
    visit "/"
    output = capture(:stdout) do
      click_on "minimal viewer"
      assert_equal 1, all("#pdfjs_viewer-minimal").size
      sleep @time_to_render
    end

    assert_rendered_pdf output, screenshot: SANDBOX_PATH + "minimal_viewer.png"
  end

  test "Using the helper" do
    visit "/"
    output = capture(:stdout) do
      click_on "helper"
      assert_equal 1, all("#pdfjs_viewer-minimal").size
      sleep @time_to_render
    end

    assert_rendered_pdf output, screenshot: SANDBOX_PATH + "helper.png"
  end

  private
  def assert_rendered_pdf(output, screenshot:)
    puts output.scan(/Warning:.+$/)
    assert_match /PDF 48164f9cb09af89995618717f0aafc/, output
    page.save_screenshot screenshot, full: true
  end

  def capture(stream)
    stream = stream.to_s
    captured_stream = Tempfile.new(stream)
    stream_io = eval("$#{stream}")
    origin_stream = stream_io.dup
    stream_io.reopen(captured_stream)

    yield

    stream_io.rewind
    return captured_stream.read
  ensure
    captured_stream.close
    captured_stream.unlink
    stream_io.reopen(origin_stream)
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
pdfjs_viewer-rails-0.0.6 test/integration/viewer_test.rb
pdfjs_viewer-rails-0.0.5 test/integration/viewer_test.rb
pdfjs_viewer-rails-0.0.4 test/integration/viewer_test.rb
pdfjs_viewer-rails-0.0.3 test/integration/viewer_test.rb
pdfjs_viewer-rails-0.0.2 test/integration/viewer_test.rb
pdfjs_viewer-rails-0.0.1 test/integration/viewer_test.rb