test: adapt tests to use dynamic props for breadcrumbs
This commit is contained in:
parent
ba0925f598
commit
1959fee39c
1 changed files with 10 additions and 21 deletions
|
@ -1,3 +1,4 @@
|
|||
import { faker } from '@faker-js/faker';
|
||||
import React from 'react';
|
||||
import { render, screen, waitFor } from '../../../../../../tests/test-utils';
|
||||
import { AppWithInfo } from '../../../../core/types';
|
||||
|
@ -9,7 +10,7 @@ import { AppDetailsPage } from './AppDetailsPage';
|
|||
describe('AppDetailsPage', () => {
|
||||
it('should render', async () => {
|
||||
// Arrange
|
||||
render(<AppDetailsPage appId="nothing" />);
|
||||
render(<AppDetailsPage appId="nothing" refTitle="" refSlug="" />);
|
||||
|
||||
// Assert
|
||||
await waitFor(() => {
|
||||
|
@ -17,22 +18,6 @@ describe('AppDetailsPage', () => {
|
|||
});
|
||||
});
|
||||
|
||||
it('should correctly pass the appId to the AppDetailsContainer', async () => {
|
||||
// Arrange
|
||||
const props = AppDetailsPage.getInitialProps?.({ query: { id: 'random' } } as any);
|
||||
|
||||
// Assert
|
||||
expect(props).toHaveProperty('appId', 'random');
|
||||
});
|
||||
|
||||
it('should transform the appId to a string', async () => {
|
||||
// Arrange
|
||||
const props = AppDetailsPage.getInitialProps?.({ query: { id: [123] } } as any);
|
||||
|
||||
// Assert
|
||||
expect(props).toHaveProperty('appId', '123');
|
||||
});
|
||||
|
||||
it('should set the breadcrumb prop of the Layout component to an array containing two elements with the correct name and href properties', async () => {
|
||||
// Arrange
|
||||
const app = createAppEntity({}) as AppWithInfo;
|
||||
|
@ -42,7 +27,11 @@ describe('AppDetailsPage', () => {
|
|||
response: app,
|
||||
}),
|
||||
);
|
||||
render(<AppDetailsPage appId={app.id} />);
|
||||
|
||||
const testSlug = faker.lorem.slug();
|
||||
const testTitle = faker.lorem.sentence();
|
||||
|
||||
render(<AppDetailsPage appId={app.id} refSlug={testSlug} refTitle={testTitle} />);
|
||||
await waitFor(() => {
|
||||
expect(screen.getByTestId('app-details')).toBeInTheDocument();
|
||||
});
|
||||
|
@ -52,10 +41,10 @@ describe('AppDetailsPage', () => {
|
|||
const breadcrumbsLinks = await screen.findAllByTestId('breadcrumb-link');
|
||||
|
||||
// Assert
|
||||
expect(breadcrumbs[0]).toHaveTextContent('Apps');
|
||||
expect(breadcrumbsLinks[0]).toHaveAttribute('href', '/apps');
|
||||
expect(breadcrumbs[0]).toHaveTextContent(testTitle);
|
||||
expect(breadcrumbsLinks[0]).toHaveAttribute('href', `/${testSlug}`);
|
||||
|
||||
expect(breadcrumbs[1]).toHaveTextContent(app.info.name);
|
||||
expect(breadcrumbsLinks[1]).toHaveAttribute('href', `/apps/${app.id}`);
|
||||
expect(breadcrumbsLinks[1]).toHaveAttribute('href', `/${testSlug}/${app.id}`);
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Add table
Reference in a new issue