Skip to content

Commit

Permalink
chore: adds snapshot tests to main test utils wrappers (#2980)
Browse files Browse the repository at this point in the history
  • Loading branch information
orangevolon authored Nov 5, 2024
1 parent 7175cd1 commit d8edc99
Show file tree
Hide file tree
Showing 18 changed files with 1,744 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import React from 'react';
import { render } from '@testing-library/react';

import { getRequiredPropsForComponent } from './required-props-for-components';
import { getAllComponents, requireComponent, supportsDOMProperties } from './utils';
import { getRequiredPropsForComponent } from '../required-props-for-components';
import { getAllComponents, requireComponent, supportsDOMProperties } from '../utils';

describe('Base props support', () => {
const componentRoot = document.createElement('div');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
import React from 'react';
import { render } from '@testing-library/react';

import FormField, { FormFieldProps } from '../../lib/components/form-field';
import { FormFieldValidationControlProps } from '../../lib/components/internal/context/form-field-context';
import createWrapper, { ElementWrapper } from '../../lib/components/test-utils/dom';
import { getRequiredPropsForComponent } from './required-props-for-components';
import { requireComponent } from './utils';
import FormField, { FormFieldProps } from '../../../lib/components/form-field';
import { FormFieldValidationControlProps } from '../../../lib/components/internal/context/form-field-context';
import createWrapper, { ElementWrapper } from '../../../lib/components/test-utils/dom';
import { getRequiredPropsForComponent } from '../required-props-for-components';
import { requireComponent } from '../utils';

const formFieldControlComponents = [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// SPDX-License-Identifier: Apache-2.0
import { pascalCase } from 'change-case';

import { getAllComponents, requireComponent } from './utils';
import { getAllComponents, requireComponent } from '../utils';

describe('component displayName matches import directory name', () => {
getAllComponents().forEach(componentName => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import React from 'react';
import { render } from '@testing-library/react';

import { getRequiredPropsForComponent } from './required-props-for-components';
import { getAllComponents, requireComponent } from './utils';
import { getRequiredPropsForComponent } from '../required-props-for-components';
import { getAllComponents, requireComponent } from '../utils';

const skippedComponents = ['button'];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,16 @@ import path from 'path';

// There are no typings for package.json
// eslint-disable-next-line @typescript-eslint/no-var-requires
const packageJson = require('../../lib/components/package.json');
const packageJson = require('../../../lib/components/package.json');

test('all exports declarations resolve to a file', () => {
for (const exportPath of Object.values<string>(packageJson.exports)) {
// context export is a folder, cannot be resolved
if (exportPath === './internal/context/') {
continue;
}
expect(() => require.resolve(exportPath, { paths: [path.join(__dirname, '../../lib/components')] })).not.toThrow();
expect(() =>
require.resolve(exportPath, { paths: [path.join(__dirname, '../../../lib/components')] })
).not.toThrow();
}
});
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
import React from 'react';
import { renderToStaticMarkup } from 'react-dom/server';

import { getRequiredPropsForComponent } from './required-props-for-components';
import { getAllComponents, requireComponent } from './utils';
import { getRequiredPropsForComponent } from '../required-props-for-components';
import { getAllComponents, requireComponent } from '../utils';

const skipComponents = [
'modal', // it uses portal API which does not work on server
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import * as React from 'react';
import { render } from '@testing-library/react';

import '../__a11y__/to-validate-a11y';
import '../../__a11y__/to-validate-a11y';

describe('a11y validator', () => {
test('valid', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import React from 'react';
import { render } from 'react-dom';
import { render as renderTestingLibrary } from '@testing-library/react';

import Button from '../../lib/components/button';
import createWrapper from '../../lib/components/test-utils/dom';
import Button from '../../../lib/components/button';
import createWrapper from '../../../lib/components/test-utils/dom';

describe('createWrapper', () => {
let spy: jest.SpyInstance;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import { pascalCase } from 'change-case';

import { COMPONENT_METADATA_KEY } from '@cloudscape-design/component-toolkit/internal';

import { PACKAGE_VERSION } from '../../lib/components/internal/environment';
import { getRequiredPropsForComponent } from './required-props-for-components';
import { getAllComponents, requireComponent, supportsDOMProperties } from './utils';
import { PACKAGE_VERSION } from '../../../lib/components/internal/environment';
import { getRequiredPropsForComponent } from '../required-props-for-components';
import { getAllComponents, requireComponent, supportsDOMProperties } from '../utils';

describe('useBaseComponent hook is used in all allowlisted public components', () => {
const componentRoot = document.createElement('div');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import React from 'react';
import { render } from '@testing-library/react';

import { getRequiredPropsForComponent } from './required-props-for-components';
import { getAllComponents, requireComponent } from './utils';
import { getRequiredPropsForComponent } from '../required-props-for-components';
import { getAllComponents, requireComponent } from '../utils';

declare global {
interface Window {
Expand Down
Loading

0 comments on commit d8edc99

Please sign in to comment.