The open alternative to Salesforce, designed for AI.
TypeScript crmcrm-systemcustomergood-first-issuegraphqlhacktoberfestjavascriptmarketingmonoreponestjsopen-sourcepostgresqlreactreactjssalestypescriptweb
Stabilize renderer popup interactions (#28665)
Raphaël Bosi3703e3294e1e
diff --git a/packages/twenty-front-component-renderer/src/__stories__/shared/test-utils/createWaitForFrontComponentInteraction.ts b/packages/twenty-front-component-renderer/src/__stories__/shared/test-utils/createWaitForFrontComponentInteraction.tsnew file mode 100644index 00000000000..184bf8a0815--- /dev/null+++ b/packages/twenty-front-component-renderer/src/__stories__/shared/test-utils/createWaitForFrontComponentInteraction.ts@@ -0,0 +1,7 @@+import { waitFor } from 'storybook/test';++import { INTERACTION_TIMEOUT } from '@/__stories__/shared/test-utils/timeouts';++export const createWaitForFrontComponentInteraction =+ (container: HTMLElement) => (assertion: () => void | Promise<void>) =>+ waitFor(assertion, { container, timeout: INTERACTION_TIMEOUT });diff --git a/packages/twenty-front-component-renderer/src/__stories__/twenty-ui-gallery/utils/countrySelectTest.ts b/packages/twenty-front-component-renderer/src/__stories__/twenty-ui-gallery/utils/countrySelectTest.tsindex 26248147423..5b54e263f91 100644--- a/packages/twenty-front-component-renderer/src/__stories__/twenty-ui-gallery/utils/countrySelectTest.ts+++ b/packages/twenty-front-component-renderer/src/__stories__/twenty-ui-gallery/utils/countrySelectTest.ts@@ -1,6 +1,7 @@-import { expect, userEvent, waitFor, within } from 'storybook/test';+import { expect, userEvent, within } from 'storybook/test';import { errorHandler } from '@/__stories__/shared/test-utils/createFrontComponentStoryMeta';+import { createWaitForFrontComponentInteraction } from '@/__stories__/shared/test-utils/createWaitForFrontComponentInteraction';import { expectFrontComponentMounted } from '@/__stories__/shared/test-utils/matchers/expectFrontComponentMounted';import { waitForSandboxRoundTrip } from '@/__stories__/shared/test-utils/waitForSandboxRoundTrip';import { type TwentyUiGalleryPlayFunction } from '@/__stories__/twenty-ui-gallery/types/TwentyUiGalleryPlayFunction';@@ -67,13 +68,21 @@ const selectCountry = async ({optionName: string;}) => {const trigger = canvas.getByRole('button', { name: triggerName });+ const waitForInteraction = createWaitForFrontComponentInteraction(+ trigger.ownerDocument.body,+ );await userEvent.click(trigger);- await waitFor(() => expect(trigger).toHaveAttribute('aria-expanded', 'true'));- await userEvent.click(await page.findByRole('option', { name: optionName }));- await waitFor(() =>- expect(trigger).toHaveAttribute('aria-expanded', 'false'),- );+ await waitForInteraction(() => {+ expect(trigger).toHaveAttribute('aria-expanded', 'true');+ expect(page.getByRole('option', { name: optionName })).toBeVisible();+ });+ const popup = page.getByRole('dialog');+ await userEvent.click(page.getByRole('option', { name: optionName }));+ await waitForInteraction(() => {+ expect(trigger).toHaveAttribute('aria-expanded', 'false');+ expect(popup).not.toBeInTheDocument();+ });};export const countrySelectTest: TwentyUiGalleryPlayFunction = async (@@ -81,6 +90,9 @@ export const countrySelectTest: TwentyUiGalleryPlayFunction = async () => {const canvas = within(context.canvasElement);const page = within(context.canvasElement.ownerDocument.body);+ const waitForInteraction = createWaitForFrontComponentInteraction(+ context.canvasElement.ownerDocument.body,+ );await expectFrontComponentMounted(canvas);expectTriggersShowSavedCountriesWithDecorativeFlags(canvas);@@ -97,7 +109,7 @@ export const countrySelectTest: TwentyUiGalleryPlayFunction = async (});await userEvent.click(billingTrigger);- await waitFor(() => {+ await waitForInteraction(() => {expect(page.getByRole('dialog', { name: 'Billing countries' }),).toBeVisible();@@ -119,6 +131,8 @@ export const countrySelectTest: TwentyUiGalleryPlayFunction = async ();const search = page.getByRole('searchbox', { name: 'Search' });expect(search.tagName).toBe('INPUT');+ expect(search).toBeVisible();+ expect(search).toHaveFocus();expect(search).toHaveAttribute('title', 'Search billing countries');expect(search).toHaveAttribute('data-ref-target', 'billing-country-search');expect(@@ -135,7 +149,7 @@ export const countrySelectTest: TwentyUiGalleryPlayFunction = async (expect(billingTrigger).toHaveAttribute('aria-expanded', 'true');await userEvent.click(page.getByRole('option', { name: 'Brésil' }));- await waitFor(() => {+ await waitForInteraction(() => {expect(billingTrigger).toHaveTextContent('Brésil');expect(billingTrigger).toHaveAttribute('aria-expanded', 'false');expect(savedCountries).toHaveTextContent('Billing: BR; Shipping: JP');@@ -151,7 +165,7 @@ export const countrySelectTest: TwentyUiGalleryPlayFunction = async (triggerName: BILLING_COUNTRY_TRIGGER_NAME,optionName: 'No country',});- await waitFor(() => {+ await waitForInteraction(() => {expect(billingTrigger).toHaveTextContent('No country');expect(savedCountries).toHaveTextContent('Billing: null; Shipping: JP');expect(@@ -171,7 +185,7 @@ export const countrySelectTest: TwentyUiGalleryPlayFunction = async (triggerName: 'Shipping country',optionName: 'No country',});- await waitFor(() => {+ await waitForInteraction(() => {expect(shippingTrigger).toHaveTextContent('No country');expect(savedCountries).toHaveTextContent('Billing: JP; Shipping: null');});@@ -181,7 +195,7 @@ export const countrySelectTest: TwentyUiGalleryPlayFunction = async (triggerName: 'Shipping country',optionName: 'Brésil',});- await waitFor(() => {+ await waitForInteraction(() => {expect(shippingTrigger).toHaveTextContent('Brésil');expect(savedCountries).toHaveTextContent('Billing: JP; Shipping: BR');});@@ -192,7 +206,7 @@ export const countrySelectTest: TwentyUiGalleryPlayFunction = async (triggerName: 'Default country',optionName: 'No country',});- await waitFor(() =>+ await waitForInteraction(() =>expect(savedCountries).toHaveTextContent('Default: null'),);await selectCountry({@@ -201,14 +215,19 @@ export const countrySelectTest: TwentyUiGalleryPlayFunction = async (triggerName: 'Default country',optionName: 'Japon',});- await waitFor(() => expect(savedCountries).toHaveTextContent('Default: JP'));+ await waitForInteraction(() =>+ expect(savedCountries).toHaveTextContent('Default: JP'),+ );const cancelableTrigger = canvas.getByRole('button', {name: 'Cancelable country',});await userEvent.click(cancelableTrigger);- await userEvent.click(await page.findByRole('option', { name: 'Brésil' }));- await waitFor(() => {+ await waitForInteraction(() =>+ expect(page.getByRole('option', { name: 'Brésil' })).toBeVisible(),+ );+ await userEvent.click(page.getByRole('option', { name: 'Brésil' }));+ await waitForInteraction(() => {expect(cancelableTrigger).toHaveTextContent('France');expect(cancelableTrigger).toHaveAttribute('aria-expanded', 'true');expect(savedCountries).toHaveTextContent('Cancelable: FR');@@ -219,9 +238,10 @@ export const countrySelectTest: TwentyUiGalleryPlayFunction = async ('aria-selected','true',);+ expect(page.getByRole('option', { name: 'Japon' })).toBeVisible();});await userEvent.click(page.getByRole('option', { name: 'Japon' }));- await waitFor(() => {+ await waitForInteraction(() => {expect(cancelableTrigger).toHaveTextContent('Japon');expect(cancelableTrigger).toHaveAttribute('aria-expanded', 'false');expect(savedCountries).toHaveTextContent('Cancelable: JP');@@ -230,7 +250,7 @@ export const countrySelectTest: TwentyUiGalleryPlayFunction = async (await userEvent.click(canvas.getByRole('button', { name: 'Set countries externally' }),);- await waitFor(() => {+ await waitForInteraction(() => {expect(billingTrigger).toHaveTextContent('Brésil');expect(shippingTrigger).toHaveTextContent('Brésil');expect(savedCountries).toHaveTextContent('Billing: BR; Shipping: BR');@@ -238,25 +258,30 @@ export const countrySelectTest: TwentyUiGalleryPlayFunction = async (await userEvent.click(canvas.getByRole('button', { name: 'Clear countries externally' }),);- await waitFor(() => {+ await waitForInteraction(() => {expect(billingTrigger).toHaveTextContent('No country');expect(shippingTrigger).toHaveTextContent('No country');expect(savedCountries).toHaveTextContent('Billing: null; Shipping: null');});await userEvent.click(billingTrigger);- expect(- await page.findByRole('option', { name: 'No country' }),- ).toHaveAttribute('aria-selected', 'true');- const search = page.getByRole('searchbox', { name: 'Search' });- await userEvent.type(search, 'jap');- await waitFor(() => {+ await waitForInteraction(() => {+ expect(page.getByRole('option', { name: 'No country' })).toHaveAttribute(+ 'aria-selected',+ 'true',+ );+ const search = page.getByRole('searchbox', { name: 'Search' });+ expect(search).toBeVisible();+ expect(search).toHaveFocus();+ });+ await userEvent.type(page.getByRole('searchbox', { name: 'Search' }), 'jap');+ await waitForInteraction(() => {expect(page.getByRole('option', { name: 'Japon' })).toBeVisible();expect(page.queryByRole('option', { name: 'France' })).toBeNull();expect(page.queryByRole('option', { name: 'Brésil' })).toBeNull();});await userEvent.click(page.getByRole('option', { name: 'Japon' }));- await waitFor(() => {+ await waitForInteraction(() => {expect(billingTrigger).toHaveTextContent('Japon');expect(savedCountries).toHaveTextContent('Billing: JP; Shipping: null');});diff --git a/packages/twenty-front-component-renderer/src/__stories__/twenty-ui-gallery/utils/overflowingListApiTest.ts b/packages/twenty-front-component-renderer/src/__stories__/twenty-ui-gallery/utils/overflowingListApiTest.tsindex fe37083b95b..bb95ebd24ab 100644--- a/packages/twenty-front-component-renderer/src/__stories__/twenty-ui-gallery/utils/overflowingListApiTest.ts+++ b/packages/twenty-front-component-renderer/src/__stories__/twenty-ui-gallery/utils/overflowingListApiTest.ts@@ -1,6 +1,7 @@-import { expect, userEvent, waitFor, within } from 'storybook/test';+import { expect, userEvent, within } from 'storybook/test';import { errorHandler } from '@/__stories__/shared/test-utils/createFrontComponentStoryMeta';+import { createWaitForFrontComponentInteraction } from '@/__stories__/shared/test-utils/createWaitForFrontComponentInteraction';import { expectFrontComponentMounted } from '@/__stories__/shared/test-utils/matchers/expectFrontComponentMounted';import { type TwentyUiGalleryPlayFunction } from '@/__stories__/twenty-ui-gallery/types/TwentyUiGalleryPlayFunction';@@ -9,6 +10,9 @@ export const overflowingListApiTest: TwentyUiGalleryPlayFunction = async ({}) => {const canvas = within(canvasElement);const page = within(canvasElement.ownerDocument.body);+ const waitForInteraction = createWaitForFrontComponentInteraction(+ canvasElement.ownerDocument.body,+ );await expectFrontComponentMounted(canvas);const initialPopup = await page.findByRole('dialog', {@@ -17,9 +21,12 @@ export const overflowingListApiTest: TwentyUiGalleryPlayFunction = async ({const initiallyHiddenItem = await within(initialPopup).findByRole('button', {name: 'Initially hidden item',});- await expect(initiallyHiddenItem).toBeVisible();+ await waitForInteraction(() => {+ expect(initiallyHiddenItem).toBeVisible();+ expect(initiallyHiddenItem).toHaveFocus();+ });await userEvent.keyboard('{Escape}');- await waitFor(() => expect(initialPopup).not.toBeVisible());+ await waitForInteraction(() => expect(initialPopup).not.toBeInTheDocument());const trigger = canvas.getByRole('button', {name: 'Custom overflow trigger',@@ -33,7 +40,7 @@ export const overflowingListApiTest: TwentyUiGalleryPlayFunction = async ({name: 'Controlled overflow items',});await expect(popup.tagName).toBe('SECTION');- await waitFor(() =>+ await waitForInteraction(() =>expect(canvas.getByLabelText('Overflow open changes')).toHaveTextContent('true:trigger-press:click',),@@ -44,25 +51,28 @@ export const overflowingListApiTest: TwentyUiGalleryPlayFunction = async ({await expect(canvas.getByLabelText('Overflow parent activations'),).toHaveTextContent('1');- await waitFor(() =>- expect(within(popup).getAllByRole('button')).toHaveLength(3),- );- await userEvent.click(- within(popup).getByRole('button', { name: 'Controlled Charlie' }),- );- await waitFor(() =>+ await waitForInteraction(() => {+ expect(popup).toBeVisible();+ expect(within(popup).getAllByRole('button')).toHaveLength(3);+ });+ const controlledItem = within(popup).getByRole('button', {+ name: 'Controlled Charlie',+ });+ await userEvent.click(controlledItem);+ await waitForInteraction(() => {expect(canvas.getByLabelText('Overflow popup click')).toHaveTextContent('click:Controlled Charlie',- ),- );+ );+ expect(controlledItem).toHaveFocus();+ });await userEvent.keyboard('{Escape}');- await waitFor(() =>+ await waitForInteraction(() =>expect(canvas.getByLabelText('Overflow open changes')).toHaveTextContent('false:escape-key:keydown',),);- await waitFor(async () => {+ await waitForInteraction(async () => {await expect(popup).toBeVisible();await expect(trigger).toHaveAttribute('aria-expanded', 'true');await expect(within(popup).getAllByRole('button')).toHaveLength(3);@@ -84,7 +94,7 @@ export const overflowingListApiTest: TwentyUiGalleryPlayFunction = async ({await userEvent.click(canvas.getByRole('button', { name: 'Close controlled overflow' }),);- await waitFor(() => expect(popup).not.toBeVisible());+ await waitForInteraction(() => expect(popup).not.toBeInTheDocument());await userEvent.click(canvas.getByRole('button', { name: 'Allow overflow Escape' }),);@@ -94,29 +104,34 @@ export const overflowingListApiTest: TwentyUiGalleryPlayFunction = async ({const externallyOpenedPopup = await page.findByRole('dialog', {name: 'Controlled overflow items',});- await userEvent.click(- await within(externallyOpenedPopup).findByRole('button', {- name: 'Controlled Bravo',- }),+ await waitForInteraction(() => expect(externallyOpenedPopup).toBeVisible());+ const externallyOpenedItem = within(externallyOpenedPopup).getByRole(+ 'button',+ { name: 'Controlled Bravo' },);+ await userEvent.click(externallyOpenedItem);+ await waitForInteraction(() => expect(externallyOpenedItem).toHaveFocus());await userEvent.keyboard('{Escape}');- await waitFor(() => expect(externallyOpenedPopup).not.toBeVisible());- await waitFor(() => expect(trigger).toHaveFocus());+ await waitForInteraction(() =>+ expect(externallyOpenedPopup).not.toBeInTheDocument(),+ );+ await waitForInteraction(() => expect(trigger).toHaveFocus());await userEvent.click(canvas.getByRole('button', { name: 'Open deferred overflow' }),);const deferredPopup = await page.findByRole('dialog', {name: 'Deferred overflow items',});- await waitFor(() =>- expect(within(deferredPopup).getAllByRole('button')).toHaveLength(3),- );+ await waitForInteraction(() => {+ expect(deferredPopup).toBeVisible();+ expect(within(deferredPopup).getAllByRole('button')).toHaveLength(3);+ });await userEvent.click(within(deferredPopup).getByRole('button', {name: 'Close deferred overflow',}),);- await waitFor(() => {+ await waitForInteraction(() => {expect(canvas.getByLabelText('Deferred overflow open changes'),).toHaveTextContent('false:imperative-action');@@ -129,7 +144,7 @@ export const overflowingListApiTest: TwentyUiGalleryPlayFunction = async ({await userEvent.click(canvas.getByRole('button', { name: 'Complete deferred exit' }),);- await waitFor(() => {+ await waitForInteraction(() => {expect(deferredPopup.isConnected).toBe(false);expect(canvas.getByLabelText('Deferred overflow popup mounted'),@@ -141,7 +156,7 @@ export const overflowingListApiTest: TwentyUiGalleryPlayFunction = async ({const reopenedDeferredPopup = await page.findByRole('dialog', {name: 'Deferred overflow items',});- await waitFor(() => {+ await waitForInteraction(() => {expect(reopenedDeferredPopup).toBeVisible();expect(within(reopenedDeferredPopup).getAllByRole('button')).toHaveLength(3,