-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
…endering)
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from pathlib import Path | ||
|
||
ROOT_DIRECTORY = Path(__file__).parent.parent.absolute() |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
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 no args") | ||
|
||
pdf_viewer(os.path.join(ROOT_DIRECTORY, "resources/test.pdf"), rendering='legacy_embed') |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
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 width") | ||
|
||
pdf_viewer(os.path.join(ROOT_DIRECTORY, "resources/test.pdf"), rendering='legacy_embed', width=500) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
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 width and height") | ||
|
||
pdf_viewer(os.path.join(ROOT_DIRECTORY, "resources/test.pdf"), rendering='legacy_embed', width=600, height=500) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
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 iframe with no args") | ||
|
||
pdf_viewer(os.path.join(ROOT_DIRECTORY, "resources/test.pdf"), rendering='legacy_iframe') |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
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 iframe with specified width") | ||
|
||
pdf_viewer(os.path.join(ROOT_DIRECTORY, "resources/test.pdf"), rendering='legacy_iframe', width=500) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
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 iframe with specified width and height") | ||
|
||
pdf_viewer(os.path.join(ROOT_DIRECTORY, "resources/test.pdf"), rendering='legacy_iframe', width=700, height=500) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import os | ||
|
||
import streamlit as st | ||
|
||
from streamlit_pdf_viewer import pdf_viewer | ||
from tests import ROOT_DIRECTORY | ||
|
||
st.subheader("Test PDF Viewer with specified height") | ||
|
||
pdf_viewer(os.path.join(ROOT_DIRECTORY, "resources/test.pdf"), height=300) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import os | ||
|
||
import streamlit as st | ||
from tests import ROOT_DIRECTORY | ||
|
||
from streamlit_pdf_viewer import pdf_viewer | ||
|
||
st.subheader("Test PDF Viewer with arguments with specified width") | ||
|
||
pdf_viewer(os.path.join(ROOT_DIRECTORY, "resources/test.pdf"), width=400) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
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_embed_no_args.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_render_template_check_container_size(page: Page): | ||
expect(page.get_by_text("Test PDF Viewer using legacy embed with no args")).to_be_visible() | ||
|
||
iframe_component = page.locator('iframe[title="streamlit_pdf_viewer.streamlit_pdf_viewer"]').nth(0) | ||
expect(iframe_component).to_be_visible() | ||
Check failure on line 40 in tests/test_embed_no_args.py GitHub Actions / build (3.10, 18)
Check failure on line 40 in tests/test_embed_no_args.py GitHub Actions / build (3.10, 18)
Check failure on line 40 in tests/test_embed_no_args.py GitHub Actions / build (3.9, 18)
Check failure on line 40 in tests/test_embed_no_args.py GitHub Actions / build (3.9, 18)
Check failure on line 40 in tests/test_embed_no_args.py GitHub Actions / build (3.11, 18)
Check failure on line 40 in tests/test_embed_no_args.py GitHub Actions / build (3.11, 18)
Check failure on line 40 in tests/test_embed_no_args.py GitHub Actions / build (3.8, 20)
Check failure on line 40 in tests/test_embed_no_args.py GitHub Actions / build (3.8, 20)
Check failure on line 40 in tests/test_embed_no_args.py GitHub Actions / build (3.11, 20)
Check failure on line 40 in tests/test_embed_no_args.py GitHub Actions / build (3.12, 18)
Check failure on line 40 in tests/test_embed_no_args.py GitHub Actions / build (3.7, 18)
Check failure on line 40 in tests/test_embed_no_args.py GitHub Actions / build (3.7, 18)
Check failure on line 40 in tests/test_embed_no_args.py GitHub Actions / build (3.10, 20)
Check failure on line 40 in tests/test_embed_no_args.py GitHub Actions / build (3.12, 20)
Check failure on line 40 in tests/test_embed_no_args.py GitHub Actions / build (3.12, 20)
Check failure on line 40 in tests/test_embed_no_args.py GitHub Actions / build (3.9, 20)
Check failure on line 40 in tests/test_embed_no_args.py GitHub Actions / build (3.9, 20)
Check failure on line 40 in tests/test_embed_no_args.py GitHub Actions / build (3.7, 20)
Check failure on line 40 in tests/test_embed_no_args.py GitHub Actions / build (3.8, 18)
Check failure on line 40 in tests/test_embed_no_args.py GitHub Actions / build (3.8, 18)
|
||
|
||
iframe_box = iframe_component.bounding_box() | ||
assert iframe_box['width'] > 0 | ||
assert iframe_box['height'] > 0 | ||
|
||
iframe_frame = page.frame_locator('iframe[title="streamlit_pdf_viewer.streamlit_pdf_viewer"]') | ||
pdf_container = iframe_frame.locator('div[id="pdfContainer"]') | ||
expect(pdf_container).to_be_visible() | ||
|
||
b_box = pdf_container.bounding_box() | ||
assert b_box['width'] == 400 | ||
assert b_box['height'] > 0 | ||
|
||
pdf_viewer = iframe_frame.locator('div[id="pdfViewer"]') | ||
expect(pdf_viewer).not_to_be_visible() | ||
|
||
annotations_locator = page.locator('div[id="pdfAnnotations"]').nth(0) | ||
expect(annotations_locator).to_be_hidden() |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
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_embed_width.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_render_template_check_container_size(page: Page): | ||
expect(page.get_by_text("Test PDF Viewer using legacy embed with specified width")).to_be_visible() | ||
|
||
iframe_component = page.locator('iframe[title="streamlit_pdf_viewer.streamlit_pdf_viewer"]').nth(0) | ||
expect(iframe_component).to_be_visible() | ||
Check failure on line 40 in tests/test_embed_width.py GitHub Actions / build (3.10, 18)
Check failure on line 40 in tests/test_embed_width.py GitHub Actions / build (3.10, 18)
Check failure on line 40 in tests/test_embed_width.py GitHub Actions / build (3.9, 18)
Check failure on line 40 in tests/test_embed_width.py GitHub Actions / build (3.9, 18)
Check failure on line 40 in tests/test_embed_width.py GitHub Actions / build (3.11, 18)
Check failure on line 40 in tests/test_embed_width.py GitHub Actions / build (3.11, 18)
Check failure on line 40 in tests/test_embed_width.py GitHub Actions / build (3.8, 20)
Check failure on line 40 in tests/test_embed_width.py GitHub Actions / build (3.8, 20)
Check failure on line 40 in tests/test_embed_width.py GitHub Actions / build (3.11, 20)
Check failure on line 40 in tests/test_embed_width.py GitHub Actions / build (3.12, 18)
Check failure on line 40 in tests/test_embed_width.py GitHub Actions / build (3.7, 18)
Check failure on line 40 in tests/test_embed_width.py GitHub Actions / build (3.7, 18)
Check failure on line 40 in tests/test_embed_width.py GitHub Actions / build (3.10, 20)
Check failure on line 40 in tests/test_embed_width.py GitHub Actions / build (3.12, 20)
Check failure on line 40 in tests/test_embed_width.py GitHub Actions / build (3.12, 20)
Check failure on line 40 in tests/test_embed_width.py GitHub Actions / build (3.9, 20)
Check failure on line 40 in tests/test_embed_width.py GitHub Actions / build (3.9, 20)
Check failure on line 40 in tests/test_embed_width.py GitHub Actions / build (3.7, 20)
Check failure on line 40 in tests/test_embed_width.py GitHub Actions / build (3.8, 18)
Check failure on line 40 in tests/test_embed_width.py GitHub Actions / build (3.8, 18)
|
||
|
||
iframe_box = iframe_component.bounding_box() | ||
assert iframe_box['width'] > 0 | ||
assert iframe_box['height'] > 0 | ||
|
||
iframe_frame = page.frame_locator('iframe[title="streamlit_pdf_viewer.streamlit_pdf_viewer"]') | ||
pdf_container = iframe_frame.locator('div[id="pdfContainer"]') | ||
expect(pdf_container).to_be_visible() | ||
|
||
b_box = pdf_container.bounding_box() | ||
assert b_box['width'] == 400 | ||
assert b_box['height'] > 0 | ||
|
||
pdf_viewer = iframe_frame.locator('div[id="pdfViewer"]') | ||
expect(pdf_viewer).not_to_be_visible() | ||
|
||
annotations_locator = page.locator('div[id="pdfAnnotations"]').nth(0) | ||
expect(annotations_locator).to_be_hidden() |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import math | ||
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_embed_width_height.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_render_template_check_container_size(page: Page): | ||
expect(page.get_by_text("Test PDF Viewer using legacy embed with specified width and height")).to_be_visible() | ||
|
||
iframe_component = page.locator('iframe[title="streamlit_pdf_viewer.streamlit_pdf_viewer"]').nth(0) | ||
expect(iframe_component).to_be_visible() | ||
|
||
iframe_box = iframe_component.bounding_box() | ||
assert iframe_box['width'] > 0 | ||
assert iframe_box['height'] > 0 | ||
|
||
iframe_frame = page.frame_locator('iframe[title="streamlit_pdf_viewer.streamlit_pdf_viewer"]') | ||
pdf_container = iframe_frame.locator('div[id="pdfContainer"]') | ||
expect(pdf_container).to_be_visible() | ||
|
||
b_box = pdf_container.bounding_box() | ||
assert b_box['width'] == 600 | ||
assert math.floor(b_box['height']) == 500 | ||
|
||
pdf_viewer = iframe_frame.locator('div[id="pdfViewer"]') | ||
expect(pdf_viewer).not_to_be_visible() | ||
|
||
annotations_locator = page.locator('div[id="pdfAnnotations"]').nth(0) | ||
expect(annotations_locator).to_be_hidden() |