mirror of
https://github.com/shlinkio/shlink-web-client.git
synced 2025-01-10 02:07:26 +03:00
Fixed missing initial values when editing one domain redirects
This commit is contained in:
parent
0804322a9f
commit
06f4cff97e
2 changed files with 23 additions and 5 deletions
|
@ -25,9 +25,11 @@ const FormGroup: FC<FormGroupContainerProps & { isLast?: boolean }> = ({ isLast,
|
||||||
export const EditDomainRedirectsModal: FC<EditDomainRedirectsModalProps> = (
|
export const EditDomainRedirectsModal: FC<EditDomainRedirectsModalProps> = (
|
||||||
{ isOpen, toggle, domain, editDomainRedirects },
|
{ isOpen, toggle, domain, editDomainRedirects },
|
||||||
) => {
|
) => {
|
||||||
const [ baseUrlRedirect, setBaseUrlRedirect ] = useState('');
|
const [ baseUrlRedirect, setBaseUrlRedirect ] = useState(domain.redirects?.baseUrlRedirect ?? '');
|
||||||
const [ regular404Redirect, setRegular404Redirect ] = useState('');
|
const [ regular404Redirect, setRegular404Redirect ] = useState(domain.redirects?.regular404Redirect ?? '');
|
||||||
const [ invalidShortUrlRedirect, setInvalidShortUrlRedirect ] = useState('');
|
const [ invalidShortUrlRedirect, setInvalidShortUrlRedirect ] = useState(
|
||||||
|
domain.redirects?.invalidShortUrlRedirect ?? '',
|
||||||
|
);
|
||||||
const handleSubmit = handleEventPreventingDefault(async () => editDomainRedirects(domain.domain, {
|
const handleSubmit = handleEventPreventingDefault(async () => editDomainRedirects(domain.domain, {
|
||||||
baseUrlRedirect: nonEmptyValueOrNull(baseUrlRedirect),
|
baseUrlRedirect: nonEmptyValueOrNull(baseUrlRedirect),
|
||||||
regular404Redirect: nonEmptyValueOrNull(regular404Redirect),
|
regular404Redirect: nonEmptyValueOrNull(regular404Redirect),
|
||||||
|
|
|
@ -9,7 +9,12 @@ describe('<EditDomainRedirectsModal />', () => {
|
||||||
let wrapper: ShallowWrapper;
|
let wrapper: ShallowWrapper;
|
||||||
const editDomainRedirects = jest.fn().mockResolvedValue(undefined);
|
const editDomainRedirects = jest.fn().mockResolvedValue(undefined);
|
||||||
const toggle = jest.fn();
|
const toggle = jest.fn();
|
||||||
const domain = Mock.of<ShlinkDomain>({ domain: 'foo.com' });
|
const domain = Mock.of<ShlinkDomain>({
|
||||||
|
domain: 'foo.com',
|
||||||
|
redirects: {
|
||||||
|
baseUrlRedirect: 'baz',
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
wrapper = shallow(
|
wrapper = shallow(
|
||||||
|
@ -51,7 +56,7 @@ describe('<EditDomainRedirectsModal />', () => {
|
||||||
|
|
||||||
wrapper.find('form').simulate('submit', { preventDefault: jest.fn() });
|
wrapper.find('form').simulate('submit', { preventDefault: jest.fn() });
|
||||||
expect(editDomainRedirects).toHaveBeenCalledWith('foo.com', {
|
expect(editDomainRedirects).toHaveBeenCalledWith('foo.com', {
|
||||||
baseUrlRedirect: null,
|
baseUrlRedirect: 'baz',
|
||||||
regular404Redirect: null,
|
regular404Redirect: null,
|
||||||
invalidShortUrlRedirect: null,
|
invalidShortUrlRedirect: null,
|
||||||
});
|
});
|
||||||
|
@ -75,5 +80,16 @@ describe('<EditDomainRedirectsModal />', () => {
|
||||||
regular404Redirect: 'new_regular_404',
|
regular404Redirect: 'new_regular_404',
|
||||||
invalidShortUrlRedirect: null,
|
invalidShortUrlRedirect: null,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
formGroups.at(0).simulate('change', '');
|
||||||
|
formGroups.at(1).simulate('change', '');
|
||||||
|
formGroups.at(2).simulate('change', '');
|
||||||
|
|
||||||
|
wrapper.find('form').simulate('submit', { preventDefault: jest.fn() });
|
||||||
|
expect(editDomainRedirects).toHaveBeenCalledWith('foo.com', {
|
||||||
|
baseUrlRedirect: null,
|
||||||
|
regular404Redirect: null,
|
||||||
|
invalidShortUrlRedirect: null,
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue