2022-06-13 08:52:17 -05:00
|
|
|
|
import { render, screen } from '@testing-library/react';
|
2022-04-22 08:33:13 -05:00
|
|
|
|
import React from 'react';
|
|
|
|
|
|
2018-09-27 04:26:47 -05:00
|
|
|
|
import { ApiKeysAddedModal, Props } from './ApiKeysAddedModal';
|
|
|
|
|
|
2022-06-13 08:52:17 -05:00
|
|
|
|
describe('ApiKeysAddedModal', () => {
|
2018-09-27 04:26:47 -05:00
|
|
|
|
const props: Props = {
|
2021-04-28 08:22:28 -05:00
|
|
|
|
onDismiss: jest.fn(),
|
2022-06-13 08:52:17 -05:00
|
|
|
|
apiKey: 'myApiKey',
|
2018-09-27 04:26:47 -05:00
|
|
|
|
rootPath: 'test/path',
|
|
|
|
|
};
|
|
|
|
|
|
2022-06-13 08:52:17 -05:00
|
|
|
|
it('should render without throwing', () => {
|
|
|
|
|
expect(() => render(<ApiKeysAddedModal {...props} />)).not.toThrow();
|
|
|
|
|
});
|
2018-09-27 04:26:47 -05:00
|
|
|
|
|
2022-06-13 08:52:17 -05:00
|
|
|
|
it('displays the apiKey in a readOnly input', () => {
|
|
|
|
|
render(<ApiKeysAddedModal {...props} />);
|
|
|
|
|
const input = screen.getByRole('textbox');
|
|
|
|
|
expect(input).toHaveValue(props.apiKey);
|
|
|
|
|
expect(input).toHaveAttribute('readonly');
|
|
|
|
|
});
|
2018-09-27 04:26:47 -05:00
|
|
|
|
|
2022-06-13 08:52:17 -05:00
|
|
|
|
it('has a `Copy to clipboard` button', () => {
|
|
|
|
|
render(<ApiKeysAddedModal {...props} />);
|
|
|
|
|
expect(screen.getByRole('button', { name: 'Copy' })).toBeInTheDocument();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('displays the correct curl path', () => {
|
|
|
|
|
render(<ApiKeysAddedModal {...props} />);
|
|
|
|
|
expect(
|
|
|
|
|
screen.getByText('curl -H "Authorization: Bearer myApiKey" test/path/api/dashboards/home')
|
|
|
|
|
).toBeInTheDocument();
|
|
|
|
|
});
|
2018-09-27 04:26:47 -05:00
|
|
|
|
|
2022-06-13 08:52:17 -05:00
|
|
|
|
it('calls onDismiss when the modal is closed', () => {
|
|
|
|
|
render(<ApiKeysAddedModal {...props} />);
|
|
|
|
|
screen.getByRole('button', { name: 'Close dialogue' }).click();
|
|
|
|
|
expect(props.onDismiss).toHaveBeenCalled();
|
2018-09-27 04:26:47 -05:00
|
|
|
|
});
|
|
|
|
|
});
|