fix: oprava zobrazení statistik pro aktuální týden
CI / Generate TypeScript types (push) Successful in 16s
CI / Server unit tests (push) Successful in 25s
CI / Build server (push) Successful in 28s
CI / Build client (push) Successful in 41s
CI / Playwright E2E tests (push) Successful in 1m46s
CI / Build and push Docker image (push) Successful in 48s
CI / Notify (push) Successful in 2s
CI / Generate TypeScript types (push) Successful in 16s
CI / Server unit tests (push) Successful in 25s
CI / Build server (push) Successful in 28s
CI / Build client (push) Successful in 41s
CI / Playwright E2E tests (push) Successful in 1m46s
CI / Build and push Docker image (push) Successful in 48s
CI / Notify (push) Successful in 2s
This commit is contained in:
@@ -126,9 +126,8 @@ export default function StatsPage() {
|
|||||||
|
|
||||||
const isCurrentOrFutureWeek = useMemo(() => {
|
const isCurrentOrFutureWeek = useMemo(() => {
|
||||||
if (!dateRange) return true;
|
if (!dateRange) return true;
|
||||||
const currentWeekEnd = getLastWorkDayOfWeek(new Date());
|
// Porovnáváme jen dny (obě data nesou čas svého vzniku), dopředu jde jít nejvýše na aktuální týden
|
||||||
currentWeekEnd.setHours(23, 59, 59, 999);
|
return formatDate(dateRange[1]) >= formatDate(getLastWorkDayOfWeek(new Date()));
|
||||||
return dateRange[1] >= currentWeekEnd;
|
|
||||||
}, [dateRange]);
|
}, [dateRange]);
|
||||||
|
|
||||||
const handleKeyDown = useCallback((e: any) => {
|
const handleKeyDown = useCallback((e: any) => {
|
||||||
|
|||||||
@@ -0,0 +1,3 @@
|
|||||||
|
[
|
||||||
|
"Statistiky se nově načtou i pro aktuální týden, který ještě neskončil"
|
||||||
|
]
|
||||||
+9
-3
@@ -5,6 +5,9 @@ import getStorage from "./storage";
|
|||||||
|
|
||||||
const storage = getStorage();
|
const storage = getStorage();
|
||||||
|
|
||||||
|
/** O kolik dní do budoucnosti smí sahat koncové datum požadovaného rozsahu. */
|
||||||
|
const MAX_FUTURE_DAYS = 7;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Vypočte a vrátí statistiky jednotlivých možností pro předaný rozsah dat.
|
* Vypočte a vrátí statistiky jednotlivých možností pro předaný rozsah dat.
|
||||||
*
|
*
|
||||||
@@ -25,9 +28,12 @@ export async function getStats(startDate: string, endDate: string): Promise<Week
|
|||||||
throw new Error('Neplatný rozsah');
|
throw new Error('Neplatný rozsah');
|
||||||
}
|
}
|
||||||
|
|
||||||
const today = new Date();
|
// Aktuální týden se načítá i s dny, které teprve budou — povolíme proto rozsah
|
||||||
today.setHours(23, 59, 59, 999);
|
// sahající maximálně týden do budoucnosti
|
||||||
if (end > today) {
|
const maxEnd = new Date();
|
||||||
|
maxEnd.setHours(23, 59, 59, 999);
|
||||||
|
maxEnd.setDate(maxEnd.getDate() + MAX_FUTURE_DAYS);
|
||||||
|
if (end > maxEnd) {
|
||||||
throw new Error('Nelze načíst statistiky pro budoucí datum');
|
throw new Error('Nelze načíst statistiky pro budoucí datum');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import bodyParser from 'body-parser';
|
|||||||
import { generateToken } from '../auth';
|
import { generateToken } from '../auth';
|
||||||
import { resetMemoryStorage } from '../storage/memory';
|
import { resetMemoryStorage } from '../storage/memory';
|
||||||
import statsRouter from '../routes/statsRoutes';
|
import statsRouter from '../routes/statsRoutes';
|
||||||
|
import { formatDate } from '../utils';
|
||||||
|
|
||||||
function buildApp() {
|
function buildApp() {
|
||||||
const app = express();
|
const app = express();
|
||||||
@@ -52,6 +53,31 @@ test('GET /stats s budoucím datem vrátí 400', async () => {
|
|||||||
expect(res.status).toBe(400);
|
expect(res.status).toBe(400);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('GET /stats s koncovým datem do týdne v budoucnosti vrátí 200', async () => {
|
||||||
|
// Aktuální týden se načítá i s dny, které teprve budou
|
||||||
|
const start = new Date();
|
||||||
|
const end = new Date();
|
||||||
|
end.setDate(end.getDate() + 3);
|
||||||
|
const res = await request(buildApp())
|
||||||
|
.get('/api/stats')
|
||||||
|
.query({ startDate: formatDate(start), endDate: formatDate(end) })
|
||||||
|
.set('Authorization', TOKEN);
|
||||||
|
expect(res.status).toBe(200);
|
||||||
|
expect(Array.isArray(res.body)).toBe(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('GET /stats s koncovým datem více než týden v budoucnosti vrátí 400', async () => {
|
||||||
|
const start = new Date();
|
||||||
|
start.setDate(start.getDate() + 8);
|
||||||
|
const end = new Date(start);
|
||||||
|
end.setDate(end.getDate() + 4);
|
||||||
|
const res = await request(buildApp())
|
||||||
|
.get('/api/stats')
|
||||||
|
.query({ startDate: formatDate(start), endDate: formatDate(end) })
|
||||||
|
.set('Authorization', TOKEN);
|
||||||
|
expect(res.status).toBe(400);
|
||||||
|
});
|
||||||
|
|
||||||
test('GET /stats/export vrátí XLSX soubor', async () => {
|
test('GET /stats/export vrátí XLSX soubor', async () => {
|
||||||
const res = await request(buildApp())
|
const res = await request(buildApp())
|
||||||
.get('/api/stats/export')
|
.get('/api/stats/export')
|
||||||
|
|||||||
Reference in New Issue
Block a user