hide empty groups in beautiful forms

fix calc for whether a group should be hidden
previous fix was overzealous (4b1478e2)
fix readable forms test bug

refactor code to be nicer for tests
and harder to introduce this test bug

also use assertJSONEqual for nicer comparison
Merge pull request #3724 from dimagi/hide-empty-groups

hide empty groups in beautiful forms