mirror of
https://github.com/shlinkio/shlink-web-client.git
synced 2026-03-10 09:33:51 +00:00
Created new Result component to display operation result messages consistently
This commit is contained in:
@@ -5,6 +5,7 @@ import { Mock } from 'ts-mockery';
|
||||
import createCreateShortUrlResult from '../../../src/short-urls/helpers/CreateShortUrlResult';
|
||||
import { ShortUrl } from '../../../src/short-urls/data';
|
||||
import { StateFlagTimeout } from '../../../src/utils/helpers/hooks';
|
||||
import { Result } from '../../../src/utils/Result';
|
||||
|
||||
describe('<CreateShortUrlResult />', () => {
|
||||
let wrapper: ShallowWrapper;
|
||||
@@ -24,7 +25,7 @@ describe('<CreateShortUrlResult />', () => {
|
||||
|
||||
it('renders an error when error is true', () => {
|
||||
const wrapper = createWrapper(Mock.all<ShortUrl>(), true);
|
||||
const errorCard = wrapper.find('.bg-danger');
|
||||
const errorCard = wrapper.find(Result).filterWhere((result) => result.prop('type') === 'error');
|
||||
|
||||
expect(errorCard).toHaveLength(1);
|
||||
expect(errorCard.html()).toContain('An error occurred while creating the URL :(');
|
||||
|
||||
@@ -5,6 +5,7 @@ import DeleteShortUrlModal from '../../../src/short-urls/helpers/DeleteShortUrlM
|
||||
import { ShortUrl } from '../../../src/short-urls/data';
|
||||
import { ShortUrlDeletion } from '../../../src/short-urls/reducers/shortUrlDeletion';
|
||||
import { ProblemDetailsError } from '../../../src/utils/services/types';
|
||||
import { Result } from '../../../src/utils/Result';
|
||||
|
||||
describe('<DeleteShortUrlModal />', () => {
|
||||
let wrapper: ShallowWrapper;
|
||||
@@ -48,7 +49,7 @@ describe('<DeleteShortUrlModal />', () => {
|
||||
shortCode: 'abc123',
|
||||
errorData: Mock.of<ProblemDetailsError>(errorData),
|
||||
});
|
||||
const warning = wrapper.find('.bg-warning');
|
||||
const warning = wrapper.find(Result).filterWhere((result) => result.prop('type') === 'warning');
|
||||
|
||||
expect(warning).toHaveLength(1);
|
||||
expect(warning.html()).toContain(expectedMessage);
|
||||
@@ -61,7 +62,7 @@ describe('<DeleteShortUrlModal />', () => {
|
||||
shortCode: 'abc123',
|
||||
errorData: Mock.of<ProblemDetailsError>({ type: 'OTHER_ERROR' }),
|
||||
});
|
||||
const error = wrapper.find('.bg-danger');
|
||||
const error = wrapper.find(Result).filterWhere((result) => result.prop('type') === 'error');
|
||||
|
||||
expect(error).toHaveLength(1);
|
||||
expect(error.html()).toContain('Something went wrong while deleting the URL :(');
|
||||
|
||||
@@ -4,6 +4,7 @@ import { Mock } from 'ts-mockery';
|
||||
import EditMetaModal from '../../../src/short-urls/helpers/EditMetaModal';
|
||||
import { ShortUrl } from '../../../src/short-urls/data';
|
||||
import { ShortUrlMetaEdition } from '../../../src/short-urls/reducers/shortUrlMeta';
|
||||
import { Result } from '../../../src/utils/Result';
|
||||
|
||||
describe('<EditMetaModal />', () => {
|
||||
let wrapper: ShallowWrapper;
|
||||
@@ -30,7 +31,7 @@ describe('<EditMetaModal />', () => {
|
||||
|
||||
it('properly renders form with components', () => {
|
||||
const wrapper = createWrapper({ saving: false, error: false });
|
||||
const error = wrapper.find('.bg-danger');
|
||||
const error = wrapper.find(Result).filterWhere((result) => result.prop('type') === 'error');
|
||||
const form = wrapper.find('form');
|
||||
const formGroup = form.find(FormGroup);
|
||||
|
||||
@@ -52,7 +53,7 @@ describe('<EditMetaModal />', () => {
|
||||
|
||||
it('renders error message on error', () => {
|
||||
const wrapper = createWrapper({ saving: false, error: true });
|
||||
const error = wrapper.find('.bg-danger');
|
||||
const error = wrapper.find(Result).filterWhere((result) => result.prop('type') === 'error');
|
||||
|
||||
expect(error).toHaveLength(1);
|
||||
});
|
||||
|
||||
@@ -4,6 +4,7 @@ import { Mock } from 'ts-mockery';
|
||||
import EditShortUrlModal from '../../../src/short-urls/helpers/EditShortUrlModal';
|
||||
import { ShortUrl } from '../../../src/short-urls/data';
|
||||
import { ShortUrlEdition } from '../../../src/short-urls/reducers/shortUrlEdition';
|
||||
import { Result } from '../../../src/utils/Result';
|
||||
|
||||
describe('<EditShortUrlModal />', () => {
|
||||
let wrapper: ShallowWrapper;
|
||||
@@ -31,7 +32,7 @@ describe('<EditShortUrlModal />', () => {
|
||||
[ true, 1 ],
|
||||
])('properly renders form with expected components', (error, expectedErrorLength) => {
|
||||
const wrapper = createWrapper({}, { saving: false, error });
|
||||
const errorElement = wrapper.find('.bg-danger');
|
||||
const errorElement = wrapper.find(Result).filterWhere((result) => result.prop('type') === 'error');
|
||||
const form = wrapper.find('form');
|
||||
const formGroup = form.find(FormGroup);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user