Code Monkey home page Code Monkey logo

Comments (1)

borisdiakur avatar borisdiakur commented on June 16, 2024

Hi @mkilp,

thanks for submitting this issue. I checked your repository and after adjusting a few things could run the test. Here is what I did:

App.js:

-import { useRef } from "react";
+import { useRef, useState } from "react";
import {
  LdButton,
  LdModal,
  LdTypo,
  LdSelect,
  LdOption
} from "@emdgroup-liquid/liquid/dist/react";
import "./styles.css";
import { defineCustomElements } from "@emdgroup-liquid/liquid/dist/loader";
import "@emdgroup-liquid/liquid/dist/css/liquid.global.css";

export default function App() {
  defineCustomElements();
  const modalRef = useRef(null);
  const tetherOptions = {
    bodyElement: modalRef.current,
    constraints: [{ to: "scrollParent" }]
  };
+ const [open, setOpen] = useState(false)
  return (
    <div className="App">
-     <LdModal ref={modalRef} tetherOptions={tetherOptions}>
+     <LdModal
+       ref={modalRef}
+       tetherOptions={tetherOptions}
+       open={open}
+       onLdmodalclosed={() => setOpen(false)}>
        <LdSelect
          filter
          placeholder={"select"}
          name={"filter"}
          mode="detached"
          tetherOptions={tetherOptions}
        >
          <LdOption key={0} value={"test"} selected={false} disabled={false}>
-           <LdTypo variant="h6">test</LdTypo>
+           test
          </LdOption>
        </LdSelect>
      </LdModal>

-     <LdButton onClick={() => modalRef.current.showModal()}>
+     <LdButton
+       onClick={() => {
+         setOpen(true)
+       }}>
        Open Modal
      </LdButton>
    </div>
  );
}

example.spec.ts:

import {expect, test} from "@playwright/test";

test('Custom Filter: Selected Filters Area', async ({page}) => {
  await page.goto('./');
- await page.locator('_react=LdButton').click();
- await page.locator('_react=LdSelect').click();
- let test = await page.locator('_react=LdSelect')
-     .locator("_react=LdOption")
-     .nth(0)
-     .click();
+
+ await page.getByRole('button', { name: 'Open Modal' }).click();
+
+ await page.getByLabel('select').click();
+ await page.getByRole('option', { name: 'test' }).click();
+
+ await page.getByLabel('test').click();
+ await page.getByRole('option', { name: 'test' }).click();
+
+ await page.getByLabel('Dismiss').click();
});

The LdOption component is not a UI-Component. It's only there for you to declaratively compose the options of the LdSelect component. So you cannot click it. What the LdSelect component does "under the hood" is the following: It watches the LdOptions and copies them to the popper element (that is handled by Tether) as LdOptionInternal components. The LdOptionInternal component is a UI component and can be clicked. Though, in your test code, it doesn't suffice to just change LdOption to LdOptionInternal, because the LdOptionInternal component is not located within the LdSelect component, but rather in the popper element.

To get around such issues when writing tests in general, I suggest you to use selectors which do not rely on implementation details. I also highly recommend you to have a look at Playwright's awesome codegen feature, which will help you to come up with correct selectors.

from liquid.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.