import{a as e,n as t}from"./chunk-BneVvdWh.js";import{t as n}from"./react-C7IZe2D1.js";import{t as r}from"./jsx-runtime-C2wGStra.js";import{n as i,t as a}from"./IconButton-DZfzVk_P.js";import{n as o,t as s}from"./Tooltip-F-35Ygr4.js";import{n as c,t as l}from"./TokyoUIFav-vlMA44YV.js";var u,d,f,p,m,h,g,_,v,y,b,x,S;t((()=>{e(n(),1),o(),i(),c(),u=r(),{within:d,userEvent:f,waitFor:p,fireEvent:m,expect:h,waitForElementToBeRemoved:g,fn:_}=__STORYBOOK_MODULE_TEST__,v={title:`Components/Tooltip/Tests`,component:s,parameters:{layout:`centered`,controls:{disable:!0},chromatic:{disableSnapshot:!0}},tags:[`!autodocs`,`!a11y-test`,`test`],decorators:[e=>(0,u.jsx)(`div`,{style:{margin:`100px 0`},children:e()})],args:{content:`Tooltip content`,dataset:{testid:`tooltip`},children:(0,u.jsx)(a,{svg:(0,u.jsx)(l,{}),assistiveText:`Favorite`})}},y={args:{onOpenChange:_()},play:async({canvas:e,step:t,args:n})=>{let r=e.getByRole(`button`);await t(`onOpenChange is not called`,async()=>{}),await t(`hover trigger element`,async()=>{h(n.onOpenChange).not.toBeCalled(),await f.hover(r)}),await t(`tooltip should be shown`,async()=>{await p(()=>h(e.getByTestId(`tooltip`)).toBeVisible()),h(n.onOpenChange).toHaveBeenCalledOnce(),h(n.onOpenChange).toBeCalledWith(!0)}),await t(`unhover trigger element`,async()=>{await f.unhover(r),m.pointerMove(document,{clientX:0,clientY:0})}),await t(`tooltip should be hidden`,async()=>{await g(()=>e.queryByTestId(`tooltip`)),h(n.onOpenChange).toHaveBeenCalledTimes(2),h(n.onOpenChange).toBeCalledWith(!1)})}},b={args:{trigger:`hover-and-touch`,onOpenChange:_(console.info)},play:async({canvasElement:e,step:t,args:n})=>{let r=d(e),i=r.getByRole(`button`);await t(`press trigger element`,async()=>{h(n.onOpenChange).not.toBeCalled(),await m.touchStart(i)}),await t(`tooltip should be shown`,async()=>{await p(()=>{h(r.getByTestId(`tooltip`)).toBeVisible()}),h(n.onOpenChange).toBeCalledWith(!0),h(n.onOpenChange).toHaveBeenCalledTimes(1)}),await t(`release trigger element`,async()=>{await m.touchEnd(i)}),await t(`tooltip should be still visible`,async()=>{await p(()=>{h(r.getByTestId(`tooltip`)).toBeInTheDocument(),h(n.onOpenChange).toHaveBeenCalledTimes(1)})}),await t(`touch outside of tooltip`,async()=>{await f.click(document.body)}),await t(`tooltip should be hidden`,async()=>{await g(()=>r.queryByTestId(`tooltip`)),h(n.onOpenChange).toHaveBeenCalledTimes(2),h(n.onOpenChange).toBeCalledWith(!1)})}},x={args:{trigger:`hover-and-touch`,onOpenChange:_(console.info)},play:async({canvasElement:e,step:t,args:n})=>{let r=d(e),i=r.getByRole(`button`);await t(`press trigger element`,async()=>{h(n.onOpenChange).not.toBeCalled(),await m.touchStart(i)}),await t(`tooltip should be shown`,async()=>{await p(()=>{h(r.getByTestId(`tooltip`)).toBeVisible()}),h(n.onOpenChange).toBeCalledWith(!0),h(n.onOpenChange).toHaveBeenCalledOnce()}),await t(`keep the trigger pressed for a long time`,async()=>{await new Promise(e=>setTimeout(e,350))}),await t(`release trigger element`,async()=>{await m.touchEnd(i)}),await t(`tooltip should be hidden`,async()=>{await g(()=>r.queryByTestId(`tooltip`)),h(n.onOpenChange).toHaveBeenCalledTimes(2),h(n.onOpenChange).toBeCalledWith(!1)})}},y.parameters={...y.parameters,docs:{...y.parameters?.docs,source:{originalSource:`{
  args: {
    onOpenChange: fn()
  },
  play: async ({
    canvas,
    step,
    args
  }) => {
    const button = canvas.getByRole('button');
    await step('onOpenChange is not called', async () => {});
    await step('hover trigger element', async () => {
      expect(args.onOpenChange).not.toBeCalled();
      await userEvent.hover(button);
    });
    await step('tooltip should be shown', async () => {
      await waitFor(() => {
        const tooltip = canvas.getByTestId('tooltip');
        return expect(tooltip).toBeVisible();
      });
      expect(args.onOpenChange).toHaveBeenCalledOnce();
      expect(args.onOpenChange).toBeCalledWith(true);
    });
    await step('unhover trigger element', async () => {
      await userEvent.unhover(button);
      // Radix Tooltip uses a "grace area" polygon that requires
      // a pointermove on document to trigger dismissal.
      // userEvent.unhover doesn't fire this event.
      fireEvent.pointerMove(document, {
        clientX: 0,
        clientY: 0
      });
    });
    await step('tooltip should be hidden', async () => {
      await waitForElementToBeRemoved(() => canvas.queryByTestId('tooltip'));
      expect(args.onOpenChange).toHaveBeenCalledTimes(2);
      expect(args.onOpenChange).toBeCalledWith(false);
    });
  }
}`,...y.parameters?.docs?.source}}},b.parameters={...b.parameters,docs:{...b.parameters?.docs,source:{originalSource:`{
  args: {
    trigger: 'hover-and-touch',
    onOpenChange: fn(console.info)
  },
  play: async ({
    canvasElement,
    step,
    args
  }) => {
    const canvas = within(canvasElement);
    const button = canvas.getByRole('button');
    await step('press trigger element', async () => {
      expect(args.onOpenChange).not.toBeCalled();
      await fireEvent.touchStart(button);
    });
    await step('tooltip should be shown', async () => {
      await waitFor(() => {
        const tooltip = canvas.getByTestId('tooltip');
        expect(tooltip).toBeVisible();
      });
      expect(args.onOpenChange).toBeCalledWith(true);
      expect(args.onOpenChange).toHaveBeenCalledTimes(1);
    });
    await step('release trigger element', async () => {
      await fireEvent.touchEnd(button);
    });
    await step('tooltip should be still visible', async () => {
      await waitFor(() => {
        const tooltip = canvas.getByTestId('tooltip');
        expect(tooltip).toBeInTheDocument();
        expect(args.onOpenChange).toHaveBeenCalledTimes(1);
      });
    });
    await step('touch outside of tooltip', async () => {
      await userEvent.click(document.body);
    });
    await step('tooltip should be hidden', async () => {
      await waitForElementToBeRemoved(() => canvas.queryByTestId('tooltip'));
      expect(args.onOpenChange).toHaveBeenCalledTimes(2);
      expect(args.onOpenChange).toBeCalledWith(false);
    });
  }
}`,...b.parameters?.docs?.source}}},x.parameters={...x.parameters,docs:{...x.parameters?.docs,source:{originalSource:`{
  args: {
    trigger: 'hover-and-touch',
    onOpenChange: fn(console.info)
  },
  play: async ({
    canvasElement,
    step,
    args
  }) => {
    const canvas = within(canvasElement);
    const button = canvas.getByRole('button');
    await step('press trigger element', async () => {
      expect(args.onOpenChange).not.toBeCalled();
      await fireEvent.touchStart(button);
    });
    await step('tooltip should be shown', async () => {
      await waitFor(() => {
        const tooltip = canvas.getByTestId('tooltip');
        expect(tooltip).toBeVisible();
      });
      expect(args.onOpenChange).toBeCalledWith(true);
      expect(args.onOpenChange).toHaveBeenCalledOnce();
    });
    await step('keep the trigger pressed for a long time', async () => {
      await new Promise(resolve => setTimeout(resolve, LONG_PRESS_DELAY +
      // 50ms is a random delay to avoid test flakiness without impacting test execution time significantly
      50));
    });
    await step('release trigger element', async () => {
      await fireEvent.touchEnd(button);
    });
    await step('tooltip should be hidden', async () => {
      await waitForElementToBeRemoved(() => canvas.queryByTestId('tooltip'));
      expect(args.onOpenChange).toHaveBeenCalledTimes(2);
      expect(args.onOpenChange).toBeCalledWith(false);
    });
  }
}`,...x.parameters?.docs?.source}}},S=[`Hover`,`Touch`,`LongTouch`]}))();export{y as Hover,x as LongTouch,b as Touch,S as __namedExportsOrder,v as default};