-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #65 from kolorfilm/refactoring/general-refactoring
General Refactoring: Change eslint + prettier rules
- Loading branch information
Showing
28 changed files
with
403 additions
and
412 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,9 @@ | ||
{ | ||
"printWidth": 80, | ||
"semi": false, | ||
"semi": true, | ||
"tabWidth": 2, | ||
"printWidth": 100, | ||
"singleQuote": true, | ||
"trailingComma": "es5" | ||
"trailingComma": "es5", | ||
"bracketSameLine": false, | ||
"bracketSpacing": true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,4 +26,4 @@ module.exports = { | |
}, | ||
], | ||
}, | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,77 +1,73 @@ | ||
import { act } from 'react' | ||
import { render, screen } from '@testing-library/react' | ||
import fetchMock from 'jest-fetch-mock' | ||
import Orders from './Orders' | ||
import { ordersMapped } from '../mocks/ordersMapped' | ||
import { ORDER_SUMMARY_LABELS } from './OrdersSummary' | ||
import { act } from 'react'; | ||
import { render, screen } from '@testing-library/react'; | ||
import fetchMock from 'jest-fetch-mock'; | ||
import Orders from './Orders'; | ||
import { ordersMapped } from '../mocks/ordersMapped'; | ||
import { ORDER_SUMMARY_LABELS } from './OrdersSummary'; | ||
|
||
jest.mock('highcharts/highstock') | ||
jest.mock('highcharts/highstock'); | ||
|
||
describe('Orders', () => { | ||
const renderComponent = async (): Promise<void> => { | ||
await act(async () => { | ||
render(<Orders />) | ||
}) | ||
} | ||
render(<Orders />); | ||
}); | ||
}; | ||
|
||
beforeEach(() => { | ||
jest.clearAllMocks() | ||
fetchMock.mockResponse(JSON.stringify({ orders: ordersMapped })) | ||
}) | ||
jest.clearAllMocks(); | ||
fetchMock.mockResponse(JSON.stringify({ orders: ordersMapped })); | ||
}); | ||
|
||
it('fetches orders correctly', async () => { | ||
await renderComponent() | ||
await renderComponent(); | ||
|
||
expect(fetchMock).toHaveBeenCalledTimes(1) | ||
expect(fetchMock).toHaveBeenCalledTimes(1); | ||
|
||
expect(fetchMock.mock.calls[0][0]).toEqual( | ||
process.env.DISCOGS_APP_URL + '/orders' | ||
) | ||
expect(fetchMock.mock.calls[0][0]).toEqual(process.env.DISCOGS_APP_URL + '/orders'); | ||
|
||
expect(screen.queryByTestId('orders-loader')).not.toBeInTheDocument() | ||
}) | ||
expect(screen.queryByTestId('orders-loader')).not.toBeInTheDocument(); | ||
}); | ||
|
||
it('renders summary correctly', async () => { | ||
await renderComponent() | ||
await renderComponent(); | ||
|
||
expect(fetchMock).toHaveBeenCalledTimes(1) | ||
expect(fetchMock).toHaveBeenCalledTimes(1); | ||
|
||
const profileLink = screen.getByTestId('order-summary-profile-link') | ||
const profileLink = screen.getByTestId('order-summary-profile-link'); | ||
expect(profileLink).toHaveAttribute( | ||
'href', | ||
`https://www.discogs.com/de/seller/${ordersMapped.username}/profile` | ||
) | ||
expect(profileLink).toHaveTextContent('Profile Link') | ||
); | ||
expect(profileLink).toHaveTextContent('Profile Link'); | ||
|
||
ORDER_SUMMARY_LABELS.forEach((label, index) => { | ||
expect( | ||
screen.getByTestId(`order-summary-label-${index}`) | ||
).toHaveTextContent(label) | ||
}) | ||
expect(screen.getByTestId(`order-summary-label-${index}`)).toHaveTextContent(label); | ||
}); | ||
|
||
expect( | ||
screen.getByText(ORDER_SUMMARY_LABELS[0] + ':').parentNode | ||
).toHaveTextContent('2018-09-05') | ||
expect( | ||
screen.getByText(ORDER_SUMMARY_LABELS[1] + ':').parentNode | ||
).toHaveTextContent('2019-02-02') | ||
expect( | ||
screen.getByText(ORDER_SUMMARY_LABELS[2] + ':').parentNode | ||
).toHaveTextContent(ordersMapped.ordersTotal.toString()) | ||
expect( | ||
screen.getByText(ORDER_SUMMARY_LABELS[3] + ':').parentNode | ||
).toHaveTextContent(ordersMapped.itemsSold.toString()) | ||
expect( | ||
screen.getByText(ORDER_SUMMARY_LABELS[4] + ':').parentNode | ||
).toHaveTextContent(ordersMapped.ordersSent.toString()) | ||
expect( | ||
screen.getByText(ORDER_SUMMARY_LABELS[5] + ':').parentNode | ||
).toHaveTextContent(ordersMapped.ordersCancelled.toString()) | ||
expect( | ||
screen.getByText(ORDER_SUMMARY_LABELS[6] + ':').parentNode | ||
).toHaveTextContent(ordersMapped.ordersRefund.toString()) | ||
expect( | ||
screen.getByText(ORDER_SUMMARY_LABELS[7] + ':').parentNode | ||
).toHaveTextContent(Number(ordersMapped.totalAmount).toFixed(2) + ' €') | ||
}) | ||
}) | ||
expect(screen.getByText(ORDER_SUMMARY_LABELS[0] + ':').parentNode).toHaveTextContent( | ||
'2018-09-05' | ||
); | ||
expect(screen.getByText(ORDER_SUMMARY_LABELS[1] + ':').parentNode).toHaveTextContent( | ||
'2019-02-02' | ||
); | ||
expect(screen.getByText(ORDER_SUMMARY_LABELS[2] + ':').parentNode).toHaveTextContent( | ||
ordersMapped.ordersTotal.toString() | ||
); | ||
expect(screen.getByText(ORDER_SUMMARY_LABELS[3] + ':').parentNode).toHaveTextContent( | ||
ordersMapped.itemsSold.toString() | ||
); | ||
expect(screen.getByText(ORDER_SUMMARY_LABELS[4] + ':').parentNode).toHaveTextContent( | ||
ordersMapped.ordersSent.toString() | ||
); | ||
expect(screen.getByText(ORDER_SUMMARY_LABELS[5] + ':').parentNode).toHaveTextContent( | ||
ordersMapped.ordersCancelled.toString() | ||
); | ||
expect(screen.getByText(ORDER_SUMMARY_LABELS[6] + ':').parentNode).toHaveTextContent( | ||
ordersMapped.ordersRefund.toString() | ||
); | ||
expect(screen.getByText(ORDER_SUMMARY_LABELS[7] + ':').parentNode).toHaveTextContent( | ||
Number(ordersMapped.totalAmount).toFixed(2) + ' €' | ||
); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,80 +1,78 @@ | ||
import React, { useEffect, useState } from 'react' | ||
import Head from 'next/head' | ||
import dynamic from 'next/dynamic' | ||
import { useEffect, useState } from 'react'; | ||
import dynamic from 'next/dynamic'; | ||
import Head from 'next/head'; | ||
import OrdersSummary from './OrdersSummary'; | ||
import { OrdersMapped } from '../types/OrdersMapped'; | ||
import styles from './Orders.module.scss'; | ||
|
||
const OrdersHighcharts = dynamic(() => import('./OrdersHighcharts'), { | ||
ssr: false, | ||
}) | ||
import OrdersSummary from './OrdersSummary' | ||
import { OrdersMapped } from '../types/OrdersMapped' | ||
import styles from './Orders.module.scss' | ||
}); | ||
|
||
const Orders: React.FC = () => { | ||
const [loading, setLoading] = useState(true) | ||
const [orders, setOrders] = useState<OrdersMapped | null>(null) | ||
const [firstOrderDate, setFirstOrderDate] = useState('') | ||
const [lastOrderDate, setLastOrderDate] = useState('') | ||
const Orders = () => { | ||
const [loading, setLoading] = useState(true); | ||
const [orders, setOrders] = useState<OrdersMapped | undefined>(undefined); | ||
const [firstOrderDate, setFirstOrderDate] = useState(''); | ||
const [lastOrderDate, setLastOrderDate] = useState(''); | ||
|
||
useEffect(() => { | ||
const fetchOrders = async (): Promise<void> => { | ||
fetch(process.env.DISCOGS_APP_URL + '/orders') | ||
.then((orders) => { | ||
return orders.json() | ||
}) | ||
.then((orders) => orders.json()) | ||
.then((data) => { | ||
if (data.hasAuthError) { | ||
location.assign('authorize') | ||
return | ||
location.assign('authorize'); | ||
return; | ||
} | ||
|
||
const orders = data.orders | ||
const seriesItems = orders.seriesItems | ||
const orders = data.orders; | ||
const seriesItems = orders.seriesItems; | ||
const formatter = new Intl.DateTimeFormat('en-CA', { | ||
year: 'numeric', | ||
month: '2-digit', | ||
day: '2-digit', | ||
}) | ||
const firstOrderDate = formatter.format(seriesItems[0].created) | ||
const lastOrderDate = formatter.format( | ||
seriesItems[seriesItems.length - 1].created | ||
) | ||
}); | ||
const firstOrderDate = formatter.format(seriesItems[0].created); | ||
const lastOrderDate = formatter.format(seriesItems[seriesItems.length - 1].created); | ||
|
||
setOrders(orders) | ||
setFirstOrderDate(firstOrderDate) | ||
setLastOrderDate(lastOrderDate) | ||
}) | ||
} | ||
setOrders(orders); | ||
setFirstOrderDate(firstOrderDate); | ||
setLastOrderDate(lastOrderDate); | ||
}); | ||
}; | ||
|
||
fetchOrders().then() | ||
}, []) | ||
fetchOrders().then(); | ||
}, []); | ||
|
||
useEffect(() => { | ||
if (orders) { | ||
setLoading(false) | ||
setLoading(false); | ||
} | ||
}, [orders]) | ||
}, [orders]); | ||
|
||
return ( | ||
<div className={styles.container}> | ||
<Head> | ||
<title>Discogs Visualizer</title> | ||
</Head> | ||
<main className={styles.main}> | ||
{loading && ( | ||
{loading ? ( | ||
<div className={styles.loader} data-testid="orders-loader"></div> | ||
)} | ||
{orders && ( | ||
<> | ||
<OrdersHighcharts orders={orders} /> | ||
<OrdersSummary | ||
orders={orders} | ||
firstOrderDate={firstOrderDate} | ||
lastOrderDate={lastOrderDate} | ||
/> | ||
</> | ||
) : ( | ||
orders && ( | ||
<> | ||
<OrdersHighcharts orders={orders} /> | ||
<OrdersSummary | ||
orders={orders} | ||
firstOrderDate={firstOrderDate} | ||
lastOrderDate={lastOrderDate} | ||
/> | ||
</> | ||
) | ||
)} | ||
</main> | ||
</div> | ||
) | ||
} | ||
); | ||
}; | ||
|
||
export default Orders | ||
export default Orders; |
Oops, something went wrong.