Configuring the Unit Tests — GSoC 2022 Week 4

Piumal Rathnayake
2 min readJul 9, 2022

--

Vector created by upklyak — www.freepik.com

Hey everyone! It’s the end of another week of GSoC 2022. You may remember that I mentioned about a test configuration problem in my Week 2 blog post. All the unit tests I had written were failing due to a reacti8next translation issue. When running the tests, it just took the keys of the translations instead of the translated values, even after creating a mock function for the useTranslation hook.

So I created a draft pull request with my configuration and asked for a solution via the openmrs3-helpme slack channel. And my mentor replied by saying that we could use this kind of mock function if I want to test the translations:

import translations from '../../translations/en.json';

jest.mock('react-i18next', () => ({
useTranslation: () => ({
t: (k, o) => translations[k] ?? (o && o.defaultValue) ?? (typeof o === 'string' ? o : k),
}),
}));

My problem was solved with his suggestion. However, he told me that it’s fine to check only the translation keys when writing the unit tests. And he suggested that we could use the E2E tests to test the translations. Therefore, I’ll be updating my pull request by writing the remaining unit tests to work with the translation keys.

Meanwhile, I kept working on the Import Component of the OCL Subscription Module. It’s the UI used for triggerring an Import from OCL using the saved subscription. You can read my previous blog post to learn more about how this component works.

Anyway, I was able to complete the Import functionality and create a pull request. It is still under review and will be merged soon. Also, I did a small demo about this component at the Weekly Squad call of the OpenMRS Microfrontend squad.

That's how the week went. See you in the next blog post. Until then, Bye!!

--

--

Piumal Rathnayake
Piumal Rathnayake

Written by Piumal Rathnayake

I'm a Computer Engineering Undergraduate at University of Peradeniya, Sri Lanka. And I also work as a software engineer at Sustainable Education Foundation.