Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cb 5753 u tests #2964

Merged
merged 8 commits into from
Oct 18, 2024
Merged

Cb 5753 u tests #2964

merged 8 commits into from
Oct 18, 2024

Conversation

devnaumov
Copy link
Member

No description provided.

@devnaumov devnaumov requested review from sergeyteleshev and Wroud and removed request for sergeyteleshev October 6, 2024 19:53
clientActivityService.updateActivity();
expect(clientActivityService.isActive).toBe(true);

jest.advanceTimersByTime(1000 * 60);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it is fine to use INACTIVE_PERIOD_TIME const here

Comment on lines 48 to 53
clientActivityService.updateActivity();
expect(setTimeout).toHaveBeenCalledTimes(1);

clientActivityService.updateActivity();
expect(clearTimeout).toHaveBeenCalledTimes(1);
expect(setTimeout).toHaveBeenCalledTimes(2);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would be nice to emulate running time here

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can randomly tick in range from 0 to INACTIVE_PERIOD_TIME - 1

Comment on lines 57 to 61
clientActivityService.updateActivity();
clientActivityService.resetActivity();

expect(clientActivityService.isActive).toBe(false);
expect(clearTimeout).toHaveBeenCalled();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here for running time. I suggest to emulate cases like it is actually happening

Comment on lines 65 to 71
const onActiveStateChangeSpy = jest.spyOn(clientActivityService.onActiveStateChange, 'execute');

clientActivityService.updateActivity();
expect(onActiveStateChangeSpy).toHaveBeenCalledWith(true);

jest.advanceTimersByTime(1000 * 60);
expect(onActiveStateChangeSpy).toHaveBeenCalledWith(false);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dont forget to mock Executor also so the test is more moduled. cause if something goes wrong in Executor logic, this test is gonna be fallen as well

Comment on lines 27 to 36
it('should set supported languages and default to first supported language', () => {
const locales: ILocale[] = [
{ isoCode: 'de', name: 'German', nativeName: 'Deutsch' },
{ isoCode: 'es', name: 'Spanish', nativeName: 'Español' },
];

service.setSupportedLanguages(locales);
expect(service.supportedLanguages.length).toBe(2);
expect(service.currentLanguage).toBe('de');
});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please, split this to 2 different tests:

  • should set supported languages
  • should set default supported language


it('should throw error if there are no supported languages', () => {
service.supportedLanguages = [];
expect(() => service.currentLanguage).toThrowError('No language is available');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this seems weird that getter can throw an error. I suggest to add TODO to refactor this logic somewhen in the LocalizationService.ts

@sergeyteleshev sergeyteleshev self-requested a review October 16, 2024 12:51
@Wroud Wroud merged commit 115cfb3 into devel Oct 18, 2024
6 of 7 checks passed
@Wroud Wroud deleted the CB-5753-u-tests branch October 18, 2024 05:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants