ebi-gene-expression-group / atlas-components

Front end components of Expression Atlas and Single Cell Expression Atlas
3 stars 3 forks source link

📦 scxa-gene-search-form 💬 Feature #182401190 – Allow empty label in gene search form #114

Closed alfonsomunozpomer closed 2 years ago

alfonsomunozpomer commented 2 years ago

I would consider this a poster boy of migrating tests done in Enzyme to Testing Library.

Going into a bit more detail, I changed the nesting of the HTML elements to correctly link the <label> to the <input> inside the React Select component. This is due to the fact that Testing Library would complain about the lack of a <form> tag in the rendered HTML.

I decided not to use data-testid so that app code wouldn’t get “contaminated” by test-only code, althought that means that getting any <input> in GeneSearchForm requires using getAll... and then specifying a hard-coded index in the array, which might be going too deep into implementation-specific details.

Another big change, after Testing Library recommendation, is to remove fetch-mock and use whatwg-fetch with Mock Service Worker (msw). In this way we get a full-fledged fetch implementation that works closer to how a browser would. The test code becomes a bit more boilerplate-y and imperative, but hopefully tests will be more robust.

At the end of the day this is what we have:

--------------------|---------|----------|---------|---------|-------------------
File                | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s 
--------------------|---------|----------|---------|---------|-------------------
All files           |   96.92 |    95.45 |      96 |   96.55 |                   
 __test__/utils     |     100 |      100 |     100 |     100 |                   
  searchExamples.js |     100 |      100 |     100 |     100 |                   
  species.js        |     100 |      100 |     100 |     100 |                   
 src                |   96.29 |    95.45 |      95 |   96.15 |                   
  Autocomplete.js   |   86.66 |    92.85 |   85.71 |   86.66 | 20,45             
  GeneSearchForm.js |     100 |    94.44 |     100 |     100 | 34                
  LabelledSelect.js |     100 |      100 |     100 |     100 |                   
  SearchExamples.js |     100 |      100 |     100 |     100 |                   
--------------------|---------|----------|---------|---------|-------------------