Skip to content

Commit

Permalink
chore: Update and remove unused packages (#990)
Browse files Browse the repository at this point in the history
Co-authored-by: Michael Marszalek <[email protected]>
Co-authored-by: Øyvind Thune <[email protected]>
  • Loading branch information
3 people authored Nov 1, 2023
1 parent dcc846f commit 4d94921
Show file tree
Hide file tree
Showing 13 changed files with 1,632 additions and 2,442 deletions.
1 change: 1 addition & 0 deletions .stylelintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ module.exports = {
rules: {
'prettier/prettier': true,
'declaration-block-no-redundant-longhand-properties': null,
'media-feature-range-notation': 'prefix',
'custom-property-pattern': null,
// 'custom-property-pattern': 'fds-.+', // this rule needs to replaced the one above once we have new tokens
'selector-class-pattern': [
Expand Down
1 change: 1 addition & 0 deletions apps/storefront/components/CodeSnippet/CodeSnippet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ const CodeSnippet = ({ language = 'markup', children = '' }) => {
<FilesIcon fontSize={20} />
</button>
</Tippy>
{/* @ts-expect-error Error (TS2786) */}
<SyntaxHighlighter
style={nightOwl}
language='jsx'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
.font {
min-height: 81px;
min-height: 72px;
width: 120px;
border-radius: 4px;
display: flex;
Expand Down
52 changes: 21 additions & 31 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,10 @@
},
"devDependencies": {
"@altinn/figma-design-tokens": "^6.0.1",
"@babel/core": "^7.21.8",
"@babel/preset-env": "^7.21.5",
"@babel/preset-react": "^7.18.6",
"@babel/preset-typescript": "^7.21.5",
"@commitlint/cli": "^17.4.1",
"@commitlint/config-conventional": "^17.4.0",
"@digdir/design-system-react": "*",
"@digdir/design-system-tokens": "*",
"@etchteam/storybook-addon-css-variables-theme": "^1.5.1",
"@next/eslint-plugin-next": "^13.2.4",
"@next/eslint-plugin-next": "^13.5.6",
"@rollup/plugin-commonjs": "^25.0.4",
"@rollup/plugin-image": "^3.0.2",
"@rollup/plugin-json": "^6.0.0",
Expand All @@ -61,38 +55,34 @@
"@storybook/react": "^7.5.1",
"@storybook/react-webpack5": "^7.5.1",
"@storybook/theming": "^7.5.1",
"@svgr/cli": "^6.5.1",
"@svgr/core": "^6.5.1",
"@svgr/rollup": "^8.1.0",
"@testing-library/jest-dom": "6.1.3",
"@testing-library/jest-dom": "^6.1.4",
"@testing-library/react": "^14.0.0",
"@testing-library/user-event": "^14.5.1",
"@types/jest": "^29.0.0",
"@types/jest": "^29.5.6",
"@types/node": "^18.11.11",
"@types/react": "^18.2.0",
"@types/react-dom": "^18.2.0",
"@types/rimraf": "^3.0.2",
"@types/testing-library__jest-dom": "^5.14.5",
"@typescript-eslint/eslint-plugin": "6.7.3",
"@typescript-eslint/parser": "6.7.3",
"babel-jest": "^29.5.0",
"babel-loader": "^9.1.2",
"classnames": "^2.3.1",
"@types/prettier": "^2.7.1",
"@types/react": "^18.2.31",
"@types/react-dom": "^18.2.14",
"@types/rimraf": "^4.0.5",
"@typescript-eslint/eslint-plugin": "6.9.0",
"@typescript-eslint/parser": "6.9.0",
"classnames": "^2.3.2",
"copyfiles": "^2.4.1",
"eslint": "8.50.0",
"eslint-config-prettier": "8.5.0",
"eslint": "8.52.0",
"eslint-config-prettier": "9.0.0",
"eslint-import-resolver-typescript": "3.6.1",
"eslint-plugin-import": "2.26.0",
"eslint-plugin-jsx-a11y": "6.6.1",
"eslint-plugin-import": "2.29.0",
"eslint-plugin-jsx-a11y": "6.7.1",
"eslint-plugin-prettier": "4.2.1",
"eslint-plugin-react": "7.31.6",
"eslint-plugin-react": "7.33.2",
"eslint-plugin-react-hooks": "4.6.0",
"eslint-plugin-storybook": "^0.6.15",
"esno": "^0.17.0",
"identity-obj-proxy": "3.0.0",
"jest": "^29.0.3",
"jest": "^29.7.0",
"jest-css-modules-transform": "^4.4.2",
"jest-environment-jsdom": "^29.0.3",
"jest-environment-jsdom": "^29.7.0",
"lerna": "^7.1.5",
"postcss": "^8.4.16",
"prettier": "^2.7.1",
Expand All @@ -106,12 +96,12 @@
"rollup-plugin-postcss": "^4.0.2",
"storybook": "^7.5.1",
"storybook-css-modules": "^1.0.8",
"stylelint": "^15.3.0",
"stylelint-config-css-modules": "^4.2.0",
"stylelint": "^15.11.0",
"stylelint-config-css-modules": "^4.3.0",
"stylelint-config-prettier": "^9.0.5",
"stylelint-config-standard": "^31.0.0",
"stylelint-config-standard": "^34.0.0",
"stylelint-prettier": "^3.0.0",
"ts-jest": "^29.1.0",
"ts-jest": "^29.1.1",
"ts-node": "^10.9.1",
"tslib": "^2.4.1",
"typescript": "^5.2.2",
Expand Down
2 changes: 1 addition & 1 deletion packages/react/src/components/Button/Button.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const stack = (Story: PartialStoryFn<ReactRenderer>) => (

const icon = <akselIcons.FloppydiskIcon />;

type AkselIcon = typeof akselIcons['AirplaneFillIcon'];
type AkselIcon = (typeof akselIcons)['AirplaneFillIcon'];
type AkselIcons = Record<string, AkselIcon>;

export const Preview: Story = {
Expand Down
4 changes: 2 additions & 2 deletions packages/react/src/components/Button/Button.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { ReactNode } from 'react';
import React, { forwardRef, type ButtonHTMLAttributes } from 'react';
import React, { forwardRef } from 'react';
import type { ReactNode, ButtonHTMLAttributes } from 'react';
import cn from 'classnames';

import { SvgIcon } from '../SvgIcon';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React from 'react';
import '@testing-library/jest-dom';
import { render as renderRtl, screen } from '@testing-library/react';
import userEvent from '@testing-library/user-event';

Expand All @@ -25,16 +26,14 @@ const defaultProps: OptionProps = {
};

describe('Option', () => {
afterEach(jest.clearAllMocks);

it('Renders label by default', () => {
render();
expect(screen.getByRole('option')).toHaveTextContent(label);
});

it('Renders with given value', () => {
render();
expect(screen.getByRole('option')).toHaveValue(value);
expect(screen.getByRole('option')).toHaveAttribute('value', value);
});

it('Renders formattedLabel if provided', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const multiSelectOptions: MultiSelectOption[] = [

const specificPropKeys = ['Single', 'Multiple'] as const;
const specificProps: Record<
typeof specificPropKeys[number],
(typeof specificPropKeys)[number],
Pick<OptionListProps, 'options' | 'multiple'>
> = {
Single: {
Expand Down
195 changes: 99 additions & 96 deletions packages/react/src/components/Tooltip/Tooltip.test.tsx
Original file line number Diff line number Diff line change
@@ -1,96 +1,99 @@
import React from 'react';
import userEvent from '@testing-library/user-event';
import { act, render as renderRtl, screen } from '@testing-library/react';

import type { TooltipProps } from './Tooltip';
import { Tooltip } from './Tooltip';

const render = async (props: Partial<TooltipProps> = {}) => {
const allProps: TooltipProps = {
children: <button>My button</button>,
content: 'Tooltip text',
...props,
};
/* Flush microtasks */
await act(async () => {});
const user = userEvent.setup();

return {
user,
...renderRtl(<Tooltip {...allProps} />),
};
};

describe('Tooltip', () => {
describe('should render children', () => {
it('should render child', async () => {
await render();
const tooltipTrigger = screen.getByRole('button', { name: 'My button' });

expect(tooltipTrigger).toBeInTheDocument();
});
});

describe('should render tooltip', () => {
it('should render tooltip on hover', async () => {
const { user } = await render();
const tooltipTrigger = screen.getByRole('button', { name: 'My button' });

expect(screen.queryByRole('tooltip')).not.toBeInTheDocument();
await act(async () => await user.hover(tooltipTrigger));
const tooltip = await screen.findByText('Tooltip text');
expect(tooltip).toBeInTheDocument();
expect(screen.queryByRole('tooltip')).toBeInTheDocument();
});

it('should render tooltip on focus', async () => {
await render();
const tooltipTrigger = screen.getByRole('button', { name: 'My button' });

expect(screen.queryByText('Tooltip text')).not.toBeInTheDocument();
act(() => tooltipTrigger.focus());
const tooltip = await screen.findByText('Tooltip text');
expect(tooltip).toBeInTheDocument();
expect(screen.queryByRole('tooltip')).toBeInTheDocument();
});

it('should close tooltip on escape', async () => {
const { user } = await render();
const tooltipTrigger = screen.getByRole('button', { name: 'My button' });

expect(screen.queryByText('Tooltip text')).not.toBeInTheDocument();
await act(async () => {
await user.hover(tooltipTrigger);
});
const tooltip = await screen.findByText('Tooltip text');
expect(tooltip).toBeInTheDocument();
await act(async () => {
await user.keyboard('[Escape]');
});
expect(screen.queryByText('Tooltip text')).not.toBeInTheDocument();
});
});

it('should render open when we pass open prop', async () => {
await render({ open: true });
const tooltipTrigger = screen.getByRole('button', { name: 'My button' });

expect(screen.getByRole('tooltip')).toBeInTheDocument();
expect(tooltipTrigger).toHaveAttribute('aria-describedby');
});

it('delay', async () => {
const user = userEvent.setup();

await render({ delay: 300 });

await act(async () => {
await user.hover(screen.getByRole('button'));
await new Promise((r) => setTimeout(r, 250));
expect(screen.queryByRole('tooltip')).toBeNull();
await new Promise((r) => setTimeout(r, 600));
});

expect(screen.getByRole('tooltip')).toBeVisible();
});
});
import React from 'react';
import userEvent from '@testing-library/user-event';
import {
act,
render as renderRtl,
screen,
waitFor,
} from '@testing-library/react';

import type { TooltipProps } from './Tooltip';
import { Tooltip } from './Tooltip';

const render = async (props: Partial<TooltipProps> = {}) => {
const allProps: TooltipProps = {
children: <button>My button</button>,
content: 'Tooltip text',
...props,
};
/* Flush microtasks */
await act(async () => {});
const user = userEvent.setup();

return {
user,
...renderRtl(<Tooltip {...allProps} />),
};
};

describe('Tooltip', () => {
describe('should render children', () => {
it('should render child', async () => {
await render();
const tooltipTrigger = screen.getByRole('button', { name: 'My button' });

expect(tooltipTrigger).toBeInTheDocument();
});
});

describe('should render tooltip', () => {
it('should render tooltip on hover', async () => {
const { user } = await render();
const tooltipTrigger = screen.getByRole('button', { name: 'My button' });

expect(screen.queryByRole('tooltip')).not.toBeInTheDocument();
await act(async () => await user.hover(tooltipTrigger));
const tooltip = await screen.findByText('Tooltip text');
expect(tooltip).toBeInTheDocument();
expect(screen.queryByRole('tooltip')).toBeInTheDocument();
});

it('should render tooltip on focus', async () => {
await render();
const tooltipTrigger = screen.getByRole('button', { name: 'My button' });

expect(screen.queryByText('Tooltip text')).not.toBeInTheDocument();
act(() => tooltipTrigger.focus());
const tooltip = await screen.findByText('Tooltip text');
expect(tooltip).toBeInTheDocument();
expect(screen.queryByRole('tooltip')).toBeInTheDocument();
});

it('should close tooltip on escape', async () => {
const { user } = await render();
const tooltipTrigger = screen.getByRole('button', { name: 'My button' });

expect(screen.queryByText('Tooltip text')).not.toBeInTheDocument();
await act(async () => {
await user.hover(tooltipTrigger);
});
const tooltip = await screen.findByText('Tooltip text');
expect(tooltip).toBeInTheDocument();
await act(async () => {
await user.keyboard('[Escape]');
});
expect(screen.queryByText('Tooltip text')).not.toBeInTheDocument();
});
});

it('should render open when we pass open prop', async () => {
await render({ open: true });
const tooltipTrigger = screen.getByRole('button', { name: 'My button' });

expect(screen.getByRole('tooltip')).toBeInTheDocument();
expect(tooltipTrigger).toHaveAttribute('aria-describedby');
});

it('delay', async () => {
const user = userEvent.setup();

await render({ delay: 300 });

await user.hover(screen.getByRole('button'));
expect(screen.queryByRole('tooltip')).toBeNull();

await waitFor(() => {
expect(screen.queryByRole('tooltip')).toBeVisible();
});
});
});
2 changes: 1 addition & 1 deletion packages/react/src/components/_InputWrapper/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export const inputVariants = [
'readonlyInfo',
'readonlyConfirm',
] as const;
export type InputVariant_ = typeof inputVariants[number];
export type InputVariant_ = (typeof inputVariants)[number];

export type ReadOnlyVariant_ = 'readonlyInfo' | 'readonlyConfirm';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export const popoverVariants = [
'danger',
] as const;

type PopoverVariant_ = typeof popoverVariants[number];
type PopoverVariant_ = (typeof popoverVariants)[number];

interface IPopoverOptions extends HTMLAttributes<HTMLDivElement> {
variant?: PopoverVariant_;
Expand Down
2 changes: 1 addition & 1 deletion packages/tokens/scripts/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ void registerTransforms(StyleDictionary);

// File name under design-tokens/Brand
const brands = ['Digdir', 'Tilsynet', 'Altinn', 'Brreg'] as const;
type Brands = typeof brands[number];
type Brands = (typeof brands)[number];

type Densities = 'Default' | 'Compact';
const prefix = 'fds';
Expand Down
Loading

0 comments on commit 4d94921

Please sign in to comment.