mirror of
https://github.com/shlinkio/shlink-web-client.git
synced 2025-01-09 01:37:24 +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> = (
|
||||
{ isOpen, toggle, domain, editDomainRedirects },
|
||||
) => {
|
||||
const [ baseUrlRedirect, setBaseUrlRedirect ] = useState('');
|
||||
const [ regular404Redirect, setRegular404Redirect ] = useState('');
|
||||
const [ invalidShortUrlRedirect, setInvalidShortUrlRedirect ] = useState('');
|
||||
const [ baseUrlRedirect, setBaseUrlRedirect ] = useState(domain.redirects?.baseUrlRedirect ?? '');
|
||||
const [ regular404Redirect, setRegular404Redirect ] = useState(domain.redirects?.regular404Redirect ?? '');
|
||||
const [ invalidShortUrlRedirect, setInvalidShortUrlRedirect ] = useState(
|
||||
domain.redirects?.invalidShortUrlRedirect ?? '',
|
||||
);
|
||||
const handleSubmit = handleEventPreventingDefault(async () => editDomainRedirects(domain.domain, {
|
||||
baseUrlRedirect: nonEmptyValueOrNull(baseUrlRedirect),
|
||||
regular404Redirect: nonEmptyValueOrNull(regular404Redirect),
|
||||
|
|
|
@ -9,7 +9,12 @@ describe('<EditDomainRedirectsModal />', () => {
|
|||
let wrapper: ShallowWrapper;
|
||||
const editDomainRedirects = jest.fn().mockResolvedValue(undefined);
|
||||
const toggle = jest.fn();
|
||||
const domain = Mock.of<ShlinkDomain>({ domain: 'foo.com' });
|
||||
const domain = Mock.of<ShlinkDomain>({
|
||||
domain: 'foo.com',
|
||||
redirects: {
|
||||
baseUrlRedirect: 'baz',
|
||||
},
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
wrapper = shallow(
|
||||
|
@ -51,7 +56,7 @@ describe('<EditDomainRedirectsModal />', () => {
|
|||
|
||||
wrapper.find('form').simulate('submit', { preventDefault: jest.fn() });
|
||||
expect(editDomainRedirects).toHaveBeenCalledWith('foo.com', {
|
||||
baseUrlRedirect: null,
|
||||
baseUrlRedirect: 'baz',
|
||||
regular404Redirect: null,
|
||||
invalidShortUrlRedirect: null,
|
||||
});
|
||||
|
@ -75,5 +80,16 @@ describe('<EditDomainRedirectsModal />', () => {
|
|||
regular404Redirect: 'new_regular_404',
|
||||
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