Skip to content

Commit

Permalink
Updating tests
Browse files Browse the repository at this point in the history
  • Loading branch information
deniolp committed Nov 28, 2019
1 parent 10b3338 commit bd30bda
Show file tree
Hide file tree
Showing 9 changed files with 41 additions and 53 deletions.
4 changes: 2 additions & 2 deletions src/components/add-review/add-review.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ interface Props {
}, id: number) => void;
onLoadFilms: () => void;
onRadioClick: () => void;
onTextareaChange: (evt: any) => void;
onTextareaChange: (evt: object) => void;
isValidated: boolean;
isReviewSending: boolean;
onUpdateForm: () => void;
Expand Down Expand Up @@ -161,7 +161,7 @@ const mapStateToProps = (state, ownProps): object => Object.assign({}, ownProps,
didReviewSend: getDidReviewSend(state),
});

const mapDispatchToProps = (dispatch) => ({
const mapDispatchToProps = (dispatch): object => ({
onSubmitForm: (review, id): void => {
dispatch(ActionCreator.blockForm(true));
dispatch(Operation.postReview(review, id));
Expand Down
2 changes: 1 addition & 1 deletion src/components/app/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ const mapStateToProps = (state, ownProps): object => Object.assign({}, ownProps,
error: getError(state),
});

const mapDispatchToProps = (dispatch) => ({
const mapDispatchToProps = (dispatch): object => ({
onGenreClick: (selectedGenre): void => {
dispatch(ActionCreator.changeGenre(selectedGenre));
dispatch(ActionCreator.resetFilmsCounter());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,13 @@ exports[`BigPlayer renders correctly 1`] = `
height="100%"
poster="/img/player-poster.jpg"
preload="auto"
src="https://media.xiph.org/mango/tears_of_steel_1080p.webm"
width="100%"
/>
>
<source
src="https://media.xiph.org/mango/tears_of_steel_1080p.webm"
type="video/webm"
/>
</video>
<button
className="player__exit"
onClick={[Function]}
Expand Down
8 changes: 4 additions & 4 deletions src/components/big-player/big-player.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const BigPlayer = (props: Props): React.SFC => {
React.useEffect(() => {
videoRef.current.oncanplaythrough = (): void => {
setIsLoading(false);
videoRef.current.poster= ``;
videoRef.current.poster = ``;
};
}, []);

Expand Down Expand Up @@ -81,9 +81,9 @@ const BigPlayer = (props: Props): React.SFC => {
height="100%"
>
<source
src={playingFilm.videoLink}
type={`video/${format}`}
></source>
src={playingFilm.videoLink}
type={`video/${format}`}
></source>
</video>
<button
type="button"
Expand Down
2 changes: 1 addition & 1 deletion src/components/film-details/film-details.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ const mapStateToProps = (state, ownProps): object => Object.assign({}, ownProps,
films: getFilmsWithChangedUrl(state),
});

const mapDispatchToProps = (dispatch) => ({
const mapDispatchToProps = (dispatch): object => ({
onLoadFilms: (): void => dispatch(Operation.loadFilms()),
});

Expand Down
2 changes: 1 addition & 1 deletion src/components/sign-in/sign-in.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ const SignIn = (props: Props): React.SFC => {
</div> : <Redirect to="/"></Redirect>;
};

const mapDispatchToProps = (dispatch) => ({
const mapDispatchToProps = (dispatch): object => ({
submitForm: (email, password): void => dispatch(Operation.logIn(email, password)),
});

Expand Down
24 changes: 4 additions & 20 deletions src/reducer/reducer.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ describe(`Action creators works correctly: `, () => {
type: `LOAD_FILMS`,
payload: [{
fake: true,
previewVideoLink: `https://upload.wikimedia.org/wikipedia/commons/transcoded/b/b3/Big_Buck_Bunny_Trailer_400p.ogv/Big_Buck_Bunny_Trailer_400p.ogv.360p.webm`,
}],
});
});
Expand Down Expand Up @@ -107,15 +106,7 @@ describe(`Action creators works correctly: `, () => {
expect(dispatch).toHaveBeenCalledTimes(1);
expect(dispatch).toHaveBeenNthCalledWith(1, {
type: `LOAD_FAVORITES`,
payload: [
{
fakeFilm: true,
previewVideoLink: `https://upload.wikimedia.org/wikipedia/commons/transcoded/b/b3/Big_Buck_Bunny_Trailer_400p.ogv/Big_Buck_Bunny_Trailer_400p.ogv.360p.webm`,
},
{
fakeFilm2: true,
previewVideoLink: `https://upload.wikimedia.org/wikipedia/commons/transcoded/b/b3/Big_Buck_Bunny_Trailer_400p.ogv/Big_Buck_Bunny_Trailer_400p.ogv.360p.webm`,
}],
payload: [{fakeFilm: true}, {fakeFilm2: true}],
});
});
});
Expand All @@ -133,7 +124,7 @@ describe(`Action creators works correctly: `, () => {
.then(() => {
expect(dispatch).toHaveBeenCalledTimes(1);
expect(dispatch).toHaveBeenNthCalledWith(1, {
type: `ADD_TO_FAVORITES`,
type: `UPDATE_FILMS`,
payload: {fakeFilm: true, isFavorite: true},
});
});
Expand All @@ -152,7 +143,7 @@ describe(`Action creators works correctly: `, () => {
.then(() => {
expect(dispatch).toHaveBeenCalledTimes(1);
expect(dispatch).toHaveBeenNthCalledWith(1, {
type: `DELETE_FROM_FAVORITES`,
type: `UPDATE_FILMS`,
payload: {fakeFilm: true, isFavorite: false},
});
});
Expand Down Expand Up @@ -249,19 +240,12 @@ describe(`Action creators works correctly: `, () => {

return commentPoster(dispatch, {}, api)
.then(() => {
expect(dispatch).toHaveBeenCalledTimes(3);
expect(dispatch).toHaveBeenCalledTimes(2);
expect(dispatch).toHaveBeenNthCalledWith(1, {
type: `BLOCK_FORM`,
payload: false,
});
expect(dispatch).toHaveBeenNthCalledWith(2, {
type: `LOAD_COMMENTS`,
payload: [
{rating: 5, comment: `Wow!`},
{rating: 4, comment: `Pretty good!`}
],
});
expect(dispatch).toHaveBeenNthCalledWith(3, {
type: `CLEAN_FORM`,
payload: true,
});
Expand Down
3 changes: 1 addition & 2 deletions src/reducer/reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ const Operation = {
if (isPromo) {
dispatch(ActionCreator.updatePromo(preparedData));
}
return dispatch(ActionCreator.updateFilms(preparedData))
return dispatch(ActionCreator.updateFilms(preparedData));
})
.catch((_err) => {});
},
Expand Down Expand Up @@ -155,7 +155,6 @@ const Operation = {
return api.post(`comments/${id}`, review)
.then((response) => {
if (response.data) {
const preparedData = response.data.map((item) => normalizeKeys(item));
dispatch(ActionCreator.blockForm(false));
dispatch(ActionCreator.cleanForm(true));
}
Expand Down
41 changes: 21 additions & 20 deletions src/reducer/selectors.ts
Original file line number Diff line number Diff line change
@@ -1,65 +1,66 @@
import {createSelector} from 'reselect';

import {changeVideoUrl} from '../utils';
import {Film, User, Review} from '../types';

export const getFilms = (state) => {
export const getFilms = (state): Film[] => {
return state.films;
};

export const getFilmsWithChangedUrl = createSelector(
getFilms,
(films) => {
return changeVideoUrl(films);
}
getFilms,
(films) => {
return changeVideoUrl(films);
}
);

export const getFavorites = (state) => {
export const getFavorites = (state): Film[] => {
return state.favorites;
};

export const getFavoritesWithChangedUrl = createSelector(
getFavorites,
(films) => {
return changeVideoUrl(films);
}
getFavorites,
(films) => {
return changeVideoUrl(films);
}
);

export const getGenre = (state) => {
export const getGenre = (state): string => {
return state.genre;
};

export const getpromo = (state) => {
export const getpromo = (state): Film => {
return state.promo;
};

export const getFilmsCounter = (state) => {
export const getFilmsCounter = (state): number => {
return state.filmsCounter;
};

export const getPlayingFilm = (state) => {
export const getPlayingFilm = (state): Film => {
return state.playingFilm;
};

export const getIsAuthorizationRequired = (state) => {
export const getIsAuthorizationRequired = (state): boolean => {
return state.isAuthorizationRequired;
};

export const getUser = (state) => {
export const getUser = (state): User => {
return state.user;
};

export const getError = (state) => {
export const getError = (state): string => {
return state.error;
};

export const getIsReviewSending = (state) => {
export const getIsReviewSending = (state): boolean => {
return state.isReviewSending;
};

export const getDidReviewSend = (state) => {
export const getDidReviewSend = (state): boolean => {
return state.didReviewSend;
};

export const getReviews = (state) => {
export const getReviews = (state): Review[] => {
return state.comments;
};

0 comments on commit bd30bda

Please sign in to comment.