The problem with current integration of unit-tests on iOS is the fact that we depends on react dependency heavily which is available in example or FabricExample projects.
Of course I didn't want to duplicate tests (and there is no clear option on how to add them for KeyboardController.xcodeproj i. e. root) so I decided to create a new "HelloWorld" project and link files that I want to test.
Fortunately current codebase is designed quite well (thanks for supporting both architectures 😀), so I have a separated business-logic (keyboard frame tracking etc.) and consumers (react views/bridge bindings).
So I didn't make any modifications to the source code. The only one "suspicious" thing is adding extension for reactTag property (I rely on it in Extensions file and Extension file needs to be linked since ViewHierarchyNavigator uses UIResponder.current extension).
Unit tests approach
I decided to test everything as unit tests. Of course some of methods, such as becomeFirstResponder doesn't work (actually they work, but there is no way to check that method has been called as we can do in jest - and by default iOS doesn't provide any mocks).
So I've created TestableTextField/TestableTextView and for hierarchy creation used these classes.
Some of corresponding Android tests can not be ported to iOS:
get all inputs -> relies on window usage, and actual window doesn't contain any TextInputs -> most likely we need to pass params and pass a mock from unit tests but I don't want to change source code right now
testSetFocusToNextDoesNothingIfLastElement -> there is no way to check that view keeps focus
testSetFocusToPrevDoesNothingIfFirstElement -> there is no way to check that view keeps focus
But overall I'm happy to have at least something to have a better protection over accident changes that can break the library code.
CI integration
Also I added a job on CI to run these tests continuously.
📢 Changelog
CI
added a job for running unit-tests;
iOS
added KeyboardControllerNative project;
excluded KeyboardControllerNative from Pods (to prevent compilation errors);
JS
excluded KeyboardControllerNative from being published to npm;
🤔 How Has This Been Tested?
Tested locally and on CI.
📝 Checklist
[ ] CI successfully passed
[x] I added new mocks and corresponding unit-tests if library API was changed
📜 Description
Added native unit tests on iOS.
💡 Motivation and Context
Where to write unit tests?
The problem with current integration of unit-tests on iOS is the fact that we depends on
react
dependency heavily which is available inexample
orFabricExample
projects.Of course I didn't want to duplicate tests (and there is no clear option on how to add them for
KeyboardController.xcodeproj
i. e. root) so I decided to create a new "HelloWorld" project and link files that I want to test.Fortunately current codebase is designed quite well (thanks for supporting both architectures 😀), so I have a separated business-logic (keyboard frame tracking etc.) and consumers (react views/bridge bindings).
So I didn't make any modifications to the source code. The only one "suspicious" thing is adding extension for
reactTag
property (I rely on it in Extensions file and Extension file needs to be linked sinceViewHierarchyNavigator
usesUIResponder.current
extension).Unit tests approach
I decided to test everything as unit tests. Of course some of methods, such as
becomeFirstResponder
doesn't work (actually they work, but there is no way to check that method has been called as we can do in jest - and by default iOS doesn't provide any mocks).So I've created
TestableTextField
/TestableTextView
and for hierarchy creation used these classes.Some of corresponding Android tests can not be ported to iOS:
But overall I'm happy to have at least something to have a better protection over accident changes that can break the library code.
CI integration
Also I added a job on CI to run these tests continuously.
📢 Changelog
CI
iOS
KeyboardControllerNative
project;KeyboardControllerNative
from Pods (to prevent compilation errors);JS
KeyboardControllerNative
from being published tonpm
;🤔 How Has This Been Tested?
Tested locally and on CI.
📝 Checklist