1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-10-13 11:17:26 +02:00
unleash.unleash/frontend/src/component/insights/Insights.test.tsx
Jaanus Sellin 8943cc0a3d
feat: basic flag creation chart (#10411)
This is partial implementation of flag creation chart. This only shows
the created flags line part, but I need to style it and also add bar
charts in next PRs.

<img width="1498" height="523" alt="image"
src="https://github.com/user-attachments/assets/6d7a3145-95ff-4d31-85dd-47d687527d47"
/>
2025-07-24 14:45:16 +03:00

64 lines
2.2 KiB
TypeScript

import { render } from 'utils/testRenderer';
import { fireEvent, screen } from '@testing-library/react';
import { Insights } from './Insights.tsx';
import { testServerRoute, testServerSetup } from 'utils/testServer';
import { vi } from 'vitest';
const server = testServerSetup();
const setupApi = () => {
testServerRoute(server, '/api/admin/insights', {
users: { total: 0, active: 0, inactive: 0 },
userTrends: [],
projectFlagTrends: [],
metricsSummaryTrends: [],
flags: { total: 0 },
flagTrends: [],
environmentTypeTrends: [],
lifecycleTrends: [],
creationArchiveTrends: [],
});
testServerRoute(server, '/api/admin/projects', {
projects: [
{ name: 'Project A Name', id: 'projectA' },
{ name: 'Project B Name', id: 'projectB' },
],
});
};
const currentTime = '2024-04-25T08:05:00.000Z';
// todo(lifecycleMetrics): this test won't be relevant anymore because the
// filters are on each section instead of the top-level component. Consider
// rewriting this for the individual section components instead.
test('Filter insights by project and date', async () => {
vi.setSystemTime(currentTime);
setupApi();
render(<Insights withCharts={false} />);
const addFilter = await screen.findByText('Filter');
fireEvent.click(addFilter);
const projectFilter = await screen.findByText('Project');
// filter by project
fireEvent.click(projectFilter);
await screen.findByText('Project A Name');
const projectName = await screen.findByText('Project B Name');
await fireEvent.click(projectName);
expect(window.location.href).toContain('project=IS%3AprojectB');
// last month moving window by default
const fromDate = await screen.findByText('03/25/2024');
await screen.findByText('04/25/2024');
// change dates by preset range
fireEvent.click(fromDate);
const previousMonth = await screen.findByText('Previous month');
fireEvent.click(previousMonth);
await screen.findByText('03/01/2024');
await screen.findByText('03/31/2024');
expect(window.location.href).toContain(
'?project=IS%3AprojectB&from=IS%3A2024-03-01&to=IS%3A2024-03-31',
);
});