From ad167d2d029fffe9e29b98c1aa6f1aeded026863 Mon Sep 17 00:00:00 2001 From: Franek Date: Sun, 6 Jun 2021 23:10:54 +0200 Subject: [PATCH] Refactor the code --- front-end/src/api/apiCalls.spec.js | 20 +++------------- front-end/src/components/ButtonWithSpinner.js | 1 - .../src/components/DeleteAccountModal.js | 1 - .../src/components/InputWithValidation.js | 3 ++- front-end/src/components/TopBar.spec.js | 3 ++- .../notice-form/ContactInformation.js | 1 - front-end/src/containers/App.spec.js | 15 ++---------- front-end/src/pages/CreateNoticePage.js | 2 +- front-end/src/pages/ErrorPage.spec.js | 3 ++- front-end/src/pages/HomePage.spec.js | 3 ++- front-end/src/pages/NoticePage.js | 24 +++++++++---------- front-end/src/pages/RegistrationPage.js | 1 + front-end/src/pages/RegistrationPage.spec.js | 3 ++- front-end/src/pages/UserProfilePage.spec.js | 3 ++- .../src/pages/VerificationEmailAddressPage.js | 2 +- 15 files changed, 32 insertions(+), 53 deletions(-) diff --git a/front-end/src/api/apiCalls.spec.js b/front-end/src/api/apiCalls.spec.js index f2f332c..8e56f18 100644 --- a/front-end/src/api/apiCalls.spec.js +++ b/front-end/src/api/apiCalls.spec.js @@ -71,21 +71,6 @@ describe('apiCalls', () => { }); }); - // describe('getNotices', () => { - // it('calls /api/1.0/notices?sort=createdAt,desc', () => { - // // given - // const username = 'username123'; - // const mockGetNotices = jest.fn(); - // axios.get = mockGetNotices; - // // when - // apiCalls.getNotices(); - // // then - // const calledPath = mockGetNotices.mock.calls[0][0]; - // expect(calledPath).toBe('/api/1.0/notices?sort=createdAt,desc'); - // }); - // }); - - describe('getNotice', () => { it('calls /api/1.0/notices/1 when 1 is provided for the function', () => { // given @@ -119,7 +104,7 @@ describe('apiCalls', () => { const mockPutNotice = jest.fn(); axios.put = mockPutNotice; // when - apiCalls.putNotice(1,{}); + apiCalls.putNotice(1, {}); // then const calledPath = mockPutNotice.mock.calls[0][0]; expect(calledPath).toBe('/api/1.0/notices/1'); @@ -140,4 +125,5 @@ describe('apiCalls', () => { }); }); -console.error = () => {} \ No newline at end of file +console.error = () => { +} \ No newline at end of file diff --git a/front-end/src/components/ButtonWithSpinner.js b/front-end/src/components/ButtonWithSpinner.js index fe77077..d4b6a03 100644 --- a/front-end/src/components/ButtonWithSpinner.js +++ b/front-end/src/components/ButtonWithSpinner.js @@ -15,7 +15,6 @@ const ButtonWithSpinner = props => { Loading... } - ); }; diff --git a/front-end/src/components/DeleteAccountModal.js b/front-end/src/components/DeleteAccountModal.js index 1109d84..d80025b 100644 --- a/front-end/src/components/DeleteAccountModal.js +++ b/front-end/src/components/DeleteAccountModal.js @@ -17,7 +17,6 @@ class DeleteAccountModal extends Component { successInfo: undefined } - onCancel = () => { this.setState({ ongoingApiCall: false, diff --git a/front-end/src/components/InputWithValidation.js b/front-end/src/components/InputWithValidation.js index 9cd3897..bc5b6a1 100644 --- a/front-end/src/components/InputWithValidation.js +++ b/front-end/src/components/InputWithValidation.js @@ -37,7 +37,8 @@ const InputWithValidation = props => { } InputWithValidation.defaultProps = { - onChange: () => {} + onChange: () => { + } }; export default InputWithValidation; \ No newline at end of file diff --git a/front-end/src/components/TopBar.spec.js b/front-end/src/components/TopBar.spec.js index 416ffe9..3a3f533 100644 --- a/front-end/src/components/TopBar.spec.js +++ b/front-end/src/components/TopBar.spec.js @@ -90,4 +90,5 @@ describe('TopBar', () => { }); }); -console.error = () => {} \ No newline at end of file +console.error = () => { +} \ No newline at end of file diff --git a/front-end/src/components/notice-form/ContactInformation.js b/front-end/src/components/notice-form/ContactInformation.js index dee9662..d9a2354 100644 --- a/front-end/src/components/notice-form/ContactInformation.js +++ b/front-end/src/components/notice-form/ContactInformation.js @@ -17,5 +17,4 @@ const ContactInformation = ({email}) => { ); }; - export default ContactInformation; diff --git a/front-end/src/containers/App.spec.js b/front-end/src/containers/App.spec.js index 0cc0ab2..bdf4039 100644 --- a/front-end/src/containers/App.spec.js +++ b/front-end/src/containers/App.spec.js @@ -45,16 +45,6 @@ const setUser1LoggedInStorage = () => { }; describe('App', () => { - // it('displays homepage when url is /', () => { - // // given - // const url = '/'; - // // when - // const {queryByTestId} = renderAppComponent(url); - // // then - // const homeDiv = queryByTestId('homepage'); - // expect(homeDiv).toBeInTheDocument(); - // }); - it('displays login page when url is /login', () => { // given const url = '/login'; @@ -85,8 +75,6 @@ describe('App', () => { expect(header).toHaveTextContent('Zarejestruj się'); }); - - it('displays create notice page when url is /notice/new', () => { // given setUser1LoggedInStorage(); @@ -119,4 +107,5 @@ describe('App', () => { }); }); -console.error = () => {} \ No newline at end of file +console.error = () => { +} \ No newline at end of file diff --git a/front-end/src/pages/CreateNoticePage.js b/front-end/src/pages/CreateNoticePage.js index 0f04954..7543481 100644 --- a/front-end/src/pages/CreateNoticePage.js +++ b/front-end/src/pages/CreateNoticePage.js @@ -28,7 +28,7 @@ class CreateNoticePage extends Component { const tertiaryImage = this.imagesComponent.current.state.tertiaryImage.split(',')[1]; const price = this.state.price .replace('zł', '').replace('zl', '') - .replaceAll(' ',''); + .replaceAll(' ', ''); const title = this.state.title.trim(); const location = this.state.location.trim(); const description = this.state.description.trim(); diff --git a/front-end/src/pages/ErrorPage.spec.js b/front-end/src/pages/ErrorPage.spec.js index eafc1f8..5adf7c2 100644 --- a/front-end/src/pages/ErrorPage.spec.js +++ b/front-end/src/pages/ErrorPage.spec.js @@ -40,4 +40,5 @@ describe('ErrorPage', () => { expect(link).toHaveAttribute('href', '/'); }); }) -console.error = () => {} \ No newline at end of file +console.error = () => { +} \ No newline at end of file diff --git a/front-end/src/pages/HomePage.spec.js b/front-end/src/pages/HomePage.spec.js index 57d9d10..f45b899 100644 --- a/front-end/src/pages/HomePage.spec.js +++ b/front-end/src/pages/HomePage.spec.js @@ -13,4 +13,5 @@ describe('HomePage', () => { expect(homeDiv).toBeInTheDocument(); }); }) -console.error = () => {} \ No newline at end of file +console.error = () => { +} \ No newline at end of file diff --git a/front-end/src/pages/NoticePage.js b/front-end/src/pages/NoticePage.js index 9baf4ce..296ca76 100644 --- a/front-end/src/pages/NoticePage.js +++ b/front-end/src/pages/NoticePage.js @@ -152,28 +152,28 @@ class NoticePage extends Component { {this.state.notice.primaryImage && First slide event.target.src = defaultNoticeImage} + className="d-block w-100" + src={`/images/notice/${this.state.notice.primaryImage}`} + alt="First slide" + onError={event => event.target.src = defaultNoticeImage} />} {this.state.notice.secondaryImage && Second slide event.target.src = defaultNoticeImage} + className="d-block w-100" + src={`/images/notice/${this.state.notice.secondaryImage}`} + alt="Second slide" + onError={event => event.target.src = defaultNoticeImage} />} {this.state.notice.tertiaryImage && Third slide event.target.src = defaultNoticeImage} + className="d-block w-100" + src={`/images/notice/${this.state.notice.tertiaryImage}`} + alt="Third slide" + onError={event => event.target.src = defaultNoticeImage} />} diff --git a/front-end/src/pages/RegistrationPage.js b/front-end/src/pages/RegistrationPage.js index 247ec3a..db15f01 100644 --- a/front-end/src/pages/RegistrationPage.js +++ b/front-end/src/pages/RegistrationPage.js @@ -99,6 +99,7 @@ export class RegistrationPage extends Component { return !!(firstName !== '' && lastName !== '' && username !== '' && email !== '' & password !== '' && passwordRepeat !== ''); } + render() { return ( diff --git a/front-end/src/pages/RegistrationPage.spec.js b/front-end/src/pages/RegistrationPage.spec.js index 6529dd5..0c330fb 100644 --- a/front-end/src/pages/RegistrationPage.spec.js +++ b/front-end/src/pages/RegistrationPage.spec.js @@ -362,4 +362,5 @@ describe('RegistrationPage', () => { }); }); -console.error = () => {} +console.error = () => { +} diff --git a/front-end/src/pages/UserProfilePage.spec.js b/front-end/src/pages/UserProfilePage.spec.js index 6965ce0..dcbb994 100644 --- a/front-end/src/pages/UserProfilePage.spec.js +++ b/front-end/src/pages/UserProfilePage.spec.js @@ -86,4 +86,5 @@ describe('UserProfilePage', () => { expect(errorDiv).toBeInTheDocument(); }); }) -console.error = () => {} +console.error = () => { +} diff --git a/front-end/src/pages/VerificationEmailAddressPage.js b/front-end/src/pages/VerificationEmailAddressPage.js index 8dba5cb..6d02908 100644 --- a/front-end/src/pages/VerificationEmailAddressPage.js +++ b/front-end/src/pages/VerificationEmailAddressPage.js @@ -25,7 +25,7 @@ class VerificationEmailAddressPage extends Component { this._isMounted = true; this.interval = setInterval(() => { if (this.state.timeInSeconds) { - if(this._isMounted){ + if (this._isMounted) { this.setState({timeInSeconds: this.state.timeInSeconds - 1}); } }