Add unit tests for backend and refactor few things on frontend

This commit is contained in:
Almira Krdzic
2018-08-14 00:44:51 +02:00
parent 47bc6bdab1
commit bb3fecd811
14 changed files with 1221 additions and 5541 deletions

View File

@@ -12,14 +12,14 @@ class OrdersDataContainer extends Component {
this.props.dispatch(getActiveOrders());
this.props.dispatch(getHistoryOrders());
}
hasCurrentCustomerOrders(orders) {
return orders.some((order) => order.isMyOrder);
}
render() {
const {activeOrders, historyOrders, type, isLoading} = this.props;
const orders = type ? type === 'active' ? activeOrders : historyOrders : {};
const {activeOrders, historyOrders, type, isLoading, isViewAllOrdersChecked} = this.props;
let orders = type ? type === 'active' ? activeOrders : historyOrders : [];
const viewAllOrders = isViewAllOrdersChecked && isViewAllOrdersChecked[type];
if (!viewAllOrders) {
// show only current customer orders
orders = orders.filter(o => o.isMyOrder);
}
const mainTitleOrder = type.charAt(0).toUpperCase() + type.slice(1);
return (
@@ -33,10 +33,10 @@ class OrdersDataContainer extends Component {
</div>
}
{ (orders && !isLoading) &&
<OrderList orders={orders} type={type}/>
<OrderList orders={orders} type={type} showOrderCustomer={viewAllOrders}/>
}
{
((orders && orders.length === 0 && !isLoading) || (orders && !this.hasCurrentCustomerOrders(orders))) &&
!isLoading && orders.length === 0 &&
<Alert color="info">{orderTexts.labels.NO_RECORDS}</Alert>
}
</WiaasBox>
@@ -47,9 +47,10 @@ class OrdersDataContainer extends Component {
}
const mapStateToProps = (state) => ({
activeOrders: state.ordersReducer.activeOrders,
historyOrders: state.ordersReducer.historyOrders,
isLoading: state.ordersReducer.isLoading
activeOrders: state.ordersReducer.activeOrders || [],
historyOrders: state.ordersReducer.historyOrders || [],
isLoading: state.ordersReducer.isLoading,
isViewAllOrdersChecked: state.ordersReducer.isViewAllOrdersChecked,
});
export default connect(mapStateToProps)(OrdersDataContainer);