mirror of
https://github.com/shlinkio/shlink-web-client.git
synced 2025-01-09 17:57:26 +03:00
Created new Result component to display operation result messages consistently
This commit is contained in:
parent
c25355c531
commit
b211a29fc5
19 changed files with 110 additions and 72 deletions
|
@ -1,7 +1,7 @@
|
||||||
import { FC } from 'react';
|
import { FC } from 'react';
|
||||||
import { v4 as uuid } from 'uuid';
|
import { v4 as uuid } from 'uuid';
|
||||||
import { RouterProps } from 'react-router';
|
import { RouterProps } from 'react-router';
|
||||||
import classNames from 'classnames';
|
import { Result } from '../utils/Result';
|
||||||
import NoMenuLayout from '../common/NoMenuLayout';
|
import NoMenuLayout from '../common/NoMenuLayout';
|
||||||
import { StateFlagTimeout } from '../utils/helpers/hooks';
|
import { StateFlagTimeout } from '../utils/helpers/hooks';
|
||||||
import { ServerForm } from './helpers/ServerForm';
|
import { ServerForm } from './helpers/ServerForm';
|
||||||
|
@ -15,19 +15,11 @@ interface CreateServerProps extends RouterProps {
|
||||||
createServer: (server: ServerWithId) => void;
|
createServer: (server: ServerWithId) => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
const Result: FC<{ type: 'success' | 'error' }> = ({ children, type }) => (
|
const ImportResult = ({ type }: { type: 'error' | 'success' }) => (
|
||||||
<div className="row">
|
<Result type={type} textCentered>
|
||||||
<div className="col-md-10 offset-md-1">
|
{type === 'success' && 'Servers properly imported. You can now select one from the list :)'}
|
||||||
<div
|
{type === 'error' && 'The servers could not be imported. Make sure the format is correct.'}
|
||||||
className={classNames('p-2 mt-3 text-white text-center', {
|
</Result>
|
||||||
'bg-main': type === 'success',
|
|
||||||
'bg-danger': type === 'error',
|
|
||||||
})}
|
|
||||||
>
|
|
||||||
{children}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
);
|
);
|
||||||
|
|
||||||
const CreateServer = (ImportServersBtn: FC<ImportServersBtnProps>, useStateFlagTimeout: StateFlagTimeout) => (
|
const CreateServer = (ImportServersBtn: FC<ImportServersBtnProps>, useStateFlagTimeout: StateFlagTimeout) => (
|
||||||
|
@ -49,8 +41,12 @@ const CreateServer = (ImportServersBtn: FC<ImportServersBtnProps>, useStateFlagT
|
||||||
<button className="btn btn-outline-primary">Create server</button>
|
<button className="btn btn-outline-primary">Create server</button>
|
||||||
</ServerForm>
|
</ServerForm>
|
||||||
|
|
||||||
{serversImported && <Result type="success">Servers properly imported. You can now select one from the list :)</Result>}
|
{(serversImported || errorImporting) && (
|
||||||
{errorImporting && <Result type="error">The servers could not be imported. Make sure the format is correct.</Result>}
|
<div className="mt-4">
|
||||||
|
{serversImported && <ImportResult type="success" />}
|
||||||
|
{errorImporting && <ImportResult type="error" />}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
</NoMenuLayout>
|
</NoMenuLayout>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
|
@ -4,10 +4,11 @@ import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
|
||||||
import { isNil } from 'ramda';
|
import { isNil } from 'ramda';
|
||||||
import { useEffect } from 'react';
|
import { useEffect } from 'react';
|
||||||
import CopyToClipboard from 'react-copy-to-clipboard';
|
import CopyToClipboard from 'react-copy-to-clipboard';
|
||||||
import { Card, CardBody, Tooltip } from 'reactstrap';
|
import { Tooltip } from 'reactstrap';
|
||||||
import { ShortUrlCreation } from '../reducers/shortUrlCreation';
|
import { ShortUrlCreation } from '../reducers/shortUrlCreation';
|
||||||
import { StateFlagTimeout } from '../../utils/helpers/hooks';
|
import { StateFlagTimeout } from '../../utils/helpers/hooks';
|
||||||
import './CreateShortUrlResult.scss';
|
import './CreateShortUrlResult.scss';
|
||||||
|
import { Result } from '../../utils/Result';
|
||||||
|
|
||||||
export interface CreateShortUrlResultProps extends ShortUrlCreation {
|
export interface CreateShortUrlResultProps extends ShortUrlCreation {
|
||||||
resetCreateShortUrl: () => void;
|
resetCreateShortUrl: () => void;
|
||||||
|
@ -25,9 +26,10 @@ const CreateShortUrlResult = (useStateFlagTimeout: StateFlagTimeout) => (
|
||||||
|
|
||||||
if (error) {
|
if (error) {
|
||||||
return (
|
return (
|
||||||
<Card body color="danger" inverse className="bg-danger mt-3">
|
<Result type="error" className="mt-3">
|
||||||
|
{canBeClosed && <FontAwesomeIcon icon={closeIcon} className="float-right pointer" onClick={resetCreateShortUrl} />}
|
||||||
An error occurred while creating the URL :(
|
An error occurred while creating the URL :(
|
||||||
</Card>
|
</Result>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -38,8 +40,7 @@ const CreateShortUrlResult = (useStateFlagTimeout: StateFlagTimeout) => (
|
||||||
const { shortUrl } = result;
|
const { shortUrl } = result;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Card inverse className="bg-main mt-3">
|
<Result type="success" className="mt-3">
|
||||||
<CardBody>
|
|
||||||
{canBeClosed && <FontAwesomeIcon icon={closeIcon} className="float-right pointer" onClick={resetCreateShortUrl} />}
|
{canBeClosed && <FontAwesomeIcon icon={closeIcon} className="float-right pointer" onClick={resetCreateShortUrl} />}
|
||||||
<b>Great!</b> The short URL is <b>{shortUrl}</b>
|
<b>Great!</b> The short URL is <b>{shortUrl}</b>
|
||||||
|
|
||||||
|
@ -56,8 +57,7 @@ const CreateShortUrlResult = (useStateFlagTimeout: StateFlagTimeout) => (
|
||||||
<Tooltip placement="left" isOpen={showCopyTooltip} target="copyBtn">
|
<Tooltip placement="left" isOpen={showCopyTooltip} target="copyBtn">
|
||||||
Copied!
|
Copied!
|
||||||
</Tooltip>
|
</Tooltip>
|
||||||
</CardBody>
|
</Result>
|
||||||
</Card>
|
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -4,6 +4,7 @@ import { identity, pipe } from 'ramda';
|
||||||
import { ShortUrlDeletion } from '../reducers/shortUrlDeletion';
|
import { ShortUrlDeletion } from '../reducers/shortUrlDeletion';
|
||||||
import { ShortUrlModalProps } from '../data';
|
import { ShortUrlModalProps } from '../data';
|
||||||
import { handleEventPreventingDefault, OptionalString } from '../../utils/utils';
|
import { handleEventPreventingDefault, OptionalString } from '../../utils/utils';
|
||||||
|
import { Result } from '../../utils/Result';
|
||||||
|
|
||||||
const THRESHOLD_REACHED = 'INVALID_SHORTCODE_DELETION';
|
const THRESHOLD_REACHED = 'INVALID_SHORTCODE_DELETION';
|
||||||
|
|
||||||
|
@ -42,25 +43,26 @@ const DeleteShortUrlModal = (
|
||||||
<ModalBody>
|
<ModalBody>
|
||||||
<p><b className="text-danger">Caution!</b> You are about to delete a short URL.</p>
|
<p><b className="text-danger">Caution!</b> You are about to delete a short URL.</p>
|
||||||
<p>This action cannot be undone. Once you have deleted it, all the visits stats will be lost.</p>
|
<p>This action cannot be undone. Once you have deleted it, all the visits stats will be lost.</p>
|
||||||
|
<p>Write <b>{shortUrl.shortCode}</b> to confirm deletion.</p>
|
||||||
|
|
||||||
<input
|
<input
|
||||||
type="text"
|
type="text"
|
||||||
className="form-control"
|
className="form-control"
|
||||||
placeholder="Insert the short code of the URL"
|
placeholder={`Insert the short code (${shortUrl.shortCode})`}
|
||||||
value={inputValue}
|
value={inputValue}
|
||||||
onChange={(e) => setInputValue(e.target.value)}
|
onChange={(e) => setInputValue(e.target.value)}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
{hasThresholdError && (
|
{hasThresholdError && (
|
||||||
<div className="p-2 mt-2 bg-warning text-center">
|
<Result type="warning" textCentered small className="mt-2">
|
||||||
{errorData?.threshold && `This short URL has received more than ${errorData.threshold} visits, and therefore, it cannot be deleted.`}
|
{errorData?.threshold && `This short URL has received more than ${errorData.threshold} visits, and therefore, it cannot be deleted.`}
|
||||||
{!errorData?.threshold && 'This short URL has received too many visits, and therefore, it cannot be deleted.'}
|
{!errorData?.threshold && 'This short URL has received too many visits, and therefore, it cannot be deleted.'}
|
||||||
</div>
|
</Result>
|
||||||
)}
|
)}
|
||||||
{hasErrorOtherThanThreshold && (
|
{hasErrorOtherThanThreshold && (
|
||||||
<div className="p-2 mt-2 bg-danger text-white text-center">
|
<Result type="error" textCentered small className="mt-2">
|
||||||
Something went wrong while deleting the URL :(
|
Something went wrong while deleting the URL :(
|
||||||
</div>
|
</Result>
|
||||||
)}
|
)}
|
||||||
</ModalBody>
|
</ModalBody>
|
||||||
<ModalFooter>
|
<ModalFooter>
|
||||||
|
|
|
@ -10,6 +10,7 @@ import DateInput from '../../utils/DateInput';
|
||||||
import { formatIsoDate } from '../../utils/helpers/date';
|
import { formatIsoDate } from '../../utils/helpers/date';
|
||||||
import { ShortUrl, ShortUrlMeta, ShortUrlModalProps } from '../data';
|
import { ShortUrl, ShortUrlMeta, ShortUrlModalProps } from '../data';
|
||||||
import { handleEventPreventingDefault, Nullable, OptionalString } from '../../utils/utils';
|
import { handleEventPreventingDefault, Nullable, OptionalString } from '../../utils/utils';
|
||||||
|
import { Result } from '../../utils/Result';
|
||||||
|
|
||||||
interface EditMetaModalConnectProps extends ShortUrlModalProps {
|
interface EditMetaModalConnectProps extends ShortUrlModalProps {
|
||||||
shortUrlMeta: ShortUrlMetaEdition;
|
shortUrlMeta: ShortUrlMetaEdition;
|
||||||
|
@ -78,9 +79,9 @@ const EditMetaModal = (
|
||||||
/>
|
/>
|
||||||
</FormGroup>
|
</FormGroup>
|
||||||
{error && (
|
{error && (
|
||||||
<div className="p-2 mt-2 bg-danger text-white text-center">
|
<Result type="error" small textCentered className="mt-2">
|
||||||
Something went wrong while saving the metadata :(
|
Something went wrong while saving the metadata :(
|
||||||
</div>
|
</Result>
|
||||||
)}
|
)}
|
||||||
</ModalBody>
|
</ModalBody>
|
||||||
<ModalFooter>
|
<ModalFooter>
|
||||||
|
|
|
@ -4,6 +4,7 @@ import { ExternalLink } from 'react-external-link';
|
||||||
import { ShortUrlEdition } from '../reducers/shortUrlEdition';
|
import { ShortUrlEdition } from '../reducers/shortUrlEdition';
|
||||||
import { handleEventPreventingDefault, hasValue, OptionalString } from '../../utils/utils';
|
import { handleEventPreventingDefault, hasValue, OptionalString } from '../../utils/utils';
|
||||||
import { ShortUrlModalProps } from '../data';
|
import { ShortUrlModalProps } from '../data';
|
||||||
|
import { Result } from '../../utils/Result';
|
||||||
|
|
||||||
interface EditShortUrlModalProps extends ShortUrlModalProps {
|
interface EditShortUrlModalProps extends ShortUrlModalProps {
|
||||||
shortUrlEdition: ShortUrlEdition;
|
shortUrlEdition: ShortUrlEdition;
|
||||||
|
@ -34,9 +35,9 @@ const EditShortUrlModal = ({ isOpen, toggle, shortUrl, shortUrlEdition, editShor
|
||||||
/>
|
/>
|
||||||
</FormGroup>
|
</FormGroup>
|
||||||
{error && (
|
{error && (
|
||||||
<div className="p-2 mt-2 bg-danger text-white text-center">
|
<Result type="error" small textCentered className="mt-2">
|
||||||
Something went wrong while saving the long URL :(
|
Something went wrong while saving the long URL :(
|
||||||
</div>
|
</Result>
|
||||||
)}
|
)}
|
||||||
</ModalBody>
|
</ModalBody>
|
||||||
<ModalFooter>
|
<ModalFooter>
|
||||||
|
|
|
@ -5,6 +5,7 @@ import { ShortUrlTags } from '../reducers/shortUrlTags';
|
||||||
import { ShortUrlModalProps } from '../data';
|
import { ShortUrlModalProps } from '../data';
|
||||||
import { OptionalString } from '../../utils/utils';
|
import { OptionalString } from '../../utils/utils';
|
||||||
import { TagsSelectorProps } from '../../tags/helpers/TagsSelector';
|
import { TagsSelectorProps } from '../../tags/helpers/TagsSelector';
|
||||||
|
import { Result } from '../../utils/Result';
|
||||||
|
|
||||||
interface EditTagsModalProps extends ShortUrlModalProps {
|
interface EditTagsModalProps extends ShortUrlModalProps {
|
||||||
shortUrlTags: ShortUrlTags;
|
shortUrlTags: ShortUrlTags;
|
||||||
|
@ -32,9 +33,9 @@ const EditTagsModal = (TagsSelector: FC<TagsSelectorProps>) => (
|
||||||
<ModalBody>
|
<ModalBody>
|
||||||
<TagsSelector tags={selectedTags} onChange={setSelectedTags} />
|
<TagsSelector tags={selectedTags} onChange={setSelectedTags} />
|
||||||
{shortUrlTags.error && (
|
{shortUrlTags.error && (
|
||||||
<div className="p-2 mt-2 bg-danger text-white text-center">
|
<Result type="error" small textCentered className="mt-2">
|
||||||
Something went wrong while saving the tags :(
|
Something went wrong while saving the tags :(
|
||||||
</div>
|
</Result>
|
||||||
)}
|
)}
|
||||||
</ModalBody>
|
</ModalBody>
|
||||||
<ModalFooter>
|
<ModalFooter>
|
||||||
|
|
|
@ -4,6 +4,7 @@ import Message from '../utils/Message';
|
||||||
import SearchField from '../utils/SearchField';
|
import SearchField from '../utils/SearchField';
|
||||||
import { SelectedServer } from '../servers/data';
|
import { SelectedServer } from '../servers/data';
|
||||||
import { boundToMercureHub } from '../mercure/helpers/boundToMercureHub';
|
import { boundToMercureHub } from '../mercure/helpers/boundToMercureHub';
|
||||||
|
import { Result } from '../utils/Result';
|
||||||
import { TagsList as TagsListState } from './reducers/tagsList';
|
import { TagsList as TagsListState } from './reducers/tagsList';
|
||||||
import { TagCardProps } from './TagCard';
|
import { TagCardProps } from './TagCard';
|
||||||
|
|
||||||
|
@ -32,7 +33,7 @@ const TagsList = (TagCard: FC<TagCardProps>) => boundToMercureHub((
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tagsList.error) {
|
if (tagsList.error) {
|
||||||
return <div className="bg-danger p-2 text-white text-center">Error loading tags :(</div>;
|
return <Result type="error">Error loading tags :(</Result>;
|
||||||
}
|
}
|
||||||
|
|
||||||
const tagsCount = tagsList.filteredTags.length;
|
const tagsCount = tagsList.filteredTags.length;
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
import { Modal, ModalBody, ModalFooter, ModalHeader } from 'reactstrap';
|
import { Modal, ModalBody, ModalFooter, ModalHeader } from 'reactstrap';
|
||||||
import { TagDeletion } from '../reducers/tagDelete';
|
import { TagDeletion } from '../reducers/tagDelete';
|
||||||
import { TagModalProps } from '../data';
|
import { TagModalProps } from '../data';
|
||||||
|
import { Result } from '../../utils/Result';
|
||||||
|
|
||||||
interface DeleteTagConfirmModalProps extends TagModalProps {
|
interface DeleteTagConfirmModalProps extends TagModalProps {
|
||||||
deleteTag: (tag: string) => Promise<void>;
|
deleteTag: (tag: string) => Promise<void>;
|
||||||
|
@ -25,9 +26,9 @@ const DeleteTagConfirmModal = (
|
||||||
<ModalBody>
|
<ModalBody>
|
||||||
Are you sure you want to delete tag <b>{tag}</b>?
|
Are you sure you want to delete tag <b>{tag}</b>?
|
||||||
{tagDelete.error && (
|
{tagDelete.error && (
|
||||||
<div className="p-2 mt-2 bg-danger text-white text-center">
|
<Result type="error" small textCentered className="mt-2">
|
||||||
Something went wrong while deleting the tag :(
|
Something went wrong while deleting the tag :(
|
||||||
</div>
|
</Result>
|
||||||
)}
|
)}
|
||||||
</ModalBody>
|
</ModalBody>
|
||||||
<ModalFooter>
|
<ModalFooter>
|
||||||
|
|
|
@ -9,6 +9,7 @@ import ColorGenerator from '../../utils/services/ColorGenerator';
|
||||||
import { TagModalProps } from '../data';
|
import { TagModalProps } from '../data';
|
||||||
import { TagEdition } from '../reducers/tagEdit';
|
import { TagEdition } from '../reducers/tagEdit';
|
||||||
import './EditTagModal.scss';
|
import './EditTagModal.scss';
|
||||||
|
import { Result } from '../../utils/Result';
|
||||||
|
|
||||||
interface EditTagModalProps extends TagModalProps {
|
interface EditTagModalProps extends TagModalProps {
|
||||||
tagEdit: TagEdition;
|
tagEdit: TagEdition;
|
||||||
|
@ -55,9 +56,9 @@ const EditTagModal = ({ getColorForKey }: ColorGenerator) => (
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{tagEdit.error && (
|
{tagEdit.error && (
|
||||||
<div className="p-2 mt-2 bg-danger text-white text-center">
|
<Result type="error" small textCentered className="mt-2">
|
||||||
Something went wrong while editing the tag :(
|
Something went wrong while editing the tag :(
|
||||||
</div>
|
</Result>
|
||||||
)}
|
)}
|
||||||
</ModalBody>
|
</ModalBody>
|
||||||
<ModalFooter>
|
<ModalFooter>
|
||||||
|
|
30
src/utils/Result.tsx
Normal file
30
src/utils/Result.tsx
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
import { FC } from 'react';
|
||||||
|
import { Row } from 'reactstrap';
|
||||||
|
import classNames from 'classnames';
|
||||||
|
import { SimpleCard } from './SimpleCard';
|
||||||
|
|
||||||
|
interface ResultProps {
|
||||||
|
type: 'success' | 'error' | 'warning';
|
||||||
|
className?: string;
|
||||||
|
textCentered?: boolean;
|
||||||
|
small?: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
export const Result: FC<ResultProps> = ({ children, type, className, textCentered = false, small = false }) => (
|
||||||
|
<Row className={className}>
|
||||||
|
<div className={classNames({ 'col-md-10 offset-md-1': !small, 'col-12': small })}>
|
||||||
|
<SimpleCard
|
||||||
|
className={classNames({
|
||||||
|
'bg-main': type === 'success',
|
||||||
|
'bg-danger': type === 'error',
|
||||||
|
'bg-warning': type === 'warning',
|
||||||
|
'text-white': type !== 'warning',
|
||||||
|
'text-center': textCentered,
|
||||||
|
})}
|
||||||
|
bodyClassName={classNames({ 'p-2': small })}
|
||||||
|
>
|
||||||
|
{children}
|
||||||
|
</SimpleCard>
|
||||||
|
</div>
|
||||||
|
</Row>
|
||||||
|
);
|
|
@ -4,11 +4,12 @@ import { ReactNode } from 'react';
|
||||||
|
|
||||||
interface SimpleCardProps extends Omit<CardProps, 'title'> {
|
interface SimpleCardProps extends Omit<CardProps, 'title'> {
|
||||||
title?: ReactNode;
|
title?: ReactNode;
|
||||||
|
bodyClassName?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const SimpleCard = ({ title, children, ...rest }: SimpleCardProps) => (
|
export const SimpleCard = ({ title, children, bodyClassName, ...rest }: SimpleCardProps) => (
|
||||||
<Card {...rest}>
|
<Card {...rest}>
|
||||||
{title && <CardHeader>{title}</CardHeader>}
|
{title && <CardHeader>{title}</CardHeader>}
|
||||||
<CardBody>{children}</CardBody>
|
<CardBody className={bodyClassName}>{children}</CardBody>
|
||||||
</Card>
|
</Card>
|
||||||
);
|
);
|
||||||
|
|
|
@ -11,6 +11,7 @@ import Message from '../utils/Message';
|
||||||
import { formatIsoDate } from '../utils/helpers/date';
|
import { formatIsoDate } from '../utils/helpers/date';
|
||||||
import { ShlinkVisitsParams } from '../utils/services/types';
|
import { ShlinkVisitsParams } from '../utils/services/types';
|
||||||
import { DateInterval, DateRange, intervalToDateRange } from '../utils/dates/types';
|
import { DateInterval, DateRange, intervalToDateRange } from '../utils/dates/types';
|
||||||
|
import { Result } from '../utils/Result';
|
||||||
import SortableBarGraph from './helpers/SortableBarGraph';
|
import SortableBarGraph from './helpers/SortableBarGraph';
|
||||||
import GraphCard from './helpers/GraphCard';
|
import GraphCard from './helpers/GraphCard';
|
||||||
import LineChartCard from './helpers/LineChartCard';
|
import LineChartCard from './helpers/LineChartCard';
|
||||||
|
@ -130,11 +131,7 @@ const VisitsStats: FC<VisitsStatsProps> = ({ children, visitsInfo, getVisits, ca
|
||||||
}
|
}
|
||||||
|
|
||||||
if (error) {
|
if (error) {
|
||||||
return (
|
return <Result type="error">An error occurred while loading visits :(</Result>;
|
||||||
<Card body inverse color="danger">
|
|
||||||
An error occurred while loading visits :(
|
|
||||||
</Card>
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isEmpty(visits)) {
|
if (isEmpty(visits)) {
|
||||||
|
|
|
@ -30,12 +30,12 @@ describe('<CreateServer />', () => {
|
||||||
const wrapper = createWrapper();
|
const wrapper = createWrapper();
|
||||||
|
|
||||||
expect(wrapper.find(ServerForm)).toHaveLength(1);
|
expect(wrapper.find(ServerForm)).toHaveLength(1);
|
||||||
expect(wrapper.find('Result')).toHaveLength(0);
|
expect(wrapper.find('ImportResult')).toHaveLength(0);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('shows success message when imported is true', () => {
|
it('shows success message when imported is true', () => {
|
||||||
const wrapper = createWrapper(true);
|
const wrapper = createWrapper(true);
|
||||||
const result = wrapper.find('Result');
|
const result = wrapper.find('ImportResult');
|
||||||
|
|
||||||
expect(result).toHaveLength(1);
|
expect(result).toHaveLength(1);
|
||||||
expect(result.prop('type')).toEqual('success');
|
expect(result.prop('type')).toEqual('success');
|
||||||
|
@ -43,7 +43,7 @@ describe('<CreateServer />', () => {
|
||||||
|
|
||||||
it('shows error message when import failed', () => {
|
it('shows error message when import failed', () => {
|
||||||
const wrapper = createWrapper(false, true);
|
const wrapper = createWrapper(false, true);
|
||||||
const result = wrapper.find('Result');
|
const result = wrapper.find('ImportResult');
|
||||||
|
|
||||||
expect(result).toHaveLength(1);
|
expect(result).toHaveLength(1);
|
||||||
expect(result.prop('type')).toEqual('error');
|
expect(result.prop('type')).toEqual('error');
|
||||||
|
|
|
@ -5,6 +5,7 @@ import { Mock } from 'ts-mockery';
|
||||||
import createCreateShortUrlResult from '../../../src/short-urls/helpers/CreateShortUrlResult';
|
import createCreateShortUrlResult from '../../../src/short-urls/helpers/CreateShortUrlResult';
|
||||||
import { ShortUrl } from '../../../src/short-urls/data';
|
import { ShortUrl } from '../../../src/short-urls/data';
|
||||||
import { StateFlagTimeout } from '../../../src/utils/helpers/hooks';
|
import { StateFlagTimeout } from '../../../src/utils/helpers/hooks';
|
||||||
|
import { Result } from '../../../src/utils/Result';
|
||||||
|
|
||||||
describe('<CreateShortUrlResult />', () => {
|
describe('<CreateShortUrlResult />', () => {
|
||||||
let wrapper: ShallowWrapper;
|
let wrapper: ShallowWrapper;
|
||||||
|
@ -24,7 +25,7 @@ describe('<CreateShortUrlResult />', () => {
|
||||||
|
|
||||||
it('renders an error when error is true', () => {
|
it('renders an error when error is true', () => {
|
||||||
const wrapper = createWrapper(Mock.all<ShortUrl>(), 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).toHaveLength(1);
|
||||||
expect(errorCard.html()).toContain('An error occurred while creating the URL :(');
|
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 { ShortUrl } from '../../../src/short-urls/data';
|
||||||
import { ShortUrlDeletion } from '../../../src/short-urls/reducers/shortUrlDeletion';
|
import { ShortUrlDeletion } from '../../../src/short-urls/reducers/shortUrlDeletion';
|
||||||
import { ProblemDetailsError } from '../../../src/utils/services/types';
|
import { ProblemDetailsError } from '../../../src/utils/services/types';
|
||||||
|
import { Result } from '../../../src/utils/Result';
|
||||||
|
|
||||||
describe('<DeleteShortUrlModal />', () => {
|
describe('<DeleteShortUrlModal />', () => {
|
||||||
let wrapper: ShallowWrapper;
|
let wrapper: ShallowWrapper;
|
||||||
|
@ -48,7 +49,7 @@ describe('<DeleteShortUrlModal />', () => {
|
||||||
shortCode: 'abc123',
|
shortCode: 'abc123',
|
||||||
errorData: Mock.of<ProblemDetailsError>(errorData),
|
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).toHaveLength(1);
|
||||||
expect(warning.html()).toContain(expectedMessage);
|
expect(warning.html()).toContain(expectedMessage);
|
||||||
|
@ -61,7 +62,7 @@ describe('<DeleteShortUrlModal />', () => {
|
||||||
shortCode: 'abc123',
|
shortCode: 'abc123',
|
||||||
errorData: Mock.of<ProblemDetailsError>({ type: 'OTHER_ERROR' }),
|
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).toHaveLength(1);
|
||||||
expect(error.html()).toContain('Something went wrong while deleting the URL :(');
|
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 EditMetaModal from '../../../src/short-urls/helpers/EditMetaModal';
|
||||||
import { ShortUrl } from '../../../src/short-urls/data';
|
import { ShortUrl } from '../../../src/short-urls/data';
|
||||||
import { ShortUrlMetaEdition } from '../../../src/short-urls/reducers/shortUrlMeta';
|
import { ShortUrlMetaEdition } from '../../../src/short-urls/reducers/shortUrlMeta';
|
||||||
|
import { Result } from '../../../src/utils/Result';
|
||||||
|
|
||||||
describe('<EditMetaModal />', () => {
|
describe('<EditMetaModal />', () => {
|
||||||
let wrapper: ShallowWrapper;
|
let wrapper: ShallowWrapper;
|
||||||
|
@ -30,7 +31,7 @@ describe('<EditMetaModal />', () => {
|
||||||
|
|
||||||
it('properly renders form with components', () => {
|
it('properly renders form with components', () => {
|
||||||
const wrapper = createWrapper({ saving: false, error: false });
|
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 form = wrapper.find('form');
|
||||||
const formGroup = form.find(FormGroup);
|
const formGroup = form.find(FormGroup);
|
||||||
|
|
||||||
|
@ -52,7 +53,7 @@ describe('<EditMetaModal />', () => {
|
||||||
|
|
||||||
it('renders error message on error', () => {
|
it('renders error message on error', () => {
|
||||||
const wrapper = createWrapper({ saving: false, error: true });
|
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);
|
expect(error).toHaveLength(1);
|
||||||
});
|
});
|
||||||
|
|
|
@ -4,6 +4,7 @@ import { Mock } from 'ts-mockery';
|
||||||
import EditShortUrlModal from '../../../src/short-urls/helpers/EditShortUrlModal';
|
import EditShortUrlModal from '../../../src/short-urls/helpers/EditShortUrlModal';
|
||||||
import { ShortUrl } from '../../../src/short-urls/data';
|
import { ShortUrl } from '../../../src/short-urls/data';
|
||||||
import { ShortUrlEdition } from '../../../src/short-urls/reducers/shortUrlEdition';
|
import { ShortUrlEdition } from '../../../src/short-urls/reducers/shortUrlEdition';
|
||||||
|
import { Result } from '../../../src/utils/Result';
|
||||||
|
|
||||||
describe('<EditShortUrlModal />', () => {
|
describe('<EditShortUrlModal />', () => {
|
||||||
let wrapper: ShallowWrapper;
|
let wrapper: ShallowWrapper;
|
||||||
|
@ -31,7 +32,7 @@ describe('<EditShortUrlModal />', () => {
|
||||||
[ true, 1 ],
|
[ true, 1 ],
|
||||||
])('properly renders form with expected components', (error, expectedErrorLength) => {
|
])('properly renders form with expected components', (error, expectedErrorLength) => {
|
||||||
const wrapper = createWrapper({}, { saving: false, error });
|
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 form = wrapper.find('form');
|
||||||
const formGroup = form.find(FormGroup);
|
const formGroup = form.find(FormGroup);
|
||||||
|
|
||||||
|
|
|
@ -7,6 +7,7 @@ import SearchField from '../../src/utils/SearchField';
|
||||||
import { rangeOf } from '../../src/utils/utils';
|
import { rangeOf } from '../../src/utils/utils';
|
||||||
import { TagsList } from '../../src/tags/reducers/tagsList';
|
import { TagsList } from '../../src/tags/reducers/tagsList';
|
||||||
import { MercureBoundProps } from '../../src/mercure/helpers/boundToMercureHub';
|
import { MercureBoundProps } from '../../src/mercure/helpers/boundToMercureHub';
|
||||||
|
import { Result } from '../../src/utils/Result';
|
||||||
|
|
||||||
describe('<TagsList />', () => {
|
describe('<TagsList />', () => {
|
||||||
let wrapper: ShallowWrapper;
|
let wrapper: ShallowWrapper;
|
||||||
|
@ -41,7 +42,7 @@ describe('<TagsList />', () => {
|
||||||
|
|
||||||
it('shows an error when tags failed to be loaded', () => {
|
it('shows an error when tags failed to be loaded', () => {
|
||||||
const wrapper = createWrapper({ error: true });
|
const wrapper = createWrapper({ error: true });
|
||||||
const errorMsg = wrapper.find('.bg-danger');
|
const errorMsg = wrapper.find(Result).filterWhere((result) => result.prop('type') === 'error');
|
||||||
|
|
||||||
expect(errorMsg).toHaveLength(1);
|
expect(errorMsg).toHaveLength(1);
|
||||||
expect(errorMsg.html()).toContain('Error loading tags :(');
|
expect(errorMsg.html()).toContain('Error loading tags :(');
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import { shallow, ShallowWrapper } from 'enzyme';
|
import { shallow, ShallowWrapper } from 'enzyme';
|
||||||
import { Card, Progress } from 'reactstrap';
|
import { Progress } from 'reactstrap';
|
||||||
import { Mock } from 'ts-mockery';
|
import { Mock } from 'ts-mockery';
|
||||||
import VisitStats from '../../src/visits/VisitsStats';
|
import VisitStats from '../../src/visits/VisitsStats';
|
||||||
import Message from '../../src/utils/Message';
|
import Message from '../../src/utils/Message';
|
||||||
|
@ -8,6 +8,7 @@ import SortableBarGraph from '../../src/visits/helpers/SortableBarGraph';
|
||||||
import { Visit, VisitsInfo } from '../../src/visits/types';
|
import { Visit, VisitsInfo } from '../../src/visits/types';
|
||||||
import LineChartCard from '../../src/visits/helpers/LineChartCard';
|
import LineChartCard from '../../src/visits/helpers/LineChartCard';
|
||||||
import VisitsTable from '../../src/visits/VisitsTable';
|
import VisitsTable from '../../src/visits/VisitsTable';
|
||||||
|
import { Result } from '../../src/utils/Result';
|
||||||
|
|
||||||
describe('<VisitStats />', () => {
|
describe('<VisitStats />', () => {
|
||||||
const visits = [ Mock.all<Visit>(), Mock.all<Visit>(), Mock.all<Visit>() ];
|
const visits = [ Mock.all<Visit>(), Mock.all<Visit>(), Mock.all<Visit>() ];
|
||||||
|
@ -53,7 +54,7 @@ describe('<VisitStats />', () => {
|
||||||
|
|
||||||
it('renders an error message when visits could not be loaded', () => {
|
it('renders an error message when visits could not be loaded', () => {
|
||||||
const wrapper = createComponent({ loading: false, error: true, visits: [] });
|
const wrapper = createComponent({ loading: false, error: true, visits: [] });
|
||||||
const errorMessage = wrapper.find(Card);
|
const errorMessage = wrapper.find(Result).filterWhere((result) => result.prop('type') === 'error');
|
||||||
|
|
||||||
expect(errorMessage).toHaveLength(1);
|
expect(errorMessage).toHaveLength(1);
|
||||||
expect(errorMessage.html()).toContain('An error occurred while loading visits :(');
|
expect(errorMessage.html()).toContain('An error occurred while loading visits :(');
|
||||||
|
|
Loading…
Reference in a new issue