Skip to content

Commit

Permalink
fix(*): fix Footer and Products
Browse files Browse the repository at this point in the history
improve type and tests

#43
  • Loading branch information
aneurysmjs committed Feb 6, 2020
1 parent 57f4b18 commit c659d3f
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 10 deletions.
6 changes: 3 additions & 3 deletions src/app/components/core/Footer/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ import { FunctionComponent } from 'react';
import withAlien from '~/store/config/alienStore/withAlien';
import FooterComponent from './Footer';

type ProductsModules = Promise<typeof import('~/store/modules/footer/footer.module')>;
type FooterModule = Promise<typeof import('~/store/modules/footer/footer.module')>;

const Footer: FunctionComponent<{ modules: Array<ProductsModules> }> = () =>
const Footer: FunctionComponent<{ modules: Array<FooterModule> }> = () =>
withAlien(FooterComponent, [
(): ProductsModules =>
(): FooterModule =>
import(/* webpackChunkName: "ReduxModule" */ '~/store/modules/footer/footer.module'),
]);

Expand Down
2 changes: 1 addition & 1 deletion src/app/store/modules/footer/actions/footerAction.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ describe('footer action', () => {
phone: '89189258147',
email: '[email protected]',
};
const payload = { footer: { social, contact } };
const payload = { social, contact };
const expectedData = { type: FOOTER_DATA, payload };
expect(footerAction(payload)).toEqual(expectedData);
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import axiosMock from 'axios';
import configureMockStore from 'redux-mock-store';

import { ApiMetaType } from '~/shared/types/MiddlewareTypes';

import apiMiddleware from '~/store/config/middlewares/apiMiddleware';

import fetchProducts from './fetchProducts';
Expand Down Expand Up @@ -41,7 +43,7 @@ const mockStore = configureMockStore([apiMiddleware]);
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
const makeStore = (initialState = []) => mockStore(() => ({ products: initialState }));

let action = { meta: {} };
let action = { meta: {} as ApiMetaType };

beforeEach(() => {
axiosMock.mockRestore();
Expand Down
1 change: 0 additions & 1 deletion src/app/store/modules/products/actions/fetchProducts.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ export default function fetchProducts(query: string): FetchProductAction {
callAPI: () => api.get(query),
shouldCallAPI: state => {
const { products } = getProducts(state);

return products.length === 0;
},
};
Expand Down
12 changes: 8 additions & 4 deletions src/app/store/modules/products/reducers/products.test.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
/* eslint-disable @typescript-eslint/ban-ts-ignore */
import products from './products';

import { ProductsActionTypes } from '~/store/modules/products/types';
import {
GET_PRODUCTS_REQUEST,
GET_PRODUCTS_SUCCESS,
GET_PRODUCTS_FAILURE,
} from '~/store/modules/products/types/actionTypes';

const productsData = [
{
Expand All @@ -28,7 +32,7 @@ describe('products reducer', () => {

it('should display loading indicator', () => {
const successAction = {
type: ProductsActionTypes.GetProductsRequest,
type: GET_PRODUCTS_REQUEST,
isLoading: true,
};
// @ts-ignore - only for testing purposes
Expand All @@ -37,7 +41,7 @@ describe('products reducer', () => {

it('should return products', () => {
const successAction = {
type: ProductsActionTypes.GetProductsSuccess,
type: GET_PRODUCTS_SUCCESS,
payload: { response },
error: null,
};
Expand All @@ -47,7 +51,7 @@ describe('products reducer', () => {

it('should return error', () => {
const errorAction = {
type: ProductsActionTypes.GetProductsFailure,
type: GET_PRODUCTS_FAILURE,
payload: { error },
};
// @ts-ignore - only for testing purposes
Expand Down

0 comments on commit c659d3f

Please sign in to comment.