-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
22 changed files
with
972 additions
and
573 deletions.
There are no files selected for viewing
8 changes: 0 additions & 8 deletions
8
client/wfprev-war/src/main/angular/src/app/app.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
113 changes: 50 additions & 63 deletions
113
client/wfprev-war/src/main/angular/src/app/app.component.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,98 +1,85 @@ | ||
import { ComponentFixture, TestBed } from '@angular/core/testing'; | ||
import { RouterTestingModule } from '@angular/router/testing'; | ||
import { AppComponent } from './app.component'; | ||
import { Router } from '@angular/router'; | ||
import { By } from '@angular/platform-browser'; | ||
import { Location } from '@angular/common'; | ||
import { BrowserAnimationsModule } from '@angular/platform-browser/animations'; | ||
import { provideHttpClientTesting } from '@angular/common/http/testing'; | ||
import { provideHttpClient } from '@angular/common/http'; | ||
import { AppConfigService } from './services/app-config.service'; | ||
import { ApplicationConfig } from './interfaces/application-config'; | ||
import { LibraryConfig } from './config/library-config'; | ||
import { AppConfigService } from 'src/app/services/app-config.service'; | ||
import { LibraryConfig } from 'src/app/config/library-config'; | ||
import { ResizablePanelComponent } from 'src/app/components/resizable-panel/resizable-panel.component'; | ||
|
||
// Create a mock configuration | ||
const mockApplicationConfig: ApplicationConfig = { | ||
// Mock configuration | ||
const mockApplicationConfig = { | ||
application: { acronym: "WFPREV", version: "0.0.0", baseUrl: "", environment: "DEV" }, | ||
rest: {}, | ||
webade: { oauth2Url: "", clientId: "", authScopes: ""} | ||
webade: { oauth2Url: "", clientId: "", authScopes: "" }, | ||
}; | ||
|
||
const mockLibraryConfig = { | ||
configurationPath: '/mock/config/path', | ||
}; | ||
|
||
// Mock AppConfigService | ||
class MockAppConfigService { | ||
private appConfig: ApplicationConfig = mockApplicationConfig; | ||
private appConfig = mockApplicationConfig; | ||
|
||
async loadAppConfig(): Promise<void> { | ||
// Simulate config loading | ||
return Promise.resolve(); | ||
} | ||
|
||
getConfig(): ApplicationConfig { | ||
getConfig(): any { | ||
return this.appConfig; | ||
} | ||
} | ||
|
||
const mockLibraryConfig = { | ||
configurationPath: '/mock/config/path' | ||
}; | ||
|
||
|
||
describe('AppComponent', () => { | ||
let router: Router; | ||
let location: Location; | ||
let fixture: ComponentFixture<AppComponent>; | ||
let app: AppComponent; | ||
describe('ResizablePanelComponent', () => { | ||
let component: ResizablePanelComponent; | ||
let fixture: ComponentFixture<ResizablePanelComponent>; | ||
|
||
beforeEach(async () => { | ||
await TestBed.configureTestingModule({ | ||
imports: [RouterTestingModule.withRoutes([])], // Setup RouterTestingModule properly | ||
declarations: [AppComponent], | ||
providers: [provideHttpClient(), // Add HTTP client provider | ||
provideHttpClientTesting(), | ||
{ | ||
provide: AppConfigService, | ||
useClass: MockAppConfigService | ||
}, | ||
{ | ||
provide: LibraryConfig, | ||
useValue: mockLibraryConfig | ||
}] | ||
imports: [ | ||
BrowserAnimationsModule, // Necessary for Angular Material animations | ||
], | ||
providers: [ | ||
provideHttpClient(), // Add HTTP client provider | ||
provideHttpClientTesting(), // Add HTTP client testing provider | ||
{ | ||
provide: AppConfigService, | ||
useClass: MockAppConfigService, | ||
}, | ||
{ | ||
provide: LibraryConfig, | ||
useValue: mockLibraryConfig, | ||
}, | ||
], | ||
}).compileComponents(); | ||
|
||
router = TestBed.inject(Router); | ||
location = TestBed.inject(Location); | ||
fixture = TestBed.createComponent(AppComponent); | ||
app = fixture.componentInstance; | ||
router.initialNavigation(); | ||
}); | ||
const appConfigService = TestBed.inject(AppConfigService); | ||
await appConfigService.loadAppConfig(); // Simulate configuration loading | ||
|
||
it('should create the app', () => { | ||
expect(app).toBeTruthy(); | ||
fixture = TestBed.createComponent(ResizablePanelComponent); | ||
component = fixture.componentInstance; | ||
fixture.detectChanges(); | ||
}); | ||
|
||
it('should navigate to "list" route and set active route', async () => { | ||
spyOn(router, 'navigate'); | ||
app.setActive('list'); | ||
expect(app.activeRoute).toBe('list'); | ||
expect(router.navigate).toHaveBeenCalledWith(['list']); | ||
it('should create the component', () => { | ||
expect(component).toBeTruthy(); | ||
}); | ||
|
||
it('should navigate to "map" route and set active route', async () => { | ||
spyOn(router, 'navigate'); | ||
app.setActive('map'); | ||
expect(app.activeRoute).toBe('map'); | ||
expect(router.navigate).toHaveBeenCalledWith(['map']); | ||
it('should initialize with default values', () => { | ||
expect(component.panelWidth).toBe('50vw'); // Default panel width | ||
expect(component.breakpoints).toEqual([5, 50, 90]); // Default breakpoints | ||
expect(component.selectedTabIndex).toBe(0); // Default selected tab index | ||
}); | ||
|
||
it('should add "active" class to the map menu item when activeRoute is "map"', () => { | ||
app.activeRoute = 'map'; | ||
fixture.detectChanges(); | ||
|
||
const mapMenuItem = fixture.debugElement.query( | ||
By.css('.span-class[class="span-class active"]') // Or more simply: '.span-class.active' | ||
); | ||
it('should resize the panel and emit panelResized event', () => { | ||
spyOn(component.panelResized, 'emit'); // Spy on the EventEmitter | ||
component.resizePanel(75); // Resize to 75vw | ||
expect(component.panelWidth).toBe('75vw'); | ||
expect(component.panelResized.emit).toHaveBeenCalled(); // Ensure the event is emitted | ||
}); | ||
|
||
expect(mapMenuItem).not.toBeNull(); | ||
expect(mapMenuItem.nativeElement.classList).toContain('active'); | ||
it('should update selectedTabIndex when selectTab is called', () => { | ||
component.selectTab(2); // Select the third tab | ||
expect(component.selectedTabIndex).toBe(2); // Check updated tab index | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.