require "test_helper" # PDFs in the document viewer: drawn with PDF.js on phones (Android shows # nothing in a frame), the browser's own viewer in a frame elsewhere. class PdfViewerTest < ActionDispatch::IntegrationTest setup do @owner = create_user("owner@example.com") @a = create_aircraft(owner: @owner) @doc = @a.documents.create!(name: "POH", doc_type: "OTHER") @doc.pages.attach(io: StringIO.new("%PDF-1.4 fake"), filename: "poh.pdf", content_type: "application/pdf") end test "a PDF page hands the viewer its file, the PDF.js folder and the frame" do sign_in @owner get aircraft_document_path(@a, @doc) assert_response :success assert_select "[data-controller=pdf-viewer][data-pdf-viewer-pdfjs-value=?]", Rails.application.config.x.pdfjs_path do assert_select "[data-pdf-viewer-url-value*='/rails/active_storage/blobs/']" assert_select "template[data-pdf-viewer-target=frame]" assert_select "[data-pdf-viewer-target=status]", text: "Loading the PDF…" assert_select "noscript" end assert_includes response.body, "