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: apply prettier on angularoauth2app #11003

Merged
merged 1 commit into from
Sep 29, 2024
Merged
Show file tree
Hide file tree
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 @@ -56,14 +56,11 @@ public class AngularOauth2ModuleFactory {
private static final String TEST_IMPORTS =
"""
import { By } from '@angular/platform-browser';
import LoginComponent from './login/login.component';
""";
import LoginComponent from './login/login.component';""";
Copy link
Contributor

Choose a reason for hiding this comment

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

FYI you can also add a backslash for avoiding line break at end:

Suggested change
import LoginComponent from './login/login.component';""";
import LoginComponent from './login/login.component';\
""";


private static final ElementReplacer TEST_NEEDLE = lineAfterRegex("^\\s+it\\('should have appName',[^}]+\\}\\);");

private static final String LOGIN_IMPORT =
"""
import LoginComponent from './login/login.component';
""";
private static final String LOGIN_IMPORT = "import LoginComponent from './login/login.component';";

private static final String OAUTH2_AUTH_SERVICE_IMPORT =
"""
Expand Down Expand Up @@ -94,13 +91,9 @@ public class AngularOauth2ModuleFactory {

it('should display login component', () => {
expect(fixture.debugElement.query(By.directive(LoginComponent))).toBeTruthy();
});
""";
});""";

private static final String HTTP_AUTH_INTERCEPTOR_IMPORT =
"""
import { httpAuthInterceptor } from './app/auth/http-auth.interceptor';
""";
private static final String HTTP_AUTH_INTERCEPTOR_IMPORT = "import { httpAuthInterceptor } from './app/auth/http-auth.interceptor';";

private static final JHipsterSource SOURCE = from("client/angular/security/oauth2/src/main/webapp/app");

Expand Down Expand Up @@ -146,18 +139,18 @@ public JHipsterModule buildModule(JHipsterModuleProperties properties) {
.and()
.in(path("src/main/webapp/main.ts"))
.add(EXISTING_PROVIDE_HTTP_CLIENT_NEEDLE, "provideHttpClient(withInterceptors([httpAuthInterceptor])),")
.add(fileStart(), HTTP_AUTH_INTERCEPTOR_IMPORT)
.add(lineAfterRegex("from '@angular/router';"), HTTP_AUTH_INTERCEPTOR_IMPORT)
.and()
.in(path("src/main/webapp/app/app.component.ts"))
.add(FILLED_STANDALONE_NEEDLE, "$1, LoginComponent]")
.add(fileStart(), OAUTH2_AUTH_SERVICE_IMPORT)
.add(fileStart(), LOGIN_IMPORT)
.add(lineAfterRegex("from '@angular/core';"), OAUTH2_AUTH_SERVICE_IMPORT)
.add(lineAfterRegex("from './auth/oauth2-auth.service';"), LOGIN_IMPORT)
.add(INJECT_NEEDLE, INJECT_IMPORT)
.add(APPNAME_NEEDLE, INJECT_OAUTH2_AUTH_SERVICE)
.add(lineAfterRegex("this.appName.set\\('" + properties.projectBaseName().name() + "'\\);"), INIT_AUTHENTICATION)
.and()
.in(path("src/main/webapp/app/app.component.spec.ts"))
.add(fileStart(), TEST_IMPORTS)
.add(lineAfterRegex("from '@angular/router';"), TEST_IMPORTS)
.add(TEST_NEEDLE, LOGIN_COMPONENT_TEST.indent(indentation.spacesCount() * 2))
.and()
.in(path("src/main/webapp/app/app.component.html"))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { TestBed } from '@angular/core/testing';
import { HttpClient, HttpRequest, provideHttpClient, withInterceptors } from '@angular/common/http';
import { HttpTestingController, provideHttpClientTesting } from '@angular/common/http/testing';
import { TestBed } from '@angular/core/testing';

import { httpAuthInterceptor } from './http-auth.interceptor';
import { Oauth2AuthService } from './oauth2-auth.service';
Expand Down Expand Up @@ -31,7 +31,6 @@ describe('httpAuthInterceptor', () => {
});

describe('Bearer Token', () => {

it('should add authorization bearer token in request when defined', () => {
jest.spyOn(oauth2AuthService, 'token', 'get').mockReturnValue(TOKEN);
const originalRequest = buildHttpRequest();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { HttpEvent, HttpHandlerFn, HttpRequest } from '@angular/common/http';
import { inject } from '@angular/core';
import { HttpRequest, HttpEvent, HttpHandlerFn } from '@angular/common/http';
import { Observable } from 'rxjs';
import { Oauth2AuthService } from './oauth2-auth.service';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Oauth2AuthService } from './oauth2-auth.service';
import { TestBed } from '@angular/core/testing';
import Keycloak, { KeycloakInitOptions } from 'keycloak-js';
import { lastValueFrom } from 'rxjs';
import { Oauth2AuthService } from './oauth2-auth.service';
import SpyInstance = jest.SpyInstance;

jest.mock('keycloak-js', () => ({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { ComponentFixture, ComponentFixtureAutoDetect, TestBed } from '@angular/core/testing';

import { By } from '@angular/platform-browser';
import LoginComponent from './login.component';
import { Oauth2AuthService } from '../auth/oauth2-auth.service';
import LoginComponent from './login.component';

describe('LoginComponent', () => {
let fixture: ComponentFixture<LoginComponent>;
Expand All @@ -11,7 +11,7 @@ describe('LoginComponent', () => {

beforeEach(async () => {
await TestBed.configureTestingModule({
providers: [{ provide: ComponentFixtureAutoDetect, useValue: true }]
providers: [{ provide: ComponentFixtureAutoDetect, useValue: true }],
}).compileComponents();
});

Expand Down