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'}
|
mode={basicMode ? 'create-basic' : 'create'}
|
||||||
onSave={async (data: ShortUrlData) => {
|
onSave={async (data: ShortUrlData) => {
|
||||||
resetCreateShortUrl();
|
resetCreateShortUrl();
|
||||||
|
|
||||||
return createShortUrl(data);
|
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 { Mock } from 'ts-mockery';
|
||||||
import { CreateShortUrl as createShortUrlsCreator } from '../../src/short-urls/CreateShortUrl';
|
import { CreateShortUrl as createShortUrlsCreator } from '../../src/short-urls/CreateShortUrl';
|
||||||
import { ShortUrlCreation } from '../../src/short-urls/reducers/shortUrlCreation';
|
import { ShortUrlCreation } from '../../src/short-urls/reducers/shortUrlCreation';
|
||||||
import { Settings } from '../../src/settings/reducers/settings';
|
import { Settings } from '../../src/settings/reducers/settings';
|
||||||
|
|
||||||
describe('<CreateShortUrl />', () => {
|
describe('<CreateShortUrl />', () => {
|
||||||
let wrapper: ShallowWrapper;
|
const ShortUrlForm = () => <span>ShortUrlForm</span>;
|
||||||
const ShortUrlForm = () => null;
|
const CreateShortUrlResult = () => <span>CreateShortUrlResult</span>;
|
||||||
const CreateShortUrlResult = () => null;
|
|
||||||
const shortUrlCreation = { validateUrls: true };
|
const shortUrlCreation = { validateUrls: true };
|
||||||
const shortUrlCreationResult = Mock.all<ShortUrlCreation>();
|
const shortUrlCreationResult = Mock.all<ShortUrlCreation>();
|
||||||
const createShortUrl = jest.fn(async () => Promise.resolve());
|
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(() => {
|
it('renders computed initial state', () => {
|
||||||
const CreateShortUrl = createShortUrlsCreator(ShortUrlForm, CreateShortUrlResult);
|
setUp();
|
||||||
|
|
||||||
wrapper = shallow(
|
expect(screen.getByText('ShortUrlForm')).toBeInTheDocument();
|
||||||
<CreateShortUrl
|
expect(screen.getByText('CreateShortUrlResult')).toBeInTheDocument();
|
||||||
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);
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue