diff --git a/ts/test/components/AvatarPlaceHolder_test.tsx b/ts/test/components/AvatarPlaceHolder_test.tsx index 388bee5a3..e4e39702f 100644 --- a/ts/test/components/AvatarPlaceHolder_test.tsx +++ b/ts/test/components/AvatarPlaceHolder_test.tsx @@ -8,6 +8,7 @@ import { MemberAvatarPlaceHolder } from '../../components/icon/MemberAvatarPlace import { TestUtils } from '../test-utils'; import { areResultsEqual, findByDataTestId, renderComponent } from './renderComponent'; +// TODO[epic=SES-2418] migrate to Storybook describe('AvatarPlaceHolder', () => { const pubkey = TestUtils.generateFakePubKeyStr(); const displayName = 'Hello World'; diff --git a/ts/test/components/SessionInput_test.tsx b/ts/test/components/SessionInput_test.tsx new file mode 100644 index 000000000..c857892f7 --- /dev/null +++ b/ts/test/components/SessionInput_test.tsx @@ -0,0 +1,27 @@ +/* eslint-disable import/no-extraneous-dependencies */ +import { cleanup } from '@testing-library/react'; +import { expect } from 'chai'; +import Sinon from 'sinon'; +import { SessionInput } from '../../components/inputs'; +import { TestUtils } from '../test-utils'; +import { findAllByElementType, renderComponent } from './renderComponent'; + +// TODO[epic=SES-2418] migrate to Storybook +describe('SessionInput', () => { + beforeEach(() => { + TestUtils.stubSVGElement(); + TestUtils.stubWindowLog(); + }); + + afterEach(() => { + Sinon.restore(); + cleanup(); + }); + + it('should render an input', async () => { + const result = renderComponent(); + const inputElements = findAllByElementType(result, 'input'); + expect(inputElements.length, 'should have an input element').to.equal(1); + result.unmount(); + }); +}); diff --git a/ts/test/components/renderComponent.tsx b/ts/test/components/renderComponent.tsx index c11ce694c..0b73a0041 100644 --- a/ts/test/components/renderComponent.tsx +++ b/ts/test/components/renderComponent.tsx @@ -1,6 +1,6 @@ import { AnimatePresence, MotionGlobalConfig } from 'framer-motion'; import { isArray, isEqual, unset } from 'lodash'; -import { ReactElement, ReactNode } from 'react'; +import { ElementType, ReactElement, ReactNode } from 'react'; import { ErrorBoundary } from 'react-error-boundary'; import TestRenderer from 'react-test-renderer'; import { SessionTheme } from '../../themes/SessionTheme'; @@ -39,6 +39,13 @@ function findByDataTestId( return renderResult.root.findByProps({ 'data-testid': dataTestId }); } +function findAllByElementType( + renderResult: TestRenderer.ReactTestRenderer, + elementType: ElementType +): Array { + return renderResult.root.findAllByType(elementType); +} + function areResultsEqual( renderResult: TestRenderer.ReactTestRenderer, renderResult2: TestRenderer.ReactTestRenderer, @@ -55,4 +62,10 @@ function areResultsEqual( return isEqual(renderResult.toJSON(), renderResult2.toJSON()); } -export { areResultsEqual, findByDataTestId, getComponentTree, renderComponent }; +export { + areResultsEqual, + findAllByElementType, + findByDataTestId, + getComponentTree, + renderComponent, +};