1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-09-19 17:52:45 +02:00
unleash.unleash/frontend/src/component/segments/SegmentProjectAlert.test.tsx
Thomas Heartman dba1c90db8
Feat: show change request data on segment project usage page (#5410)
Show usage in change requests if that'd cause you to not be able to move
the segment into a project.

- [x] ~Relies on changes from #5407 (and #5405, #5406) to go through
first.~


![image](https://github.com/Unleash/unleash/assets/17786332/e6b84664-db86-457e-885f-a86c95bc46ec)
2023-11-28 10:01:56 +01:00

61 lines
2.0 KiB
TypeScript

import React from 'react';
import { render } from 'utils/testRenderer';
import { screen } from '@testing-library/react';
import { SegmentProjectAlert } from './SegmentProjectAlert';
describe('SegmentDeleteUsedSegment', () => {
it('should link to change requests for change request strategies', async () => {
const projectId = 'project1';
const strategies = [
{
projectId,
featureName: 'feature1',
strategyName: 'flexible rollout',
environment: 'default',
changeRequest: { id: 1, title: null },
},
{
projectId,
featureName: 'feature1',
strategyName: 'flexible rollout',
environment: 'default',
changeRequest: { id: 2, title: 'My cool CR' },
},
];
const projectsUsed = [...new Set(strategies.map((s) => s.projectId))];
render(
<SegmentProjectAlert
projects={[]}
availableProjects={[]}
projectsUsed={projectsUsed}
strategies={strategies}
/>,
);
const links = await screen.findAllByRole('link');
expect(links).toHaveLength(strategies.length + projectsUsed.length);
const [projectLink, crLink1, crLink2] = links;
expect(projectLink).toHaveTextContent(projectId);
expect(projectLink).toHaveAttribute('href', `/projects/${projectId}`);
expect(crLink1).toHaveTextContent('#1');
expect(crLink1).toHaveAccessibleDescription('Change request 1');
expect(crLink1).toHaveAttribute(
'href',
`/projects/${projectId}/change-requests/1`,
);
expect(crLink2).toHaveTextContent('#2 (My cool CR)');
expect(crLink2).toHaveAccessibleDescription('Change request 2');
expect(crLink2).toHaveAttribute(
'href',
`/projects/${projectId}/change-requests/2`,
);
});
});