@@ -2371,3 +2371,197 @@ def expect_open(self, open: bool, *, timeout: Timeout = None) -> None:
23712371 playwright_expect (self .loc_handle ).to_have_attribute (
23722372 "aria-expanded" , str (open ).lower (), timeout = timeout
23732373 )
2374+
2375+
2376+ class _CardBodyP (_InputBaseP , Protocol ):
2377+ loc_body : Locator
2378+
2379+
2380+ class _CardBodyM :
2381+ def expect_body (
2382+ self : _CardBodyP ,
2383+ text : PatternOrStr | list [PatternOrStr ],
2384+ * ,
2385+ timeout : Timeout = None ,
2386+ ) -> None :
2387+ """Note: If testing against multiple elements, text should be an array"""
2388+ playwright_expect (self .loc ).to_have_text (
2389+ text ,
2390+ timeout = timeout ,
2391+ )
2392+
2393+
2394+ class _CardFooterLayoutP (_InputBaseP , Protocol ):
2395+ loc_footer : Locator
2396+
2397+
2398+ class _CardFooterM :
2399+ def expect_footer (
2400+ self : _CardFooterLayoutP ,
2401+ text : PatternOrStr ,
2402+ * ,
2403+ timeout : Timeout = None ,
2404+ ) -> None :
2405+ playwright_expect (self .loc_footer ).to_have_text (
2406+ text ,
2407+ timeout = timeout ,
2408+ )
2409+
2410+
2411+ class _CardFullScreenLayoutP (_OutputBaseP , Protocol ):
2412+ loc_title : Locator
2413+ _loc_fullscreen : Locator
2414+ _loc_close_button : Locator
2415+
2416+
2417+ class _CardFullScreenM :
2418+ def open_full_screen (
2419+ self : _CardFullScreenLayoutP , * , timeout : Timeout = None
2420+ ) -> None :
2421+ self .loc_title .hover (timeout = timeout )
2422+ self ._loc_fullscreen .wait_for (state = "visible" , timeout = timeout )
2423+ self ._loc_fullscreen .click (timeout = timeout )
2424+
2425+ def close_full_screen (
2426+ self : _CardFullScreenLayoutP , * , timeout : Timeout = None
2427+ ) -> None :
2428+ self ._loc_close_button .click (timeout = timeout )
2429+
2430+ def expect_full_screen (
2431+ self : _CardFullScreenLayoutP , open : bool , * , timeout : Timeout = None
2432+ ) -> None :
2433+ playwright_expect (self ._loc_close_button ).to_have_count (
2434+ int (open ), timeout = timeout
2435+ )
2436+
2437+
2438+ class ValueBox (
2439+ _WidthLocM ,
2440+ _CardBodyM ,
2441+ _CardFullScreenM ,
2442+ _InputWithContainer ,
2443+ ):
2444+ # title: TagChild,
2445+ # value: TagChild,
2446+ # *args: TagChild | TagAttrs,
2447+ # showcase: TagChild = None,
2448+ # showcase_layout: ((TagChild, Tag) -> CardItem) | None = None,
2449+ # full_screen: bool = False,
2450+ # theme_color: str | None = "primary",
2451+ # height: CssUnit | None = None,
2452+ # max_height: CssUnit | None = None,
2453+ # fill: bool = True,
2454+ # class_: str | None = None,
2455+ # **kwargs: TagAttrValue
2456+ def __init__ (self , page : Page , id : str ) -> None :
2457+ super ().__init__ (
2458+ page ,
2459+ id = id ,
2460+ loc_container = f"div#{ id } .bslib-value-box" ,
2461+ loc = "> div > .value-box-grid" ,
2462+ )
2463+ value_box_grid = self .loc
2464+ self .loc = value_box_grid .locator (
2465+ "> div > .value-box-area > :not(:first-child)"
2466+ )
2467+ self .loc_showcase = value_box_grid .locator ("> div > .value-box-showcase" )
2468+ self .loc_title = value_box_grid .locator (
2469+ "> div > .value-box-area > :first-child"
2470+ )
2471+ self .loc_body = self .loc
2472+ self ._loc_fullscreen = self .loc_container .locator (
2473+ "> bslib-tooltip > .bslib-full-screen-enter"
2474+ )
2475+
2476+ # an easier approach is using `#bslib-full-screen-overlay:has(+ div#{id}.card) > a`
2477+ # but playwright doesn't allow that
2478+ self ._loc_close_button = (
2479+ self .page .locator (f"#bslib-full-screen-overlay + div#{ id } .bslib-value-box" )
2480+ .locator (".." )
2481+ .locator ("#bslib-full-screen-overlay > a" )
2482+ )
2483+
2484+ def expect_height (self , value : StyleValue , * , timeout : Timeout = None ) -> None :
2485+ expect_to_have_style (
2486+ self .loc_container , "--bslib-grid-height" , value , timeout = timeout
2487+ )
2488+
2489+ def expect_title (
2490+ self ,
2491+ text : PatternOrStr ,
2492+ * ,
2493+ timeout : Timeout = None ,
2494+ ) -> None :
2495+ playwright_expect (self .loc_title ).to_have_text (
2496+ text ,
2497+ timeout = timeout ,
2498+ )
2499+
2500+ # hard to test since it can be customized by user
2501+ # def expect_showcase_layout(self, layout, *, timeout: Timeout = None) -> None:
2502+ # raise NotImplementedError()
2503+
2504+
2505+ class Card (_WidthLocM , _CardFooterM , _CardBodyM , _CardFullScreenM , _InputWithContainer ):
2506+ # *args: TagChild | TagAttrs | CardItem,
2507+ # full_screen: bool = False,
2508+ # height: CssUnit | None = None,
2509+ # max_height: CssUnit | None = None,
2510+ # min_height: CssUnit | None = None,
2511+ # fill: bool = True,
2512+ # class_: str | None = None,
2513+ # wrapper: WrapperCallable | MISSING_TYPE | None = MISSING,
2514+ # **kwargs: TagAttrValue
2515+ def __init__ (self , page : Page , id : str ) -> None :
2516+ super ().__init__ (
2517+ page ,
2518+ id = id ,
2519+ loc_container = f"div#{ id } .card" ,
2520+ loc = "> div.card-body" ,
2521+ )
2522+ self .loc_title = self .loc_container .locator ("> div.card-header" )
2523+ self .loc_footer = self .loc_container .locator ("> div.card-footer" )
2524+ self ._loc_fullscreen = self .loc_container .locator (
2525+ "> bslib-tooltip > .bslib-full-screen-enter"
2526+ )
2527+ # an easier approach is using `#bslib-full-screen-overlay:has(+ div#{id}.card) > a`
2528+ # but playwright doesn't allow that
2529+ self ._loc_close_button = (
2530+ self .page .locator (f"#bslib-full-screen-overlay + div#{ id } " )
2531+ .locator (".." )
2532+ .locator ("#bslib-full-screen-overlay > a" )
2533+ )
2534+ self .loc_body = self .loc
2535+
2536+ def expect_header (
2537+ self ,
2538+ text : PatternOrStr ,
2539+ * ,
2540+ timeout : Timeout = None ,
2541+ ) -> None :
2542+ playwright_expect (self .loc_title ).to_have_text (
2543+ text ,
2544+ timeout = timeout ,
2545+ )
2546+
2547+ # def expect_body(
2548+ # self,
2549+ # text: PatternOrStr,
2550+ # index: int = 0,
2551+ # *,
2552+ # timeout: Timeout = None,
2553+ # ) -> None:
2554+ # """Note: Function requires an index since multiple bodies can exist in loc"""
2555+ # playwright_expect(self.loc.nth(index).locator("> :first-child")).to_have_text(
2556+ # text,
2557+ # timeout=timeout,
2558+ # )
2559+
2560+ def expect_max_height (self , value : StyleValue , * , timeout : Timeout = None ) -> None :
2561+ expect_to_have_style (self .loc_container , "max-height" , value , timeout = timeout )
2562+
2563+ def expect_min_height (self , value : StyleValue , * , timeout : Timeout = None ) -> None :
2564+ expect_to_have_style (self .loc_container , "min-height" , value , timeout = timeout )
2565+
2566+ def expect_height (self , value : StyleValue , * , timeout : Timeout = None ) -> None :
2567+ expect_to_have_style (self .loc_container , "height" , value , timeout = timeout )
0 commit comments