Skip to content

Commit

Permalink
Fix storybook tests (#6150)
Browse files Browse the repository at this point in the history
The PRs merged on Friday introduced regressions on our storybook tests
suite
  • Loading branch information
charlesBochet authored Jul 6, 2024
1 parent 7b3a590 commit 46dac5a
Show file tree
Hide file tree
Showing 10 changed files with 44 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ import toKebabCase from 'lodash.kebabcase';
import { ObjectMetadataItem } from '../types/ObjectMetadataItem';

export const getObjectSlug = (
objectMetadataItem: Pick<ObjectMetadataItem, 'labelPlural'>,
) => toKebabCase(objectMetadataItem.labelPlural);
objectMetadataItem: Pick<ObjectMetadataItem, 'namePlural'>,
) => toKebabCase(objectMetadataItem.namePlural);
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ export const Disabled: Story = {
};

export const WithOpenSelect: Story = {
play: async ({ canvasElement }) => {
const canvas = within(canvasElement);
play: async () => {
const canvas = within(document.body);

const inputField = await canvas.findByText('Text');

Expand All @@ -49,8 +49,8 @@ export const WithExcludedFieldTypes: Story = {
args: {
excludedFieldTypes: [FieldMetadataType.Uuid, FieldMetadataType.Numeric],
},
play: async ({ canvasElement }) => {
const canvas = within(canvasElement);
play: async () => {
const canvas = within(document.body);

const inputField = await canvas.findByText('Text');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ type Story = StoryObj<typeof SettingsObjectInactiveMenuDropDown>;
export const Default: Story = {};

export const Open: Story = {
play: async ({ canvasElement }) => {
const canvas = within(canvasElement);
play: async () => {
const canvas = within(document.body);

const dropdownButton = await canvas.getByRole('button');

Expand All @@ -45,8 +45,8 @@ export const Open: Story = {
};

export const WithActivate: Story = {
play: async ({ canvasElement }) => {
const canvas = within(canvasElement);
play: async () => {
const canvas = within(document.body);

const dropdownButton = await canvas.getByRole('button');

Expand All @@ -66,8 +66,8 @@ export const WithActivate: Story = {

export const WithDelete: Story = {
args: { isCustomObject: true },
play: async ({ canvasElement }) => {
const canvas = within(canvasElement);
play: async () => {
const canvas = within(document.body);

const dropdownButton = await canvas.getByRole('button');

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Controller, useFormContext } from 'react-hook-form';
import styled from '@emotion/styled';
import { Controller, useFormContext } from 'react-hook-form';
import { z } from 'zod';

import { ObjectMetadataItem } from '@/object-metadata/types/ObjectMetadataItem';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ type Story = StoryObj<typeof IconPicker>;
export const Default: Story = {};

export const WithOpen: Story = {
play: async ({ canvasElement }) => {
const canvas = within(canvasElement);
play: async () => {
const canvas = within(document.body);

const iconPickerButton = await canvas.findByRole('button', {
name: 'Click to select icon (no icon selected)',
Expand All @@ -54,8 +54,8 @@ export const WithSelectedIcon: Story = {

export const WithOpenAndSelectedIcon: Story = {
...WithSelectedIcon,
play: async ({ canvasElement }) => {
const canvas = within(canvasElement);
play: async () => {
const canvas = within(document.body);

const iconPickerButton = await canvas.findByRole('button', {
name: 'Click to select icon (selected: IconCalendarEvent)',
Expand All @@ -67,8 +67,8 @@ export const WithOpenAndSelectedIcon: Story = {

export const WithSearch: Story = {
...WithSelectedIcon,
play: async ({ canvasElement }) => {
const canvas = within(canvasElement);
play: async () => {
const canvas = within(document.body);

const iconPickerButton = await canvas.findByRole('button', {
name: 'Click to select icon (selected: IconCalendarEvent)',
Expand All @@ -92,8 +92,8 @@ export const WithSearch: Story = {

export const WithSearchAndClose: Story = {
...WithSelectedIcon,
play: async ({ canvasElement }) => {
const canvas = within(canvasElement);
play: async () => {
const canvas = within(document.body);

let iconPickerButton = await canvas.findByRole('button', {
name: 'Click to select icon (selected: IconCalendarEvent)',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ type Story = StoryObj<typeof InternalDatePicker>;
export const Default: Story = {};

export const WithOpenMonthSelect: Story = {
play: async ({ canvasElement }) => {
const canvas = within(canvasElement);
play: async () => {
const canvas = within(document.body);

const monthSelect = await canvas.findByText('January');

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { useState } from 'react';
import styled from '@emotion/styled';
import { Decorator, Meta, StoryObj } from '@storybook/react';
import { expect, userEvent, waitFor, within } from '@storybook/test';
import { PlayFunction } from '@storybook/types';
import { useState } from 'react';
import { Avatar, ComponentDecorator } from 'twenty-ui';

import { Button } from '@/ui/input/button/components/Button';
Expand Down Expand Up @@ -76,8 +76,8 @@ export const Empty: Story = {
<StyledEmptyDropdownContent data-testid="dropdown-content" />
),
},
play: async ({ canvasElement }) => {
const canvas = within(canvasElement);
play: async () => {
const canvas = within(document.body);

const button = await canvas.findByRole('button');
userEvent.click(button);
Expand Down Expand Up @@ -199,8 +199,8 @@ const FakeCheckableMenuItemList = ({ hasAvatar }: { hasAvatar?: boolean }) => {
);
};

const playInteraction: PlayFunction<any, any> = async ({ canvasElement }) => {
const canvas = within(canvasElement);
const playInteraction: PlayFunction<any, any> = async () => {
const canvas = within(document.body);

const button = await canvas.findByRole('button');
userEvent.click(button);
Expand Down Expand Up @@ -251,8 +251,8 @@ export const SearchWithLoadingMenu: Story = {
</>
),
},
play: async ({ canvasElement }) => {
const canvas = within(canvasElement);
play: async () => {
const canvas = within(document.body);

const button = await canvas.findByRole('button');

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { zodResolver } from '@hookform/resolvers/zod';
import pick from 'lodash.pick';
import { useEffect } from 'react';
import { FormProvider, useForm } from 'react-hook-form';
import { useNavigate, useParams } from 'react-router-dom';
import { zodResolver } from '@hookform/resolvers/zod';
import pick from 'lodash.pick';
import { H2Title, IconArchive, IconSettings } from 'twenty-ui';
import { z } from 'zod';

Expand Down Expand Up @@ -81,7 +81,12 @@ export const SettingsObjectEdit = () => {
),
});

navigate(`${settingsObjectsPagePath}/${getObjectSlug(formValues)}`);
navigate(
`${settingsObjectsPagePath}/${getObjectSlug({
...formValues,
namePlural: formValues.labelPlural,
})}`,
);
} catch (error) {
enqueueSnackBar((error as Error).message, {
variant: SnackBarVariant.Error,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,13 @@ export const StandardObject: Story = {

export const CustomObject: Story = {
args: {
routeParams: { ':objectSlug': 'workspaces' },
routeParams: { ':objectSlug': 'my-customs' },
},
};

export const ObjectDropdownMenu: Story = {
play: async ({ canvasElement }) => {
await sleep(100);

const canvas = within(canvasElement);
play: async () => {
const canvas = within(document.body);
const objectSummaryVerticalDotsIconButton = await canvas.findByRole(
'button',
{
Expand All @@ -59,10 +57,8 @@ export const ObjectDropdownMenu: Story = {
};

export const FieldDropdownMenu: Story = {
play: async ({ canvasElement }) => {
await sleep(100);

const canvas = within(canvasElement);
play: async () => {
const canvas = within(document.body);
const [fieldVerticalDotsIconButton] = await canvas.findAllByRole('button', {
name: 'Active Field Options',
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
import { CurrencyCode } from '@/object-record/record-field/types/CurrencyCode';
import {
FieldMetadataType,
ObjectEdge,
ObjectMetadataItemsQuery,
ObjectMetadataItemsQuery
} from '~/generated-metadata/graphql';
import { CalendarChannelVisibility, MessageChannelVisibility } from "~/generated/graphql";

// This file is not designed to be manually edited.
// It's an extract from the dev seeded environment metadata call
Expand Down

0 comments on commit 46dac5a

Please sign in to comment.