Skip to content

Commit

Permalink
Api hookup (#395) (#396)
Browse files Browse the repository at this point in the history
  • Loading branch information
yzlucas authored Jan 6, 2025
1 parent 33f364a commit 5895792
Show file tree
Hide file tree
Showing 22 changed files with 972 additions and 573 deletions.
8 changes: 0 additions & 8 deletions client/wfprev-war/src/main/angular/src/app/app.component.html
Original file line number Diff line number Diff line change
@@ -1,13 +1,5 @@
<div>
<app-app-header></app-app-header>
<div class="create-project-button-row">
<button class="create-project-button" (click)="createNewProject()">
<span class="button-text">
<img alt="create-project" class="icon" src="/assets/add-button.svg">
Create New Project
</span>
</button>
</div>
<nav class="nav-class">
<div>
<span class="span-class" [class.active]="activeRoute === 'list'" (click)="setActive('list')">
Expand Down
27 changes: 0 additions & 27 deletions client/wfprev-war/src/main/angular/src/app/app.component.scss
Original file line number Diff line number Diff line change
Expand Up @@ -30,31 +30,4 @@
background-color: #0056b3;
color: white;
}
}

.create-project-button-row{
text-align: right;
padding:12px 27px;
.create-project-button{
cursor: pointer;
display: inline-flex;
padding: 10px 16px;
justify-content: center;
align-items: center;
gap: 10px;
border-radius: 8px;
background: #013366;
.button-text{
color: #FFF;
font-family: "BCSans", "Noto Sans", Verdana, Arial, sans-serif;
font-size: 12px;
font-style: normal;
font-weight: 400;
line-height: normal;
.icon{
vertical-align: text-bottom;
padding-right: 5px;
}
}
}
}
113 changes: 50 additions & 63 deletions client/wfprev-war/src/main/angular/src/app/app.component.spec.ts
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
});
});
9 changes: 0 additions & 9 deletions client/wfprev-war/src/main/angular/src/app/app.component.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { Component } from '@angular/core';
import { MatDialog } from '@angular/material/dialog';
import { Router } from '@angular/router';
import { CreateNewProjectDialogComponent } from 'src/app/components/create-new-project-dialog/create-new-project-dialog.component';
import { ResourcesRoutes } from 'src/app/utils';
import { AppConfigService } from 'src/app/services/app-config.service';
import { TokenService } from 'src/app/services/token.service';
Expand Down Expand Up @@ -37,12 +36,4 @@ export class AppComponent {
goHome(): void {
this.router.navigate([ResourcesRoutes.LANDING]); // Navigate back to the home page
}

createNewProject(): void {
this.dialog.open(CreateNewProjectDialogComponent, {
width: '880px',
disableClose: true,
hasBackdrop: true,
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
<label>Business Area<span class="required">*</span></label>
<select formControlName="businessArea">
<option value="">select...</option>
<option *ngFor="let area of businessAreas" [value]="area">{{ area }}</option>
<option *ngFor="let area of businessAreas" [value]="area.programAreaGuid">{{ area.programAreaName }}</option>
</select>
</div>
</div>
Expand All @@ -38,28 +38,28 @@
<label>Forest Region<span class="required">*</span></label>
<select formControlName="forestRegion">
<option value="">select...</option>
<option *ngFor="let region of forestRegions" [value]="region">{{ region }}</option>
<option *ngFor="let region of forestRegions" [value]="region.orgUnitId">{{ region.orgUnitName }}</option>
</select>
</div>
<div class="form-field">
<label>Forest District<span class="required">*</span></label>
<select formControlName="forestDistrict">
<option value="">select...</option>
<option *ngFor="let district of forestDistricts" [value]="district">{{ district }}</option>
<option *ngFor="let district of forestDistricts" [value]="district.orgUnitId">{{ district.orgUnitName }}</option>
</select>
</div>
<div class="form-field">
<label>BC Parks Region<span class="required">*</span></label>
<select formControlName="bcParksRegion">
<option value="">select...</option>
<option *ngFor="let region of bcParksRegions" [value]="region">{{ region }}</option>
<option *ngFor="let region of bcParksRegions" [value]="region.orgUnitId">{{ region.orgUnitName }}</option>
</select>
</div>
<div class="form-field">
<label>BC Parks Section<span class="required">*</span></label>
<select formControlName="bcParksSection">
<option value="">select...</option>
<option *ngFor="let section of bcParksSections" [value]="section">{{ section }}</option>
<option *ngFor="let section of bcParksSections" [value]="section.orgUnitId">{{ section.orgUnitName }}</option>
</select>
</div>
</div>
Expand Down
Loading

0 comments on commit 5895792

Please sign in to comment.