mirror of
https://github.com/shlinkio/shlink-web-client.git
synced 2024-12-23 09:30:31 +03:00
Migrated CreateShortUrl test to react testing library
This commit is contained in:
parent
e538f2a3bb
commit
105254d053
2 changed files with 17 additions and 26 deletions
|
@ -55,7 +55,6 @@ export const CreateShortUrl = (
|
|||
mode={basicMode ? 'create-basic' : 'create'}
|
||||
onSave={async (data: ShortUrlData) => {
|
||||
resetCreateShortUrl();
|
||||
|
||||
return createShortUrl(data);
|
||||
}}
|
||||
/>
|
||||
|
|
|
@ -1,38 +1,30 @@
|
|||
import { shallow, ShallowWrapper } from 'enzyme';
|
||||
import { render, screen } from '@testing-library/react';
|
||||
import { Mock } from 'ts-mockery';
|
||||
import { CreateShortUrl as createShortUrlsCreator } from '../../src/short-urls/CreateShortUrl';
|
||||
import { ShortUrlCreation } from '../../src/short-urls/reducers/shortUrlCreation';
|
||||
import { Settings } from '../../src/settings/reducers/settings';
|
||||
|
||||
describe('<CreateShortUrl />', () => {
|
||||
let wrapper: ShallowWrapper;
|
||||
const ShortUrlForm = () => null;
|
||||
const CreateShortUrlResult = () => null;
|
||||
const ShortUrlForm = () => <span>ShortUrlForm</span>;
|
||||
const CreateShortUrlResult = () => <span>CreateShortUrlResult</span>;
|
||||
const shortUrlCreation = { validateUrls: true };
|
||||
const shortUrlCreationResult = Mock.all<ShortUrlCreation>();
|
||||
const createShortUrl = jest.fn(async () => Promise.resolve());
|
||||
const CreateShortUrl = createShortUrlsCreator(ShortUrlForm, CreateShortUrlResult);
|
||||
const setUp = () => render(
|
||||
<CreateShortUrl
|
||||
shortUrlCreationResult={shortUrlCreationResult}
|
||||
createShortUrl={createShortUrl}
|
||||
selectedServer={null}
|
||||
resetCreateShortUrl={() => {}}
|
||||
settings={Mock.of<Settings>({ shortUrlCreation })}
|
||||
/>,
|
||||
);
|
||||
|
||||
beforeEach(() => {
|
||||
const CreateShortUrl = createShortUrlsCreator(ShortUrlForm, CreateShortUrlResult);
|
||||
it('renders computed initial state', () => {
|
||||
setUp();
|
||||
|
||||
wrapper = shallow(
|
||||
<CreateShortUrl
|
||||
shortUrlCreationResult={shortUrlCreationResult}
|
||||
createShortUrl={createShortUrl}
|
||||
selectedServer={null}
|
||||
resetCreateShortUrl={() => {}}
|
||||
settings={Mock.of<Settings>({ shortUrlCreation })}
|
||||
/>,
|
||||
);
|
||||
});
|
||||
afterEach(() => wrapper.unmount());
|
||||
afterEach(jest.clearAllMocks);
|
||||
|
||||
it('renders a ShortUrlForm with a computed initial state', () => {
|
||||
const form = wrapper.find(ShortUrlForm);
|
||||
const result = wrapper.find(CreateShortUrlResult);
|
||||
|
||||
expect(form).toHaveLength(1);
|
||||
expect(result).toHaveLength(1);
|
||||
expect(screen.getByText('ShortUrlForm')).toBeInTheDocument();
|
||||
expect(screen.getByText('CreateShortUrlResult')).toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue