// SPDX-FileCopyrightText: Copyright Orangebot, Inc. and Medplum contributors
// SPDX-License-Identifier: Apache-2.0
import { MantineProvider } from '@mantine/core';
import { Notifications, notifications } from '@mantine/notifications';
import { MockClient } from '@medplum/mock';
import { MedplumProvider } from '@medplum/react';
import { MemoryRouter } from 'react-router';
import { AppRoutes } from '../AppRoutes';
import { act, render, screen } from '../test-utils/render';
describe('DatabaseToolsPage', () => {
let medplum: MockClient;
function setup(): void {
render(
<MedplumProvider medplum={medplum}>
<MemoryRouter initialEntries={['/admin/super/db']} initialIndex={0}>
<MantineProvider>
<Notifications />
<AppRoutes />
</MantineProvider>
</MemoryRouter>
</MedplumProvider>
);
}
beforeEach(() => {
medplum = new MockClient();
jest.useFakeTimers();
jest.spyOn(medplum, 'isSuperAdmin').mockImplementation(() => true);
});
afterEach(async () => {
await act(async () => notifications.clean());
jest.clearAllMocks();
await act(async () => {
jest.runOnlyPendingTimers();
});
jest.useRealTimers();
});
test('Access denied', async () => {
jest.spyOn(medplum, 'isSuperAdmin').mockImplementationOnce(() => false);
setup();
expect(screen.getByText('Forbidden')).toBeInTheDocument();
});
test('GIN Indexes', async () => {
setup();
expect(screen.getByText('Configure GIN indexes')).toBeInTheDocument();
});
});