From 93f33b62185b9d62c0835b38347d9fb2af230bb1 Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Fri, 31 Jan 2020 20:04:03 +0100 Subject: [PATCH 1/4] Fixed some tests after not injecting a component --- test/short-urls/CreateShortUrl.test.js | 2 +- test/short-urls/SearchBar.test.js | 2 +- test/short-urls/helpers/ShortUrlsRowMenu.test.js | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/test/short-urls/CreateShortUrl.test.js b/test/short-urls/CreateShortUrl.test.js index 6d281b7c..aac1172d 100644 --- a/test/short-urls/CreateShortUrl.test.js +++ b/test/short-urls/CreateShortUrl.test.js @@ -14,7 +14,7 @@ describe('', () => { const createShortUrl = jest.fn(); beforeEach(() => { - const CreateShortUrl = createShortUrlsCreator(TagsSelector, () => ''); + const CreateShortUrl = createShortUrlsCreator(TagsSelector, () => '', () => ''); wrapper = shallow( diff --git a/test/short-urls/SearchBar.test.js b/test/short-urls/SearchBar.test.js index 423af3cd..2d7ef01c 100644 --- a/test/short-urls/SearchBar.test.js +++ b/test/short-urls/SearchBar.test.js @@ -9,7 +9,7 @@ import DateRangeRow from '../../src/utils/DateRangeRow'; describe('', () => { let wrapper; const listShortUrlsMock = jest.fn(); - const SearchBar = searchBarCreator({}); + const SearchBar = searchBarCreator({}, () => ''); afterEach(() => { listShortUrlsMock.mockReset(); diff --git a/test/short-urls/helpers/ShortUrlsRowMenu.test.js b/test/short-urls/helpers/ShortUrlsRowMenu.test.js index 38d1db67..cfcee90d 100644 --- a/test/short-urls/helpers/ShortUrlsRowMenu.test.js +++ b/test/short-urls/helpers/ShortUrlsRowMenu.test.js @@ -17,7 +17,7 @@ describe('', () => { shortUrl: 'https://doma.in/abc123', }; const createWrapper = () => { - const ShortUrlsRowMenu = createShortUrlsRowMenu(DeleteShortUrlModal, EditTagsModal, EditMetaModal); + const ShortUrlsRowMenu = createShortUrlsRowMenu(DeleteShortUrlModal, EditTagsModal, EditMetaModal, () => ''); wrapper = shallow( Date: Fri, 31 Jan 2020 20:06:28 +0100 Subject: [PATCH 2/4] Simplified EditTagsModal component and shortUrlTags reducer --- src/short-urls/helpers/EditTagsModal.js | 27 +++++-------------- src/short-urls/reducers/shortUrlTags.js | 13 +++------ src/short-urls/services/provideServices.js | 8 ++---- test/short-urls/helpers/EditTagsModal.test.js | 25 +---------------- test/short-urls/reducers/shortUrlTags.test.js | 16 +++-------- 5 files changed, 16 insertions(+), 73 deletions(-) diff --git a/src/short-urls/helpers/EditTagsModal.js b/src/short-urls/helpers/EditTagsModal.js index 8ea99935..141b66ff 100644 --- a/src/short-urls/helpers/EditTagsModal.js +++ b/src/short-urls/helpers/EditTagsModal.js @@ -2,6 +2,7 @@ import React from 'react'; import { Modal, ModalBody, ModalFooter, ModalHeader } from 'reactstrap'; import PropTypes from 'prop-types'; import { ExternalLink } from 'react-external-link'; +import { pipe } from 'ramda'; import { shortUrlTagsType } from '../reducers/shortUrlTags'; import { shortUrlType } from '../reducers/shortUrlsList'; @@ -12,7 +13,6 @@ const EditTagsModal = (TagsSelector) => class EditTagsModal extends React.Compon shortUrl: shortUrlType.isRequired, shortUrlTags: shortUrlTagsType, editShortUrlTags: PropTypes.func, - shortUrlTagsEdited: PropTypes.func, resetShortUrlsTags: PropTypes.func, }; @@ -20,28 +20,14 @@ const EditTagsModal = (TagsSelector) => class EditTagsModal extends React.Compon const { editShortUrlTags, shortUrl, toggle } = this.props; editShortUrlTags(shortUrl.shortCode, this.state.tags) - .then(() => { - this.tagsSaved = true; - toggle(); - }) + .then(toggle) .catch(() => {}); }; - refreshShortUrls = () => { - if (!this.tagsSaved) { - return; - } - - const { shortUrlTagsEdited, shortUrl, shortUrlTags } = this.props; - const { tags } = shortUrlTags; - - shortUrlTagsEdited(shortUrl.shortCode, tags); - }; componentDidMount() { const { resetShortUrlsTags } = this.props; resetShortUrlsTags(); - this.tagsSaved = false; } constructor(props) { @@ -50,12 +36,13 @@ const EditTagsModal = (TagsSelector) => class EditTagsModal extends React.Compon } render() { - const { isOpen, toggle, shortUrl, shortUrlTags } = this.props; + const { isOpen, toggle, shortUrl, shortUrlTags, resetShortUrlsTags } = this.props; const url = shortUrl && (shortUrl.shortUrl || ''); + const close = pipe(resetShortUrlsTags, toggle); return ( - this.refreshShortUrls()}> - + + Edit tags for @@ -67,7 +54,7 @@ const EditTagsModal = (TagsSelector) => class EditTagsModal extends React.Compon )} - + +