|
@@ -5,111 +5,119 @@ import { Route } from 'react-router';
|
|
|
import { clusterSchemaPath } from 'lib/paths';
|
|
|
import { screen, waitFor } from '@testing-library/dom';
|
|
|
import {
|
|
|
- schemasFulfilledState,
|
|
|
+ schemasInitialState,
|
|
|
schemaVersion,
|
|
|
} from 'redux/reducers/schemas/__test__/fixtures';
|
|
|
import fetchMock from 'fetch-mock';
|
|
|
+import ClusterContext, {
|
|
|
+ ContextProps,
|
|
|
+ initialValue as contextInitialValue,
|
|
|
+} from 'components/contexts/ClusterContext';
|
|
|
+import { RootState } from 'redux/interfaces';
|
|
|
+
|
|
|
+import { versionPayload, versionEmptyPayload } from './fixtures';
|
|
|
|
|
|
const clusterName = 'testClusterName';
|
|
|
-const subject = 'schema7_1';
|
|
|
+const schemasAPILatestUrl = `/api/clusters/${clusterName}/schemas/${schemaVersion.subject}/latest`;
|
|
|
+const schemasAPIVersionsUrl = `/api/clusters/${clusterName}/schemas/${schemaVersion.subject}/versions`;
|
|
|
+
|
|
|
+const renderComponent = (
|
|
|
+ initialState: RootState['schemas'] = schemasInitialState,
|
|
|
+ context: ContextProps = contextInitialValue
|
|
|
+) => {
|
|
|
+ return render(
|
|
|
+ <Route path={clusterSchemaPath(':clusterName', ':subject')}>
|
|
|
+ <ClusterContext.Provider value={context}>
|
|
|
+ <Details />
|
|
|
+ </ClusterContext.Provider>
|
|
|
+ </Route>,
|
|
|
+ {
|
|
|
+ pathname: clusterSchemaPath(clusterName, schemaVersion.subject),
|
|
|
+ preloadedState: {
|
|
|
+ schemas: initialState,
|
|
|
+ },
|
|
|
+ }
|
|
|
+ );
|
|
|
+};
|
|
|
|
|
|
describe('Details', () => {
|
|
|
- describe('for an initial state', () => {
|
|
|
- it('renders pageloader', () => {
|
|
|
- render(
|
|
|
- <Route path={clusterSchemaPath(':clusterName', ':subject')}>
|
|
|
- <Details />
|
|
|
- </Route>,
|
|
|
- {
|
|
|
- pathname: clusterSchemaPath(clusterName, subject),
|
|
|
- preloadedState: {},
|
|
|
- }
|
|
|
- );
|
|
|
- expect(screen.getByRole('progressbar')).toBeInTheDocument();
|
|
|
- expect(screen.queryByText(subject)).not.toBeInTheDocument();
|
|
|
- expect(screen.queryByText('Edit Schema')).not.toBeInTheDocument();
|
|
|
- expect(screen.queryByText('Remove Schema')).not.toBeInTheDocument();
|
|
|
- });
|
|
|
- });
|
|
|
+ afterEach(() => fetchMock.reset());
|
|
|
|
|
|
- describe('for a loaded scheme', () => {
|
|
|
- beforeEach(() => {
|
|
|
- render(
|
|
|
- <Route path={clusterSchemaPath(':clusterName', ':subject')}>
|
|
|
- <Details />
|
|
|
- </Route>,
|
|
|
- {
|
|
|
- pathname: clusterSchemaPath(clusterName, subject),
|
|
|
- preloadedState: {
|
|
|
- loader: {
|
|
|
- 'schemas/fetch': 'fulfilled',
|
|
|
- },
|
|
|
- schemas: schemasFulfilledState,
|
|
|
- },
|
|
|
- }
|
|
|
+ describe('fetch failed', () => {
|
|
|
+ beforeEach(async () => {
|
|
|
+ const schemasAPILatestMock = fetchMock.getOnce(schemasAPILatestUrl, 404);
|
|
|
+ const schemasAPIVersionsMock = fetchMock.getOnce(
|
|
|
+ schemasAPIVersionsUrl,
|
|
|
+ 404
|
|
|
);
|
|
|
+ renderComponent();
|
|
|
+ await waitFor(() => {
|
|
|
+ expect(schemasAPILatestMock.called()).toBeTruthy();
|
|
|
+ });
|
|
|
+ await waitFor(() => {
|
|
|
+ expect(schemasAPIVersionsMock.called()).toBeTruthy();
|
|
|
+ });
|
|
|
});
|
|
|
|
|
|
- it('renders component with shema info', () => {
|
|
|
- expect(screen.getByText('Edit Schema')).toBeInTheDocument();
|
|
|
- });
|
|
|
-
|
|
|
- it('renders progressbar for versions block', () => {
|
|
|
+ it('renders pageloader', () => {
|
|
|
expect(screen.getByRole('progressbar')).toBeInTheDocument();
|
|
|
- expect(screen.queryByRole('table')).not.toBeInTheDocument();
|
|
|
+ expect(screen.queryByText(schemaVersion.subject)).not.toBeInTheDocument();
|
|
|
+ expect(screen.queryByText('Edit Schema')).not.toBeInTheDocument();
|
|
|
+ expect(screen.queryByText('Remove Schema')).not.toBeInTheDocument();
|
|
|
});
|
|
|
});
|
|
|
|
|
|
- describe('for a loaded scheme and versions', () => {
|
|
|
- afterEach(() => fetchMock.restore());
|
|
|
- it('renders versions table', async () => {
|
|
|
- const mock = fetchMock.getOnce(
|
|
|
- `/api/clusters/${clusterName}/schemas/${subject}/versions`,
|
|
|
- [schemaVersion]
|
|
|
- );
|
|
|
- render(
|
|
|
- <Route path={clusterSchemaPath(':clusterName', ':subject')}>
|
|
|
- <Details />
|
|
|
- </Route>,
|
|
|
- {
|
|
|
- pathname: clusterSchemaPath(clusterName, subject),
|
|
|
- preloadedState: {
|
|
|
- loader: {
|
|
|
- 'schemas/fetch': 'fulfilled',
|
|
|
- },
|
|
|
- schemas: schemasFulfilledState,
|
|
|
- },
|
|
|
- }
|
|
|
- );
|
|
|
- await waitFor(() => expect(mock.called()).toBeTruthy());
|
|
|
+ describe('fetch success', () => {
|
|
|
+ describe('has schema versions', () => {
|
|
|
+ beforeEach(async () => {
|
|
|
+ const schemasAPILatestMock = fetchMock.getOnce(
|
|
|
+ schemasAPILatestUrl,
|
|
|
+ schemaVersion
|
|
|
+ );
|
|
|
+ const schemasAPIVersionsMock = fetchMock.getOnce(
|
|
|
+ schemasAPIVersionsUrl,
|
|
|
+ versionPayload
|
|
|
+ );
|
|
|
+ renderComponent();
|
|
|
+ await waitFor(() => {
|
|
|
+ expect(schemasAPILatestMock.called()).toBeTruthy();
|
|
|
+ });
|
|
|
+ await waitFor(() => {
|
|
|
+ expect(schemasAPIVersionsMock.called()).toBeTruthy();
|
|
|
+ });
|
|
|
+ });
|
|
|
|
|
|
- expect(screen.queryByRole('progressbar')).not.toBeInTheDocument();
|
|
|
- expect(screen.getByRole('table')).toBeInTheDocument();
|
|
|
+ it('renders component with schema info', () => {
|
|
|
+ expect(screen.getByText('Edit Schema')).toBeInTheDocument();
|
|
|
+ expect(screen.queryByRole('progressbar')).not.toBeInTheDocument();
|
|
|
+ expect(screen.getByRole('table')).toBeInTheDocument();
|
|
|
+ });
|
|
|
});
|
|
|
|
|
|
- it('renders versions table with 0 items', async () => {
|
|
|
- const mock = fetchMock.getOnce(
|
|
|
- `/api/clusters/${clusterName}/schemas/${subject}/versions`,
|
|
|
- []
|
|
|
- );
|
|
|
- render(
|
|
|
- <Route path={clusterSchemaPath(':clusterName', ':subject')}>
|
|
|
- <Details />
|
|
|
- </Route>,
|
|
|
- {
|
|
|
- pathname: clusterSchemaPath(clusterName, subject),
|
|
|
- preloadedState: {
|
|
|
- loader: {
|
|
|
- 'schemas/fetch': 'fulfilled',
|
|
|
- },
|
|
|
- schemas: schemasFulfilledState,
|
|
|
- },
|
|
|
- }
|
|
|
- );
|
|
|
- await waitFor(() => expect(mock.called()).toBeTruthy());
|
|
|
+ describe('empty schema versions', () => {
|
|
|
+ beforeEach(async () => {
|
|
|
+ const schemasAPILatestMock = fetchMock.getOnce(
|
|
|
+ schemasAPILatestUrl,
|
|
|
+ schemaVersion
|
|
|
+ );
|
|
|
+ const schemasAPIVersionsMock = fetchMock.getOnce(
|
|
|
+ schemasAPIVersionsUrl,
|
|
|
+ versionEmptyPayload
|
|
|
+ );
|
|
|
+ renderComponent();
|
|
|
+ await waitFor(() => {
|
|
|
+ expect(schemasAPILatestMock.called()).toBeTruthy();
|
|
|
+ });
|
|
|
+ await waitFor(() => {
|
|
|
+ expect(schemasAPIVersionsMock.called()).toBeTruthy();
|
|
|
+ });
|
|
|
+ });
|
|
|
|
|
|
- expect(screen.getByRole('table')).toBeInTheDocument();
|
|
|
- expect(screen.getByText('No active Schema')).toBeInTheDocument();
|
|
|
+ // seems like incorrect behaviour
|
|
|
+ it('renders versions table with 0 items', () => {
|
|
|
+ expect(screen.getByRole('table')).toBeInTheDocument();
|
|
|
+ expect(screen.getByText('No active Schema')).toBeInTheDocument();
|
|
|
+ });
|
|
|
});
|
|
|
});
|
|
|
});
|