Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate enzyme Dialog tests to React Testing Library #6760

Merged
merged 14 commits into from
Aug 8, 2022

Conversation

b3h3m0th
Copy link
Contributor

@b3h3m0th b3h3m0th commented Aug 2, 2022

What's in this PR?

Dialog component unit test migration enzyme --> RTL

);

expect(view.find('Dialog > Portal').at(0).render()).toMatchSnapshot();
expect(screen.getByText('My dialog content')).toBeInTheDocument();
Copy link
Contributor Author

@b3h3m0th b3h3m0th Aug 2, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't really know how to match a snapshot here because the <Dialog/> is rendered inside of a React Portal. I assume that is the reason why the regular container snapshot only outputs <div/> instead of a nice component snapshot of the <Dialog/>. I have already posted a question on SO.

In the meantime I added a test case that checks whether an element with the passed children text is in the document. Neither am I sure if that can replace the snapshot 100% nor if that is a bulletproof solution... probably not.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not 100% sure but can you do a snapshot to document.body.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe this discussion can help yout to find a solution here: testing-library/react-testing-library#62

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've already checked out that discussion but probably wasn't reading it carefully enough the first time. Anyway I made it work by snapshotting the baseElement instead of the container (both are properties returned by render()).

@b3h3m0th b3h3m0th marked this pull request as ready for review August 2, 2022 13:17
@alexander-schranz alexander-schranz marked this pull request as draft August 2, 2022 20:04
@alexander-schranz alexander-schranz added the DX Affecting the end developer label Aug 2, 2022
@b3h3m0th b3h3m0th marked this pull request as ready for review August 3, 2022 06:54
@niklasnatter niklasnatter merged commit 61a5e6b into sulu:2.4 Aug 8, 2022
niklasnatter added a commit that referenced this pull request Aug 15, 2022
* Setup @testing-library/react as replacement for enzyme (#6711)

* Fix webspace name with special characters in it (#6714)

* Migrate enzyme Badge tests to React Testing Library (#6719)

* Migrate enzyme ButtonGroup tests to React Testing Library (#6726)

* Migrate enzyme Card & CardCollection tests to React Testing Library (#6727)

* Migrate enzyme Button tests to React Testing Library (#6721)

* Migrate enzyme CharacterCounter tests to React Testing Library (#6730)

* Fix ImageMap with custom admin path (#6729)

* Migrate enzyme CirclularProgressbar tests to React Testing Library (#6733)

* Migrate enzyme Chip tests to React Testing Library (#6732)

* Migrate enzyme Checkbox & CheckboxGroup tests to React Testing Library (#6731)

* Migrate enzyme CroppedText tests to React Testing Library (#6735)

* Migrate enzyme Breadcrumb tests to React Testing Library (#6725)

* Migrate enzyme Divider tests to React Testing Library (#6736)

* Migrate enzyme DropdownButton tests to React Testing Library (#6737)

* Migrate enzyme Folder & FolderList tests to React Testing Library (#6742)

* Migrate enzyme Field, Form & Section tests to React Testing Library (#6743)

* Migrate enzyme GhostIndicator tests to React Testing Library (#6745)

* Migrate enzyme Heading tests to React Testing Library (#6747)

* Migrate enzyme Loader tests to React Testing Library (#6750)

* Migrate enzyme Masonry tests to React Testing Library (#6752)

* Migrate enzyme Menu tests to React Testing Library (#6754)

* Migrate enzyme PermissionHint tests to React Testing Library (#6755)

* Migrate enzyme Toggler tests to React Testing Library (#6756)

* Migrate enzyme Snackbar tests to React Testing Library (#6757)

* Migrate enzyme Backdrop tests to React Testing Library (#6758)

* Migrate enzyme AutoCompletePopover tests to React Testing Library  (#6713)

* Migrate enzyme Block tests to React Testing Library (#6720)

* Migrate enzyme Grid tests to React Testing Library (#6746)

* Migrate enzyme Matrix tests to React Testing Library (#6762)

* Fix code style after php-cs-fixer update (#6772)

* Fix code styl eof PhpWebspaceCollectionDumperTest

* Fix php-cs-fix

* Fix php-cs

* Migrate enzyme Email tests to React Testing Library (#6738)

* added enzyme duplicate test file

* WIP migrated tests, added snapshots

* added comment

* added icon click test

* WIP added test

* migrated redirect test

* fixed snapshots

* fixed review

* Update src/Sulu/Bundle/AdminBundle/Resources/js/components/Input/Input.js

Co-authored-by: niklasnatter <niklas.natter@gmail.com>

* Migrate enzyme Icon tests to React Testing Library (#6748)

* added duplicate enzyme test file

* WIP added icon tests

* finished test migration

* Migrate enzyme Input tests to React Testing Library (#6751)

* added duplicate enzyme test file

* migrated first tests

* migrated render tests

* WIP added partial change test

* WIP added alternative solution

* WIP adapted input change test

* added input callback test

* finally fixed input somehow

* removed enzyme duplicate test file

* added missing snapshots

* Migrate enzyme PublishIndicator tests to React Testing Library (#6759)

migrated tests

* Migrate enzyme Dialog tests to React Testing Library (#6760)

* Migrate enzyme Dialog tests to React Testing Library

* migrated dialog tests

* udpated test

* added disabled test

* adde large class test

* added loading test

* removed unused destructured variable

* added closed test

* added click callback test

* added cancel callback test

* added snackbar test

* added unknown error display test

* migrated snackbar click callback test, fixed snapshot, removed duplicate enzyme test file

* fixed dialog snapshot & updated getByText queries to regex

* Migrate enzyme TextArea tests to React Testing Library (#6766)

* Migrate enzyme TextArea tests to React Testing Library

* added snapshot tests

* migrated tests

* Migrate enzyme Phone tests to React Testing Library (#6770)

* Migrate enzyme Phone tests to React Testing Library

* added iconclick test

* added iconclick test

* migrated tests

* removed duplicate enzyme test file & fixed snapshots

* Migrate enzyme Url tests to React Testing Library (#6771)

* Migrate enzyme Url tests to React Testing Library

* migrated protocol and path init test

* migrated tests

* migrated invalid url test

* added reset undefined test

* migrated remove error on valid email change test

* migrated remove error on change field test

* migrate onchange callback protocol change test

* migrate onchange callback on path change

* added migrated tests

* migrated undefined email test

* added correct email test

* migrate test

* migrate blur test

* migrate onblur change test

* added default prop call tests

* removed duplicate enzyme test file & update snapshots

* Migrate enzyme Switch tests to React Testing Library (#6775)

* Migrate enzyme Switch tests to React Testing Library

* removed stopPropagation test

* removed duplicate enzyme test file & fixed snapshots

* Migrate enzyme SingleItemSelection tests to React Testing Library (#6776)

* migrated snapshot tests

* migrated tests, fixed snapshots, removed duplicate enzyme test file

* Migrate enzyme PasswordConfirmation tests to React Testing Library (#6778)

* Migrate enzyme PasswordConfirmation tests to React Testing Library

* migrated passwordconfirmation tests

* added snapshots

* Migrate enzyme Navigation tests to React Testing Library (#6779)

* Migrate enzyme Navigation tests to React Testing Library

* migrated navigation component unit tests

* migrated usersection enzyme tests to RTL

* updated by text queries to regex

* Migrate enzyme SegmentCounter tests to React Testing Library (#6780)

* Fix eslint errors in javascript test cases (#6782)

* Use userEvent instead of fireEvent for simulating user interactions in javascript tests (#6783)

* Update snackbar snapshot

* Update Input snapshots

* Update email snapshots

* Update checkbox snapshots

* Update phone snapshots

* Update PasswordConfirmation snapshots

* Update Block Snapshots

* Migrate missing enzyme Block tests to React Testing Library (#6786)

* Migrate enzyme Radio tests to React Testing Library (#6777)

* Migrate enzyme SingleSelect tests to React Testing Library (#6781)

* Update phpstan-baseline.neon

* Fix merge error in RadioGroup.test.js

Co-authored-by: mamazu <14860264+mamazu@users.noreply.github.com>
Co-authored-by: Behemoth <54234287+b3h3m0th@users.noreply.github.com>
Co-authored-by: Luca Colombo <luca.colombo@newvisibility.it>
Co-authored-by: Simon Ostini <simonostini@gmail.com>
Co-authored-by: Alexander Schranz <alexander@sulu.io>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
DX Affecting the end developer
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants