shlink-web-client/test/short-urls/CreateShortUrl.test.tsx

39 lines
1.3 KiB
TypeScript
Raw Normal View History

import { shallow, ShallowWrapper } from 'enzyme';
import { Mock } from 'ts-mockery';
import createShortUrlsCreator from '../../src/short-urls/CreateShortUrl';
import { ShortUrlCreation } from '../../src/short-urls/reducers/shortUrlCreation';
import { Settings } from '../../src/settings/reducers/settings';
2018-11-01 15:15:09 +03:00
describe('<CreateShortUrl />', () => {
let wrapper: ShallowWrapper;
const ShortUrlForm = () => null;
const CreateShortUrlResult = () => null;
const shortUrlCreation = { validateUrls: true };
const shortUrlCreationResult = Mock.all<ShortUrlCreation>();
const createShortUrl = jest.fn(async () => Promise.resolve());
2018-11-01 15:15:09 +03:00
beforeEach(() => {
const CreateShortUrl = createShortUrlsCreator(ShortUrlForm, CreateShortUrlResult);
2018-11-01 15:15:09 +03:00
wrapper = shallow(
<CreateShortUrl
shortUrlCreationResult={shortUrlCreationResult}
createShortUrl={createShortUrl}
selectedServer={null}
resetCreateShortUrl={() => {}}
settings={Mock.of<Settings>({ shortUrlCreation })}
/>,
2018-11-01 15:15:09 +03:00
);
});
afterEach(() => wrapper.unmount());
afterEach(jest.clearAllMocks);
2018-11-01 15:15:09 +03:00
it('renders a ShortUrlForm with a computed initial state', () => {
const form = wrapper.find(ShortUrlForm);
const result = wrapper.find(CreateShortUrlResult);
2018-11-01 15:15:09 +03:00
expect(form).toHaveLength(1);
expect(result).toHaveLength(1);
2018-11-01 15:15:09 +03:00
});
});