|
| 1 | +import * as React from 'react'; |
| 2 | +import { render, screen, fireEvent } from '@testing-library/react'; |
| 3 | + |
| 4 | +import { Basic } from './InPlaceEditor.stories'; |
| 5 | + |
| 6 | +describe('InPlaceEditor', () => { |
| 7 | + it('should render the field value on mount', async () => { |
| 8 | + render(<Basic delay={0} />); |
| 9 | + await screen.findByText('John Doe'); |
| 10 | + }); |
| 11 | + it('should reveal an input on click', async () => { |
| 12 | + render(<Basic delay={0} />); |
| 13 | + const value = await screen.findByText('John Doe'); |
| 14 | + value.click(); |
| 15 | + await screen.findByDisplayValue('John Doe'); |
| 16 | + }); |
| 17 | + it('should let the user change the value', async () => { |
| 18 | + render(<Basic delay={0} />); |
| 19 | + const value = await screen.findByText('John Doe'); |
| 20 | + value.click(); |
| 21 | + const input = await screen.findByDisplayValue('John Doe'); |
| 22 | + fireEvent.change(input, { target: { value: 'Jane Doe' } }); |
| 23 | + fireEvent.blur(input); |
| 24 | + await screen.findByText('Jane Doe'); |
| 25 | + }); |
| 26 | + it('should revert to the previous version on error', async () => { |
| 27 | + render(<Basic delay={0} updateFails />); |
| 28 | + const value = await screen.findByText('John Doe'); |
| 29 | + value.click(); |
| 30 | + const input = await screen.findByDisplayValue('John Doe'); |
| 31 | + fireEvent.change(input, { target: { value: 'Jane Doe' } }); |
| 32 | + fireEvent.blur(input); |
| 33 | + await screen.findByText('Jane Doe'); |
| 34 | + await screen.findByText('John Doe'); |
| 35 | + }); |
| 36 | + describe('notifyOnSuccess', () => { |
| 37 | + it('should show a notification on success', async () => { |
| 38 | + render(<Basic delay={0} notifyOnSuccess />); |
| 39 | + const value = await screen.findByText('John Doe'); |
| 40 | + value.click(); |
| 41 | + const input = await screen.findByDisplayValue('John Doe'); |
| 42 | + fireEvent.change(input, { target: { value: 'Jane Doe' } }); |
| 43 | + fireEvent.blur(input); |
| 44 | + await screen.findByText('Element updated'); |
| 45 | + }); |
| 46 | + }); |
| 47 | + describe('showButtons', () => { |
| 48 | + it('should render save and cancel buttons', async () => { |
| 49 | + render(<Basic delay={0} showButtons />); |
| 50 | + const value = await screen.findByText('John Doe'); |
| 51 | + value.click(); |
| 52 | + await screen.findByLabelText('Save'); |
| 53 | + await screen.findByLabelText('Cancel'); |
| 54 | + }); |
| 55 | + }); |
| 56 | +}); |
0 commit comments