Skip to content

Commit

Permalink
test parameter validation
Browse files Browse the repository at this point in the history
  • Loading branch information
lfoppiano committed May 12, 2024
1 parent 364cb94 commit 8d01a0e
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 0 deletions.
12 changes: 12 additions & 0 deletions tests/streamlit_apps/example_invalid_params.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import os

import streamlit as st

from streamlit_pdf_viewer import pdf_viewer
from tests import ROOT_DIRECTORY

st.subheader("Test PDF Viewer using legacy embed with specified height")

pdf_viewer(os.path.join(ROOT_DIRECTORY, "resources/test.pdf"), rendering='unwrap', height='500')
pdf_viewer(os.path.join(ROOT_DIRECTORY, "resources/test.pdf"), rendering='unwrap', width='500')
pdf_viewer(os.path.join(ROOT_DIRECTORY, "resources/test.pdf"), rendering='unwrap', width='500', height='500')
47 changes: 47 additions & 0 deletions tests/test_invalid_params.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import os
from pathlib import Path

import pytest
from playwright.sync_api import Page, expect

from tests import ROOT_DIRECTORY
from tests.e2e_utils import StreamlitRunner

BASIC_EXAMPLE_FILE = os.path.join(ROOT_DIRECTORY, "tests", "streamlit_apps", "example_invalid_params.py")


@pytest.fixture(scope="session")
def browser_type_launch_args(browser_type_launch_args):
return {
**browser_type_launch_args,
"firefox_user_prefs": {
"pdfjs.disabled": False,
}
}


@pytest.fixture(autouse=True, scope="module")
def streamlit_app():
with StreamlitRunner(Path(BASIC_EXAMPLE_FILE)) as runner:
yield runner


@pytest.fixture(autouse=True, scope="function")
def go_to_app(page: Page, streamlit_app: StreamlitRunner):
page.goto(streamlit_app.server_url)
# Wait for app to load
page.get_by_role("img", name="Running...").is_hidden()


def test_should_fail_rendering(page: Page):
expect(page.get_by_text("Test PDF Viewer using legacy embed with specified height")).to_be_visible()

iframe_component = page.locator('iframe[title="streamlit_pdf_viewer.streamlit_pdf_viewer"]').nth(0)
expect(iframe_component).not_to_be_visible()

iframe_frame = page.frame_locator('iframe[title="streamlit_pdf_viewer.streamlit_pdf_viewer"]')
pdf_container = iframe_frame.locator('div[id="pdfContainer"]')
expect(pdf_container).not_to_be_visible()

pdf_viewer = iframe_frame.locator('div[id="pdfViewer"]')
expect(pdf_viewer).not_to_be_visible()

0 comments on commit 8d01a0e

Please sign in to comment.