Skip to content

Commit

Permalink
basic ui tests for layout
Browse files Browse the repository at this point in the history
  • Loading branch information
thuydotm committed Jan 15, 2025
1 parent 86c5d3b commit ae23de4
Showing 1 changed file with 70 additions and 0 deletions.
70 changes: 70 additions & 0 deletions tests/ui/layout/test_layout.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import pytest

pytest.importorskip('playwright')

from panel_material_ui.layout import Card, Accordion, Tabs, Paper

from playwright.sync_api import expect
from tests.util import serve_component

pytestmark = pytest.mark.ui


def test_card_default(page):
layout = Card(1, 2, 3, title="Card 1")
serve_component(page, layout)

expect(page.locator('.card')).to_have_count(1)

action = page.locator('.MuiCardHeader-action')
content = page.locator('.MuiCardContent-root')
expect(action).to_have_count(1)
expect(content).to_have_count(1)

# collapse the card
action.click()
expect(content).to_have_count(0)


def test_card_collapsible(page):
layout = Card(1, 2, 3, title="Card 1", collapsible=False)
serve_component(page, layout)
# card not collapsible, there's no arrow icon for collapse/expand
expect(page.locator('.MuiCardHeader-action')).to_have_count(0)


def test_accordion_active(page):
layout = Accordion(("Card 1", "Card 1 objects"), ("Card 2", "Card 2 objects"))
serve_component(page, layout)

expect(page.locator('.accordion')).to_have_count(1)
# 2 collapsed cards
cards = page.locator('.MuiAccordion-gutters')
expect(cards).to_have_count(2)
expanded_cards = page.locator('.MuiCollapse-entered')
expect(expanded_cards).to_have_count(0)

# expand the card, `active` is set properly
card0 = cards.nth(0)
card0.click()
expect(expanded_cards).to_have_count(1)
expanded_cards.wait_for(timeout=5000)
assert layout.active == [0]

# set `active`, the cards expanded accordingly
layout.active = [0, 1]
expect(page.locator('.Mui-expanded')).to_have_count(2)


def test_tabs(page):
layout = Tabs(("Tab 1", "Tab 1 objects"), ("Tab 2", "Card 2 objects"))
serve_component(page, layout)

expect(page.locator('.tabs')).to_have_count(1)
expect(page.locator('.MuiTab-root')).to_have_count(2)


def test_paper(page):
layout = Paper(name="Paper", objects=[1, 2, 3])
serve_component(page, layout)
expect(page.locator('.paper')).to_have_count(1)

0 comments on commit ae23de4

Please sign in to comment.