Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: personal dashboard #8343

Merged
merged 2 commits into from
Oct 2, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
164 changes: 164 additions & 0 deletions frontend/src/component/personalDashboard/PersonalDashboard.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
import { PersonalDashboard } from './PersonalDashboard';
import { render } from 'utils/testRenderer';
import { fireEvent, screen } from '@testing-library/react';
import { testServerRoute, testServerSetup } from '../../utils/testServer';

const server = testServerSetup();

const setupLongRunningProject = () => {
testServerRoute(server, '/api/admin/user', {
user: {
name: 'Unleash User',
},
});

testServerRoute(server, '/api/admin/personal-dashboard', {
projects: [
{
id: 'projectId',
memberCount: 10,
featureCount: 100,
health: 80,
name: 'projectName',
},
],
flags: [
{
name: 'myFlag',
project: 'projectId',
type: 'release',
},
],
});

testServerRoute(server, '/api/admin/personal-dashboard/projectId', {
onboardingStatus: { status: 'onboarded' },
insights: {
avgHealthCurrentWindow: 80,
avgHealthPastWindow: 70,
},
latestEvents: [{ summary: 'someone created a flag', id: 0 }],
roles: [{ name: 'Member' }],
owners: [
[
{
name: 'Some Owner',
ownerType: 'user',
email: '[email protected]',
imageUrl: 'url',
},
],
],
});

testServerRoute(server, '/api/admin/projects/projectId/features/myFlag', {
environments: [
{ name: 'development', type: 'development' },
{ name: 'production', type: 'production' },
],
children: [],
});
};

const setupNewProject = () => {
testServerRoute(server, '/api/admin/user', {
user: {
name: 'Unleash User',
},
});

testServerRoute(server, '/api/admin/personal-dashboard', {
projects: [
{
id: 'projectId',
memberCount: 3,
featureCount: 0,
health: 100,
name: 'projectName',
},
],
flags: [],
});

testServerRoute(server, '/api/admin/personal-dashboard/projectId', {
onboardingStatus: { status: 'onboarding-started' },
insights: {
avgHealthCurrentWindow: null,
avgHealthPastWindow: null,
},
latestEvents: [],
roles: [],
owners: [
[
{
name: 'Some Owner',
ownerType: 'user',
email: '[email protected]',
imageUrl: 'url',
},
],
],
});

testServerRoute(server, '/api/admin/projects/projectId/features/myFlag', {
environments: [
{ name: 'development', type: 'development' },
{ name: 'production', type: 'production' },
],
children: [],
});
};

// @ts-ignore
HTMLCanvasElement.prototype.getContext = () => {};

test('Render personal dashboard for a long running project', async () => {
setupLongRunningProject();
render(<PersonalDashboard />);

const welcomeDialogClose = await screen.findByText(
"Got it, let's get started!",
);

fireEvent.click(welcomeDialogClose);

await screen.findByText('Welcome Unleash User');
await screen.findByText('projectName');
await screen.findByText('10'); // members
await screen.findByText('100'); // features
await screen.findByText('80%'); // health

await screen.findByText(
'We have gathered projects and flags you have favorited or owned',
);
await screen.findByText('Project Insight');
await screen.findByText('70%'); // avg health past window
await screen.findByText('someone created a flag');
await screen.findByText('Member');

await screen.findByText('myFlag');
await screen.findByText('No feature flag metrics data');
await screen.findByText('production');
await screen.findByText('Last 48 hours');
});

test('Render personal dashboard for a new project', async () => {
setupNewProject();
render(<PersonalDashboard />);

await screen.findByText('Welcome Unleash User');
await screen.findByText('projectName');
await screen.findByText('Setup incomplete');
await screen.findByText('3'); // members
await screen.findByText('0'); // features
await screen.findByText('100%'); // health

await screen.findByText('Create a feature flag');
await screen.findByText('Connect an SDK');
await screen.findByText('You have no project roles in this project.');
await screen.findByText(
'You have not created or favorited any feature flags. Once you do, they will show up here.',
);

await screen.findByText('No feature flag metrics data');
});
Loading