|
| 1 | +/* |
| 2 | + * Copyright 2023 Adobe. All rights reserved. |
| 3 | + * This file is licensed to you under the Apache License, Version 2.0 (the "License"); |
| 4 | + * you may not use this file except in compliance with the License. You may obtain a copy |
| 5 | + * of the License at http://www.apache.org/licenses/LICENSE-2.0 |
| 6 | + * |
| 7 | + * Unless required by applicable law or agreed to in writing, software distributed under |
| 8 | + * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS |
| 9 | + * OF ANY KIND, either express or implied. See the License for the specific language |
| 10 | + * governing permissions and limitations under the License. |
| 11 | + */ |
| 12 | + |
| 13 | +import {screen, testSSR} from '@react-spectrum/test-utils'; |
| 14 | + |
| 15 | +describe('Dialog SSR', function () { |
| 16 | + it('should render without errors', async function () { |
| 17 | + await testSSR(__filename, ` |
| 18 | + import {Button, Dialog, DialogTrigger, Heading, Input, Label, Modal, TextField} from '../'; |
| 19 | +
|
| 20 | + <React.StrictMode> |
| 21 | + <DialogTrigger isOpen> |
| 22 | + <Button>Sign up…</Button> |
| 23 | + <Modal> |
| 24 | + <Dialog> |
| 25 | + {({ close }) => ( |
| 26 | + <form> |
| 27 | + <Heading>Sign up</Heading> |
| 28 | + <TextField autoFocus> |
| 29 | + <Label>First Name:</Label> |
| 30 | + <Input /> |
| 31 | + </TextField> |
| 32 | + <TextField> |
| 33 | + <Label>Last Name:</Label> |
| 34 | + <Input /> |
| 35 | + </TextField> |
| 36 | + <Button onPress={close}> |
| 37 | + Submit |
| 38 | + </Button> |
| 39 | + </form> |
| 40 | + )} |
| 41 | + </Dialog> |
| 42 | + </Modal> |
| 43 | + </DialogTrigger> |
| 44 | + </React.StrictMode> |
| 45 | + `, () => { |
| 46 | + // Assert that server rendered stuff into the HTML. |
| 47 | + let dialog = screen.queryByRole('dialog'); |
| 48 | + expect(dialog).toBeNull(); |
| 49 | + }); |
| 50 | + |
| 51 | + // Assert that hydrated UI matches what we expect. |
| 52 | + let dialog = screen.getByRole('dialog'); |
| 53 | + expect(dialog).toBeInTheDocument(); |
| 54 | + }); |
| 55 | +}); |
0 commit comments