Skip to content

Commit

Permalink
Refactor the code
Browse files Browse the repository at this point in the history
  • Loading branch information
wysockif committed Jun 6, 2021
1 parent 2963476 commit ad167d2
Show file tree
Hide file tree
Showing 15 changed files with 32 additions and 53 deletions.
20 changes: 3 additions & 17 deletions front-end/src/api/apiCalls.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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');
Expand All @@ -140,4 +125,5 @@ describe('apiCalls', () => {
});
});

console.error = () => {}
console.error = () => {
}
1 change: 0 additions & 1 deletion front-end/src/components/ButtonWithSpinner.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ const ButtonWithSpinner = props => {
<span className="sr-only">Loading...</span>
</Spinner>}
</Button>

);
};

Expand Down
1 change: 0 additions & 1 deletion front-end/src/components/DeleteAccountModal.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ class DeleteAccountModal extends Component {
successInfo: undefined
}


onCancel = () => {
this.setState({
ongoingApiCall: false,
Expand Down
3 changes: 2 additions & 1 deletion front-end/src/components/InputWithValidation.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ const InputWithValidation = props => {
}

InputWithValidation.defaultProps = {
onChange: () => {}
onChange: () => {
}
};

export default InputWithValidation;
3 changes: 2 additions & 1 deletion front-end/src/components/TopBar.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,4 +90,5 @@ describe('TopBar', () => {
});

});
console.error = () => {}
console.error = () => {
}
1 change: 0 additions & 1 deletion front-end/src/components/notice-form/ContactInformation.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,4 @@ const ContactInformation = ({email}) => {
);
};


export default ContactInformation;
15 changes: 2 additions & 13 deletions front-end/src/containers/App.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -85,8 +75,6 @@ describe('App', () => {
expect(header).toHaveTextContent('Zarejestruj się');
});



it('displays create notice page when url is /notice/new', () => {
// given
setUser1LoggedInStorage();
Expand Down Expand Up @@ -119,4 +107,5 @@ describe('App', () => {
});
});

console.error = () => {}
console.error = () => {
}
2 changes: 1 addition & 1 deletion front-end/src/pages/CreateNoticePage.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
3 changes: 2 additions & 1 deletion front-end/src/pages/ErrorPage.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,5 @@ describe('ErrorPage', () => {
expect(link).toHaveAttribute('href', '/');
});
})
console.error = () => {}
console.error = () => {
}
3 changes: 2 additions & 1 deletion front-end/src/pages/HomePage.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ describe('HomePage', () => {
expect(homeDiv).toBeInTheDocument();
});
})
console.error = () => {}
console.error = () => {
}
24 changes: 12 additions & 12 deletions front-end/src/pages/NoticePage.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,28 +152,28 @@ class NoticePage extends Component {
<Carousel.Item style={{maxHeight: "430px"}}>
{this.state.notice.primaryImage &&
<Image
className="d-block w-100"
src={`/images/notice/${this.state.notice.primaryImage}`}
alt="First slide"
onError={event => 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}
/>}
</Carousel.Item>
<Carousel.Item style={{maxHeight: "430px"}}>
{this.state.notice.secondaryImage &&
<Image
className="d-block w-100"
src={`/images/notice/${this.state.notice.secondaryImage}`}
alt="Second slide"
onError={event => 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}
/>}
</Carousel.Item>
<Carousel.Item style={{maxHeight: "430px"}}>
{this.state.notice.tertiaryImage &&
<Image
className="d-block w-100"
src={`/images/notice/${this.state.notice.tertiaryImage}`}
alt="Third slide"
onError={event => 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}
/>}
</Carousel.Item>
</Carousel>
Expand Down
1 change: 1 addition & 0 deletions front-end/src/pages/RegistrationPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ export class RegistrationPage extends Component {
return !!(firstName !== '' && lastName !== '' && username !== ''
&& email !== '' & password !== '' && passwordRepeat !== '');
}

render() {
return (
<Container className="col-11 col-sm-10 col-md-9 col-lg-7 col-xl-5 mt-5" style={{marginBottom: "90px"}}>
Expand Down
3 changes: 2 additions & 1 deletion front-end/src/pages/RegistrationPage.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -362,4 +362,5 @@ describe('RegistrationPage', () => {

});
});
console.error = () => {}
console.error = () => {
}
3 changes: 2 additions & 1 deletion front-end/src/pages/UserProfilePage.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,4 +86,5 @@ describe('UserProfilePage', () => {
expect(errorDiv).toBeInTheDocument();
});
})
console.error = () => {}
console.error = () => {
}
2 changes: 1 addition & 1 deletion front-end/src/pages/VerificationEmailAddressPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -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});
}
}
Expand Down

0 comments on commit ad167d2

Please sign in to comment.