forked from patternfly/patternfly-react
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: Migrate tests to RTL (6) (patternfly#7063)
* chore: migrate tests to rtl (6) * update comments * adding some tests back
- Loading branch information
Showing
75 changed files
with
5,687 additions
and
9,609 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
138 changes: 0 additions & 138 deletions
138
packages/react-console/src/components/AccessConsoles/__tests__/AccessConsole.test.tsx
This file was deleted.
Oops, something went wrong.
110 changes: 110 additions & 0 deletions
110
packages/react-console/src/components/AccessConsoles/__tests__/AccessConsoles.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
import React from 'react'; | ||
|
||
import { render, screen } from '@testing-library/react'; | ||
import userEvent from '@testing-library/user-event'; | ||
import '@testing-library/jest-dom'; | ||
|
||
import { AccessConsoles } from '../AccessConsoles'; | ||
import { SerialConsole } from '../../SerialConsole'; | ||
import { VncConsole } from '../../VncConsole'; | ||
import { DesktopViewer } from '../../DesktopViewer'; | ||
import { constants } from '../../common/constants'; | ||
|
||
const { SERIAL_CONSOLE_TYPE, LOADING } = constants; | ||
|
||
const MyVncConsoleTestWrapper = () => <p>VNC console text</p>; | ||
const SerialConsoleConnected = () => <p>Serial console text</p>; | ||
|
||
const vnc = { | ||
address: 'my.host.com', | ||
port: 5902, | ||
tlsPort: '5903' | ||
}; | ||
|
||
describe('AccessConsoles', () => { | ||
beforeAll(() => { | ||
window.HTMLCanvasElement.prototype.getContext = () => ({ canvas: {} } as any); | ||
}); | ||
|
||
test('with SerialConsole as a single child', () => { | ||
const { asFragment } = render( | ||
<AccessConsoles> | ||
<SerialConsole onData={jest.fn()} onConnect={jest.fn()} onDisconnect={jest.fn()} status={LOADING} /> | ||
</AccessConsoles> | ||
); | ||
expect(asFragment()).toMatchSnapshot(); | ||
}); | ||
|
||
test('with VncConsole as a single child', () => { | ||
const { asFragment } = render( | ||
<AccessConsoles> | ||
<VncConsole host="foo.bar.host" textDisconnected="Disconnected state text" /> | ||
</AccessConsoles> | ||
); | ||
expect(asFragment()).toMatchSnapshot(); | ||
}); | ||
|
||
test('with SerialConsole and VncConsole as children', () => { | ||
const { asFragment } = render( | ||
<AccessConsoles> | ||
<VncConsole host="foo.bar.host" textDisconnected="Disconnected state text" /> | ||
<SerialConsole onData={jest.fn()} onConnect={jest.fn()} onDisconnect={jest.fn()} status={LOADING} /> | ||
</AccessConsoles> | ||
); | ||
expect(asFragment()).toMatchSnapshot(); | ||
}); | ||
|
||
test('with wrapped SerialConsole as a child', () => { | ||
const { asFragment } = render( | ||
<AccessConsoles> | ||
<SerialConsoleConnected /> | ||
</AccessConsoles> | ||
); | ||
expect(asFragment()).toMatchSnapshot(); | ||
}); | ||
|
||
test('with preselected SerialConsole', () => { | ||
const { asFragment } = render( | ||
<AccessConsoles preselectedType={SERIAL_CONSOLE_TYPE}> | ||
<SerialConsole onData={jest.fn()} onConnect={jest.fn()} onDisconnect={jest.fn()} status={LOADING} /> | ||
</AccessConsoles> | ||
); | ||
|
||
expect(asFragment()).toMatchSnapshot(); | ||
}); | ||
|
||
test('switching SerialConsole and VncConsole', () => { | ||
render( | ||
<AccessConsoles> | ||
<MyVncConsoleTestWrapper /> | ||
<SerialConsole onData={jest.fn()} onConnect={jest.fn()} onDisconnect={jest.fn()} status={LOADING} /> | ||
</AccessConsoles> | ||
); | ||
|
||
// VNC (first option) is initially selected | ||
expect(screen.queryByText(/Loading/)).toBeNull(); | ||
expect(screen.getByText('VNC console text')).toBeInTheDocument(); | ||
|
||
// Open dropdown and select "Serial console" option | ||
userEvent.click(screen.getByRole('button', { name: 'Options menu' })); | ||
userEvent.click(screen.getByText('Serial console', { selector: 'button' })); | ||
|
||
// VNC content is no longer visible, and loading contents of the Serial console are visible. | ||
expect(screen.getByText(/Loading/)).toBeInTheDocument(); | ||
expect(screen.queryByText('VNC console text')).toBeNull(); | ||
}); | ||
|
||
test('Empty', () => { | ||
const { asFragment } = render(<AccessConsoles />); | ||
expect(asFragment()).toMatchSnapshot(); | ||
}); | ||
|
||
test('with DesktopViewer', () => { | ||
const { asFragment } = render( | ||
<AccessConsoles> | ||
<DesktopViewer vnc={vnc} /> | ||
</AccessConsoles> | ||
); | ||
expect(asFragment()).toMatchSnapshot(); | ||
}); | ||
}); |
Oops, something went wrong.