2020-08-30 20:45:17 +03:00
|
|
|
import { shallow, ShallowWrapper } from 'enzyme';
|
2018-11-01 15:15:09 +03:00
|
|
|
import moment from 'moment';
|
|
|
|
import { identity } from 'ramda';
|
2020-08-30 20:45:17 +03:00
|
|
|
import { Mock } from 'ts-mockery';
|
2018-12-18 01:11:55 +03:00
|
|
|
import createShortUrlsCreator from '../../src/short-urls/CreateShortUrl';
|
2018-11-01 15:15:09 +03:00
|
|
|
import DateInput from '../../src/utils/DateInput';
|
2020-08-30 20:45:17 +03:00
|
|
|
import { ShortUrlCreation } from '../../src/short-urls/reducers/shortUrlCreation';
|
2018-11-01 15:15:09 +03:00
|
|
|
|
|
|
|
describe('<CreateShortUrl />', () => {
|
2020-08-30 20:45:17 +03:00
|
|
|
let wrapper: ShallowWrapper;
|
|
|
|
const TagsSelector = () => null;
|
|
|
|
const shortUrlCreationResult = Mock.all<ShortUrlCreation>();
|
|
|
|
const createShortUrl = jest.fn(async () => Promise.resolve());
|
2018-11-01 15:15:09 +03:00
|
|
|
|
|
|
|
beforeEach(() => {
|
2020-11-28 11:34:41 +03:00
|
|
|
const CreateShortUrl = createShortUrlsCreator(TagsSelector, () => null, () => null, () => null);
|
2018-12-18 01:11:55 +03:00
|
|
|
|
2018-11-01 15:15:09 +03:00
|
|
|
wrapper = shallow(
|
2020-08-30 20:45:17 +03:00
|
|
|
<CreateShortUrl
|
|
|
|
shortUrlCreationResult={shortUrlCreationResult}
|
|
|
|
createShortUrl={createShortUrl}
|
|
|
|
selectedServer={null}
|
|
|
|
resetCreateShortUrl={() => {}}
|
|
|
|
/>,
|
2018-11-01 15:15:09 +03:00
|
|
|
);
|
|
|
|
});
|
2020-08-30 20:45:17 +03:00
|
|
|
afterEach(() => wrapper.unmount());
|
|
|
|
afterEach(jest.clearAllMocks);
|
2018-11-01 15:15:09 +03:00
|
|
|
|
2020-03-29 20:36:45 +03:00
|
|
|
it('saves short URL with data set in form controls', () => {
|
2018-11-01 15:15:09 +03:00
|
|
|
const validSince = moment('2017-01-01');
|
|
|
|
const validUntil = moment('2017-01-06');
|
|
|
|
|
2020-03-29 20:36:45 +03:00
|
|
|
wrapper.find('.form-control-lg').simulate('change', { target: { value: 'https://long-domain.com/foo/bar' } });
|
|
|
|
wrapper.find('TagsSelector').simulate('change', [ 'tag_foo', 'tag_bar' ]);
|
|
|
|
wrapper.find('#customSlug').simulate('change', { target: { value: 'my-slug' } });
|
|
|
|
wrapper.find('#domain').simulate('change', { target: { value: 'example.com' } });
|
|
|
|
wrapper.find('#maxVisits').simulate('change', { target: { value: '20' } });
|
|
|
|
wrapper.find('#shortCodeLength').simulate('change', { target: { value: 15 } });
|
|
|
|
wrapper.find(DateInput).at(0).simulate('change', validSince);
|
|
|
|
wrapper.find(DateInput).at(1).simulate('change', validUntil);
|
|
|
|
wrapper.find('form').simulate('submit', { preventDefault: identity });
|
|
|
|
|
|
|
|
expect(createShortUrl).toHaveBeenCalledTimes(1);
|
|
|
|
expect(createShortUrl).toHaveBeenCalledWith({
|
|
|
|
longUrl: 'https://long-domain.com/foo/bar',
|
|
|
|
tags: [ 'tag_foo', 'tag_bar' ],
|
|
|
|
customSlug: 'my-slug',
|
|
|
|
domain: 'example.com',
|
|
|
|
validSince: validSince.format(),
|
|
|
|
validUntil: validUntil.format(),
|
|
|
|
maxVisits: '20',
|
|
|
|
findIfExists: false,
|
|
|
|
shortCodeLength: 15,
|
2018-11-01 15:15:09 +03:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|