Feature/kids 839 implement allowance success screen #734
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
[## Description
](https://linear.app/givt/issue/KIDS-839/implement-allowance-success-screen)
This PR also illustrates the use of a UIModel and a golden test.
A UIModel contains all the information a widget needs to display information. By using a UIModel you can make the widget easily testable and the cubit can format the data it emits into a UIModel without having to know about the widget. The second part I will illustrate in a follow up PR. As this PR illustrates I'm not using a UIModel for every widget, just the ones I need to separate the logic from the UI. I use parameter functions to bubble up any user interactions. The top widget that does know about the cubit can then listen to those functions and perform the necessary calls on a cubit (will be illustrated in a follow-up PR).
A golden test is basically a "screenshot/rendering" test. By running
flutter test --update-goldens
you can create the "current/initial" screenshots of all widget golden tests ORflutter test <path_to_specific_test> --update-goldens
of a specific widget golden test. When you run the test/ all tests in the golden folder it will check for any differences. The slightest difference will make it fail so you can check wether the visual changes were intended or not. It also allows you to easily check for renderflex overflows, or even just visually test a screen without even connecting it in the app. And I also like it for reviewing PRs, people can visually see what I created. For illustration sake I added the "failures", (so I ran a test where i added a 6 to my string). The file being checked against is the "success_pages_golden.png" in the goldens folder of the test. All golden tests will be run when theflutter test
command is used.There's some things that needed 1-time setup in this PR. In order to write a golden test you really only need to look at the success_pages_golden_test.dart. In the
testGoldens
method you define the golden. You use agoldenBuilder
to build the golden and its test scenarios. ThecheckIfScreenMatchesGolden
is a convenience method to do the actual golden testing.If anything is unclear please comment and I can elaborate further.
Up-sides:
Down-sides of golden tests:
In my opinion golden test should only be used for components/ screens that are crucial and where changes truly need to be reviewed. We can also solve this problem by "tagging" tests and only run the tests that have a "crucial" tag.