diff --git a/.betterer.results b/.betterer.results index cccbb6fad1b..2ddef2a2f99 100644 --- a/.betterer.results +++ b/.betterer.results @@ -110,9 +110,6 @@ exports[`no enzyme tests`] = { "public/app/features/alerting/TestRuleResult.test.tsx:2358420489": [ [0, 19, 13, "RegExp match", "2409514259"] ], - "public/app/features/api-keys/ApiKeysAddedModal.test.tsx:3246264379": [ - [0, 20, 13, "RegExp match", "2409514259"] - ], "public/app/features/dashboard/components/ShareModal/ShareLink.test.tsx:2357087833": [ [0, 35, 13, "RegExp match", "2409514259"] ], diff --git a/public/app/features/api-keys/ApiKeysAddedModal.test.tsx b/public/app/features/api-keys/ApiKeysAddedModal.test.tsx index 35e0a556e76..b6342923402 100644 --- a/public/app/features/api-keys/ApiKeysAddedModal.test.tsx +++ b/public/app/features/api-keys/ApiKeysAddedModal.test.tsx @@ -1,27 +1,41 @@ -import { shallow } from 'enzyme'; +import { render, screen } from '@testing-library/react'; import React from 'react'; import { ApiKeysAddedModal, Props } from './ApiKeysAddedModal'; -const setup = (propOverrides?: object) => { +describe('ApiKeysAddedModal', () => { const props: Props = { onDismiss: jest.fn(), - apiKey: 'api key test', + apiKey: 'myApiKey', rootPath: 'test/path', }; - Object.assign(props, propOverrides); + it('should render without throwing', () => { + expect(() => render()).not.toThrow(); + }); - const wrapper = shallow(); + it('displays the apiKey in a readOnly input', () => { + render(); + const input = screen.getByRole('textbox'); + expect(input).toHaveValue(props.apiKey); + expect(input).toHaveAttribute('readonly'); + }); - return { - wrapper, - }; -}; + it('has a `Copy to clipboard` button', () => { + render(); + expect(screen.getByRole('button', { name: 'Copy' })).toBeInTheDocument(); + }); + + it('displays the correct curl path', () => { + render(); + expect( + screen.getByText('curl -H "Authorization: Bearer myApiKey" test/path/api/dashboards/home') + ).toBeInTheDocument(); + }); -describe('Render', () => { - it('should render component', () => { - const { wrapper } = setup(); - expect(wrapper).toMatchSnapshot(); + it('calls onDismiss when the modal is closed', () => { + render(); + screen.getByRole('button', { name: 'Close dialogue' }).click(); + expect(props.onDismiss).toHaveBeenCalled(); }); }); diff --git a/public/app/features/api-keys/__snapshots__/ApiKeysAddedModal.test.tsx.snap b/public/app/features/api-keys/__snapshots__/ApiKeysAddedModal.test.tsx.snap deleted file mode 100644 index 2a5670c70f1..00000000000 --- a/public/app/features/api-keys/__snapshots__/ApiKeysAddedModal.test.tsx.snap +++ /dev/null @@ -1,52 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`Render should render component 1`] = ` - - - - - Copy - - } - id="Key" - readOnly={true} - value="api key test" - /> - - - It is not stored in this form, so be sure to copy it now. - - - You can authenticate a request using the Authorization HTTP header, example: - - - curl -H "Authorization: Bearer - api key test - " - test/path - /api/dashboards/home - - -`;
- You can authenticate a request using the Authorization HTTP header, example: -
- curl -H "Authorization: Bearer - api key test - " - test/path - /api/dashboards/home -