mirror of
https://github.com/Unleash/unleash.git
synced 2025-10-13 11:17:26 +02:00
Splits the insights page into separate sections with their own separate filters. Each filter is sticky to the top of the page, similar to how the previous filters worked. In doing this, I have also moved around a lot of code. Refer to the inline comments for more specific examples, but on a high level, this PR: - Moves the flag check from InsightsCharts into Insights itself. Because the old Insights had filters and state, and the new one does not, it made sense to fork off higher up in the tree. Because the new version doesn't have state, I have also simplified it and removed an intermediate component (InsightsCharts) that doesn't feel necessary anymore. - Because InsightsCharts isn't used anymore, I've moved the LegacyInsightsCharts file back into InsightsCharts. However, I'm happy to move it back if we think that's useful. - Instead of all charts living in InsightsCharts, I've split each section into its own file in the new sections directory. Because the sections have separate filters, they don't share any state anymore, so there's nothing they share. - I'm reusing the existing hook and endpoint. As it stands, the performance insights use **most** of the data from that payload (but not all of it). The user insights use some of it. Flag lifecycle insights doesn't use anything, but I've wired it up to make the filters work. I expect that we'll iterate on the API endpoints etc later. 
62 lines
2.1 KiB
TypeScript
62 lines
2.1 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: [],
|
|
});
|
|
|
|
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',
|
|
);
|
|
});
|