UNPKG

@agnos-ui/page-objects

Version:

Page objects to be used when testing AgnosUI-based applications with Playwright.

2 lines (1 loc) 16.8 kB
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const l=require("@agnos-ui/base-po"),m={rootComponent:".modal",closeButton:".btn-close",backdrop:"xpath=./preceding-sibling::div[contains(@class,'modal-backdrop')]",header:".modal-header",title:".modal-title",body:".modal-body",footer:".modal-footer"};class w extends l.BasePO{selectors=structuredClone(m);getComponentSelector(){return this.selectors.rootComponent}get locatorHeader(){return this.locatorRoot.locator(this.selectors.header)}get locatorTitle(){return this.locatorHeader.locator(this.selectors.title)}get locatorBody(){return this.locatorRoot.locator(this.selectors.body)}get locatorFooter(){return this.locatorRoot.locator(this.selectors.footer)}get locatorCloseButton(){return this.locatorRoot.locator(this.selectors.closeButton)}get locatorBackdrop(){return this.locatorRoot.locator(this.selectors.backdrop)}async state(){return this.locatorRoot.evaluate((t,e)=>{const o=t.querySelector(e.closeButton)?.getAttribute("aria-label"),r=t.querySelector(e.header)?.innerText?.trim(),s=t.querySelector(e.title)?.innerText?.trim(),a=t.querySelector(e.body)?.innerText?.trim(),n=t.querySelector(e.footer)?.innerText?.trim();return{rootClasses:t.className.trim().split(" ").sort(),header:r,title:s,body:a,footer:n,closeButton:o}},this.selectors)}}const p={rootComponent:".au-pagination",activePage:".active",previousPage:".au-previous",nextPage:".au-next",firstPage:".au-first",lastPage:".au-last",pages:".au-page",ellipses:".au-ellipsis"};class k extends l.BasePO{selectors=structuredClone(p);getComponentSelector(){return this.selectors.rootComponent}get locatorActivePage(){return this.locatorRoot.locator(this.selectors.activePage)}get locatorPreviousButton(){return this.locatorRoot.locator(this.selectors.previousPage)}get locatorNextButton(){return this.locatorRoot.locator(this.selectors.nextPage)}get locatorFirstButton(){return this.locatorRoot.locator(this.selectors.firstPage)}get locatorLastButton(){return this.locatorRoot.locator(this.selectors.lastPage)}get locatorPages(){return this.locatorRoot.locator(this.selectors.pages)}locatorNthPage(t){return this.locatorRoot.locator(this.selectors.pages).nth(t-1)}locatorPage(t){return this.locatorRoot.locator(this.selectors.pages,{hasText:t})}get locatorEllipses(){return this.locatorRoot.locator(this.selectors.ellipses)}async state(){return this.locatorRoot.evaluate(t=>{const e={rootClasses:[],disabled:null,pages:[],hrefs:[]},o=[...t.querySelectorAll(".au-page")],r=[],s=[],a={},n=g=>g?.getAttribute("href"),d=t.querySelector("a.au-first"),u=t.querySelector("a.au-previous"),i=t.querySelector("a.au-next"),h=t.querySelector("a.au-last");d&&(a.first=n(d)),u&&(a.previous=n(u)),i&&(a.next=n(i)),h&&(a.last=n(h));for(const g of o)s.push(g.getAttribute("href")||""),r.push((g.textContent||"").trim());const q=[...t.querySelectorAll("a.au-page[aria-disabled]")];return e.pages=r,e.hrefs=s,e.hrefsNavigation=a,e.rootClasses=t.className.trim().split(" "),e.disabled=q.length===o.length?"true":null,t.querySelector("a.au-previous[aria-disabled]")?e.isPreviousDisabled=!0:u&&(e.isPreviousDisabled=!1),t.querySelector("a.au-next[aria-disabled]")?e.isNextDisabled=!0:i&&(e.isNextDisabled=!1),t.querySelector("a.au-first[aria-disabled]")?e.isFirstDisabled=!0:d&&(e.isFirstDisabled=!1),t.querySelector("a.au-last[aria-disabled]")?e.isLastDisabled=!0:h&&(e.isLastDisabled=!1),e})}}const y={rootComponent:".au-rating",star:".au-rating-star"};class T extends l.BasePO{selectors=structuredClone(y);getComponentSelector(){return this.selectors.rootComponent}locatorStar(t){return this.locatorRoot.locator(this.selectors.star).nth(t)}async state(){return await this.locatorRoot.evaluate((t,e)=>{const o=[...t.querySelectorAll(e.star)],r=[],s=[];for(const a of o)r.push((a.textContent||"").trim()),s.push(a.className.split(" "));return{rootClasses:t.className.trim().split(" ").sort(),value:t.getAttribute("aria-valuenow"),min:t.getAttribute("aria-valuemin"),max:t.getAttribute("aria-valuemax"),text:t.getAttribute("aria-valuetext"),disabled:t.getAttribute("aria-disabled"),readonly:t.getAttribute("aria-readonly"),stars:r,classes:s}},this.selectors)}}const C={rootComponent:".au-select"};class L extends l.BasePO{selectors=structuredClone(C);getComponentSelector(){return this.selectors.rootComponent}get locatorInput(){return this.locatorRoot.locator('input[type="text"]').nth(0)}get locatorMenu(){return this.locatorRoot.locator(".dropdown-menu")}get locatorMenuItems(){return this.locatorMenu.locator(".au-select-item")}locatorMenuItem(t){return this.locatorMenu.getByText(t).nth(0)}get locatorBadges(){return this.locatorRoot.locator("div.au-select-badge")}locatorBadgeItem(t){return this.locatorBadges.filter({hasText:t}).nth(0)}async state(){return await this.locatorRoot.evaluate(t=>{const e=t.querySelector('div[role="combobox"]'),o=t.querySelector('input[type="text"]'),r=[];if(e){const u=e.querySelectorAll("div.au-select-badge");for(const i of u)r.push(i?.textContent?.trim())}const s=t.querySelector("ul.dropdown-menu"),a=s!=null,n=[],d=[];if(s!=null){const u=s.querySelectorAll("li.dropdown-item");for(const i of u){const h=i.textContent?.trim();n.push(h),i.classList.contains("selected")&&d.push(h)}}return{text:o.value,badges:r,isOpen:a,list:n,checked:d}})}}const S={rootComponent:".alert",body:".alert-body",closeButton:".btn-close"};class V extends l.BasePO{selectors=structuredClone(S);getComponentSelector(){return this.selectors.rootComponent}get locatorCloseButton(){return this.locatorRoot.locator(this.selectors.closeButton)}async state(){return this.locatorRoot.evaluate((t,e)=>{const o=t.querySelector(e.body)?.innerText?.replace(/[^\x20-\x7E]/g,""),r=t.querySelector(e.closeButton)?.getAttribute("aria-label");return{rootClasses:t.className.trim().split(" ").sort(),body:o,closeButton:r}},this.selectors)}}class I extends l.BasePO{selectors={item:".accordion-item",bodyContainer:".accordion-collapse",body:".accordion-body",header:".accordion-header",buttons:".accordion-button"};getComponentSelector(){return".au-accordion"}get locatorAccordionItems(){return this.locatorRoot.locator(this.selectors.item)}locatorAccordionItem(t){return this.locatorRoot.locator(this.selectors.item).nth(t)}get locatorAccordionCBodyContainers(){return this.locatorAccordionItems.locator(this.selectors.bodyContainer)}locatorAccordionBodyContainer(t){return this.locatorAccordionItem(t).locator(this.selectors.bodyContainer)}get locatorAccordionBodies(){return this.locatorAccordionCBodyContainers.locator(this.selectors.body)}locatorAccordionBody(t){return this.locatorAccordionBodyContainer(t).locator(this.selectors.body)}get locatorAccordionHeaders(){return this.locatorAccordionItems.locator(this.selectors.header)}locatorAccordionHeader(t){return this.locatorAccordionItem(t).locator(this.selectors.header)}get locatorAccordionButtons(){return this.locatorAccordionHeaders.locator(this.selectors.buttons)}locatorAccordionButton(t){return this.locatorAccordionHeader(t).locator(this.selectors.buttons)}async state(){return await this.locatorRoot.evaluate(t=>{const e=[...t.querySelectorAll(".accordion-item")],o=[];for(const r of e){const s=r.querySelector(".accordion-collapse"),a=r.querySelector(".accordion-button");o.push({classes:r.className.trim().split(" "),id:r.id,isInDOM:s!==null,bodyContainerId:s?.id,buttonId:a?.id,expanded:a?.getAttribute("aria-expanded"),disabled:a?.getAttribute("aria-disabled"),labeledBy:s?.getAttribute("aria-labelledby"),buttonControls:a?.getAttribute("aria-controls")})}return{rootClasses:t.className.trim().split(" "),items:o}})}}const x={rootComponent:'[role="progressbar"]',outerBar:".progress",innerBar:".progress-bar"};class H extends l.BasePO{selectors=structuredClone(x);getComponentSelector(){return this.selectors.rootComponent}get locatorOuterBar(){return this.locatorRoot.locator(this.selectors.outerBar)}get locatorInnerBar(){return this.locatorRoot.locator(this.selectors.innerBar)}async state(){return this.locatorRoot.evaluate(t=>{const e=t.querySelector(".progress-bar"),o=t.querySelector(".progress");return{ariaLabel:t.getAttribute("aria-label"),ariaValueNow:t.getAttribute("aria-valuenow"),ariaValueMin:t.getAttribute("aria-valuemin"),ariaValueMax:t.getAttribute("aria-valuemax"),ariaValueText:t.getAttribute("aria-valuetext"),label:e?.textContent?.trim(),innerClasses:e?.className?.trim()?.split(" ")?.sort()??[],outerHeight:o?.style?.height,innerWidth:e?.style?.width}})}}const B={rootComponent:".au-slider",clickableArea:".au-slider-clickable-area",clickableAreaVertical:".au-slider-clickable-area-vertical",handle:".au-slider-handle",tick:".au-slider-tick",tickLabel:".au-slider-tick-label",tickLabelVertical:".au-slider-tick-label-vertical",tickLabelNow:".au-slider-tick-label-now",minLabelHorizontal:".au-slider-label-min",maxLabelHorizontal:".au-slider-label-max",minLabelVertical:".au-slider-label-vertical-min",maxLabelVertical:".au-slider-label-vertical-max",valueLabel:".au-slider-label-now",progress:".au-slider-progress",content:".au-slider-content"};class M extends l.BasePO{selectors=structuredClone(B);getComponentSelector(){return this.selectors.rootComponent}get clickableArea(){return this.locatorRoot.locator(this.selectors.clickableArea)}get clickableAreaVertical(){return this.locatorRoot.locator(this.selectors.clickableAreaVertical)}get locatorHandle(){return this.locatorRoot.locator(this.selectors.handle)}get locatorTick(){return this.locatorRoot.locator(this.selectors.tick)}get locatorTickLabel(){return this.locatorRoot.locator(this.selectors.tickLabel)}get locatorTickLabelNow(){return this.locatorRoot.locator(this.selectors.tickLabelNow)}get locatorTickLabelVertical(){return this.locatorRoot.locator(this.selectors.tickLabelVertical)}get locatorMinLabelHorizontal(){return this.locatorRoot.locator(this.selectors.minLabelHorizontal)}get locatorMaxLabelHorizontal(){return this.locatorRoot.locator(this.selectors.maxLabelHorizontal)}get locatorMinLabelVertical(){return this.locatorRoot.locator(this.selectors.minLabelVertical)}get locatorMaxLabelVertical(){return this.locatorRoot.locator(this.selectors.maxLabelVertical)}get locatorProgress(){return this.locatorRoot.locator(this.selectors.progress)}get locatorValueLabel(){return this.locatorRoot.locator(this.selectors.valueLabel)}get locatorContent(){return this.locatorRoot.locator(this.selectors.content)}async sliderHandleState(){return this.locatorRoot.locator(this.selectors.handle).evaluateAll(t=>t.map(e=>({style:e.getAttribute("style"),value:e.getAttribute("aria-valuenow"),min:e.getAttribute("aria-valuemin"),max:e.getAttribute("aria-valuemax"),disabled:e.getAttribute("aria-disabled"),readonly:e.getAttribute("aria-readonly"),ariaLabel:e.getAttribute("aria-label"),ariaValueText:e.getAttribute("aria-valuetext")})))}async sliderProgressState(){return this.locatorRoot.locator(this.selectors.progress).evaluateAll(t=>t.map(e=>e.getAttribute("style")))}async sliderTickLabelState(t){return t.evaluateAll(e=>e.map(o=>({style:o.getAttribute("style"),innerText:o.innerText})))}}const b={rootComponent:".toast",closeButton:".btn-close",header:".toast-header",body:".toast-body"};class A extends l.BasePO{selectors=structuredClone(b);getComponentSelector(){return this.selectors.rootComponent}get locatorCloseButton(){return this.locatorRoot.locator(this.selectors.closeButton)}async state(){return await this.locatorRoot.evaluate((t,e)=>{const o=t.querySelector(e.body)?.innerText,r=t.querySelector(e.header)?.innerText,s=t.querySelector(e.closeButton)?.getAttribute("aria-label");return{rootClasses:t.className.trim().split(" ").sort(),body:o,header:r,closeButton:s}},this.selectors)}}const R={rootComponent:".au-toaster",container:".au-toaster-container",closeButton:".au-toaster-closeAll"};class E extends l.BasePO{selectors=structuredClone(R);getComponentSelector(){return this.selectors.rootComponent}get locatorContainer(){return this.locatorRoot.locator(this.selectors.container)}async toastPOs(){return Array.from({length:await this.locatorContainer.locator(b.rootComponent).count()},(t,e)=>new A(this.locatorContainer,e))}get locatorCloseButton(){return this.locatorRoot.locator(this.selectors.closeButton)}}const P={rootComponent:'[role="tree"]',itemContainer:'[role="treeitem"]',itemToggle:".au-tree-expand-icon",itemContents:".au-tree-item"};class z extends l.BasePO{selectors=structuredClone(P);getComponentSelector(){return this.selectors.rootComponent}get locatorItemToggle(){return this.locatorRoot.locator(this.selectors.itemToggle)}get locatorItemContainer(){return this.locatorRoot.locator(this.selectors.itemContents)}async itemContainerState(){return this.locatorRoot.locator(this.selectors.itemContainer).evaluateAll(t=>t.map(e=>({ariaSelected:e.getAttribute("aria-selected"),ariaExpanded:e.getAttribute("aria-expanded")})))}async itemToggleState(){return this.locatorRoot.locator(this.selectors.itemToggle).evaluateAll(t=>t.map(e=>({ariaLabel:e.getAttribute("aria-label")})))}}const v={rootComponent:".au-collapse"};class D extends l.BasePO{selectors=structuredClone(v);getComponentSelector(){return this.selectors.rootComponent}async state(){return this.locatorRoot.evaluate((t,e)=>({rootClasses:t.className.trim().split(" ").sort()}),this.selectors)}}const f={rootComponent:".au-carousel",container:".au-carousel-container",slide:".au-carousel-slide",nextBtn:".carousel-control-next",prevBtn:".carousel-control-prev",indicators:".carousel-indicators",indicatorBtn:".carousel-indicators button"};class F extends l.BasePO{selectors=structuredClone(f);getComponentSelector(){return this.selectors.rootComponent}get locatorContainer(){return this.locatorRoot.locator(this.selectors.container)}get locatorNextBtn(){return this.locatorRoot.locator(this.selectors.nextBtn)}get locatorPrevBtn(){return this.locatorRoot.locator(this.selectors.prevBtn)}get locatorIndicators(){return this.locatorRoot.locator(this.selectors.indicators)}get locatorIndicatorBtn(){return this.locatorRoot.locator(this.selectors.indicatorBtn)}get locatorSlide(){return this.locatorRoot.locator(this.selectors.slide)}async state(){return this.locatorRoot.evaluate(t=>{const e=t.querySelectorAll(".carousel-indicators button");return{rootClasses:t.className.trim().split(" ").sort(),prevBtn:t.querySelector(".carousel-control-prev")!==null,nextBtn:t.querySelector(".carousel-control-next")!==null,indicators:{selected:[...e].findIndex(o=>o.classList.contains("active")),count:e.length},slides:{visible:[...t.querySelectorAll(".au-carousel-slide")].findIndex(o=>{const r=o.getBoundingClientRect(),s=t.getBoundingClientRect();return r.left>=s.left&&r.right<=s.right})}}})}}const O={rootComponent:".au-drawer",backdrop:"xpath=./preceding-sibling::div[contains(@class,'au-drawer-backdrop')]",header:".au-drawer-header",body:".au-drawer-body",container:".au-drawer-container",splitter:".au-splitter",closeButton:"Close"};class _ extends l.BasePO{selectors=structuredClone(O);getComponentSelector(){return this.selectors.rootComponent}get locatorHeader(){return this.locatorRoot.locator(this.selectors.header)}get locatorBody(){return this.locatorRoot.locator(this.selectors.body)}get locatorBackdrop(){return this.locatorRoot.locator(this.selectors.backdrop)}get locatorContainer(){return this.locatorRoot.locator(this.selectors.container)}get locatorSplitter(){return this.locatorRoot.locator(this.selectors.splitter)}get locatorCloseButton(){return this._page.getByRole("button",{name:"Close"})}async hoverOnSplitter(){const t=this.locatorSplitter,e=await t.boundingBox(),o=Math.round(e.width/2),r=Math.round(e.height/2);return await t.hover({position:{x:o,y:r}}),{x:e.x+o,y:e.y+r}}async state(){return this.locatorRoot.evaluate((t,e)=>{const o=t.querySelector(e.header)?.innerText?.trim(),r=t.querySelector(e.body)?.innerText?.trim();return{rootClasses:t.className.trim().split(" ").sort(),header:o,body:r}},this.selectors)}async statePosition(){return this.locatorRoot.evaluate(t=>{const e=t.style;return{"--bs-drawer-size":e.getPropertyValue("--bs-drawer-size"),"--bs-drawer-size-min":e.getPropertyValue("--bs-drawer-size-min"),"--bs-drawer-size-max":e.getPropertyValue("--bs-drawer-size-max")}})}}exports.AccordionPO=I;exports.AlertPO=V;exports.CarouselPO=F;exports.CollapsePO=D;exports.DrawerPO=_;exports.ModalPO=w;exports.PaginationPO=k;exports.ProgressbarPO=H;exports.RatingPO=T;exports.SelectPO=L;exports.SliderPO=M;exports.ToastPO=A;exports.ToasterPO=E;exports.TreePO=z;exports.alertSelectors=S;exports.carouselSelectors=f;exports.collapseSelectors=v;exports.drawerSelectors=O;exports.modalSelectors=m;exports.paginationSelectors=p;exports.progressbarSelectors=x;exports.ratingSelectors=y;exports.selectSelectors=C;exports.sliderSelectors=B;exports.toastSelectors=b;exports.toasterSelectors=R;exports.treeSelectors=P;