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

[Angular] Refactor this code to not nest functions more than 4 levels deep #26654

Merged
merged 1 commit into from
Jul 11, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ function accountWithAuthorities(authorities: string[]): Account {
};
}

const mockFn = (value: string | null): jest.Mock<string | null> => jest.fn(() => value);

describe('Account Service', () => {
let service: AccountService;
<%_ if (generateUserManagement) { _%>
Expand Down Expand Up @@ -174,7 +176,7 @@ describe('save', () => {
describe('should change the language on authentication if necessary', () => {
it('should change language if user has not changed language manually', () => {
// GIVEN
mockStorageService.getLocale = jest.fn(() => null);
mockStorageService.getLocale = mockFn(null);

// WHEN
service.identity().subscribe();
Expand All @@ -186,7 +188,7 @@ describe('save', () => {

it('should not change language if user has changed language manually', () => {
// GIVEN
mockStorageService.getLocale = jest.fn(() => 'sessionLang');
mockStorageService.getLocale = mockFn('sessionLang');

// WHEN
service.identity().subscribe();
Expand All @@ -201,7 +203,7 @@ describe('save', () => {
describe('navigateToStoredUrl', () => {
it('should navigate to the previous stored url post successful authentication', () => {
// GIVEN
mockStorageService.getUrl = jest.fn(() => 'admin/users?page=0');
mockStorageService.getUrl = mockFn('admin/users?page=0');

// WHEN
service.identity().subscribe();
Expand All @@ -226,7 +228,7 @@ describe('save', () => {

it('should not navigate to the previous stored url when no such url exists post successful authentication', () => {
// GIVEN
mockStorageService.getUrl = jest.fn(() => null);
mockStorageService.getUrl = mockFn(null);

// WHEN
service.identity().subscribe();
Expand Down
Loading