Skip to content

Commit

Permalink
Update failing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
chidozieononiwu committed Sep 19, 2024
1 parent 3344d7c commit f33dfff
Show file tree
Hide file tree
Showing 9 changed files with 156 additions and 42 deletions.
Original file line number Diff line number Diff line change
@@ -1,14 +1,49 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';

import { ConversationPageComponent } from './conversation-page.component';
import { ActivatedRoute, convertToParamMap } from '@angular/router';
import { HttpClientTestingModule } from '@angular/common/http/testing';
import { ReviewPageLayoutComponent } from '../shared/review-page-layout/review-page-layout.component';
import { ConversationsComponent } from '../conversations/conversations.component';
import { NavBarComponent } from '../shared/nav-bar/nav-bar.component';
import { ReviewInfoComponent } from '../shared/review-info/review-info.component';
import { MenuModule } from 'primeng/menu';
import { FooterComponent } from '../shared/footer/footer.component';
import { MenubarModule } from 'primeng/menubar';
import { LanguageNamesPipe } from 'src/app/_pipes/language-names.pipe';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';

describe('ConversationPageComponent', () => {
let component: ConversationPageComponent;
let fixture: ComponentFixture<ConversationPageComponent>;

beforeEach(() => {
TestBed.configureTestingModule({
declarations: [ConversationPageComponent]
declarations: [
ConversationPageComponent,
ConversationsComponent,
NavBarComponent,
FooterComponent,
ReviewInfoComponent,
ReviewPageLayoutComponent,
LanguageNamesPipe
],
imports: [
BrowserAnimationsModule,
HttpClientTestingModule,
MenuModule,
MenubarModule
],
providers: [
{
provide: ActivatedRoute,
useValue: {
snapshot: {
paramMap: convertToParamMap({ reviewId: 'test' })
}
}
}
]
});
fixture = TestBed.createComponent(ConversationPageComponent);
component = fixture.componentInstance;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export class ConversationPageComponent {
private destroy$ = new Subject<void>();

constructor(private route: ActivatedRoute, private reviewsService: ReviewsService, private userProfileService: UserProfileService,
private apiRevisionsService: RevisionsService, private commentsService: CommentsService, private router: Router
private apiRevisionsService: RevisionsService, private commentsService: CommentsService
) {}

ngOnInit() {
Expand All @@ -52,11 +52,6 @@ export class ConversationPageComponent {
icon: 'bi bi-braces',
tooltip: 'API',
command: () => this.openLatestAPIReivisonForReview()
},
{
icon: 'bi bi-clock-history',
tooltip: 'Revisions',
command: () => this.router.navigate([`/revision/${this.reviewId}`])
}
];
}
Expand Down Expand Up @@ -91,6 +86,6 @@ export class ConversationPageComponent {

openLatestAPIReivisonForReview() {
const apiRevision = this.apiRevisions.find(x => x.apiRevisionType === "Automatic") ?? this.apiRevisions[0];
this.apiRevisionsService.openAPIRevisionPage(apiRevision, this.router.url);
this.apiRevisionsService.openAPIRevisionPage(apiRevision, this.route);
}
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,60 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';

import { RevisionPageComponent } from './revision-page.component';
import { ActivatedRoute, convertToParamMap } from '@angular/router';
import { HttpClientTestingModule } from '@angular/common/http/testing';
import { ReviewPageLayoutComponent } from '../shared/review-page-layout/review-page-layout.component';
import { NavBarComponent } from '../shared/nav-bar/nav-bar.component';
import { RevisionsListComponent } from '../revisions-list/revisions-list.component';
import { MessageService } from 'primeng/api';
import { ReviewInfoComponent } from '../shared/review-info/review-info.component';
import { MenubarModule } from 'primeng/menubar';
import { MenuModule } from 'primeng/menu';
import { FooterComponent } from '../shared/footer/footer.component';
import { ContextMenuModule } from 'primeng/contextmenu';
import { SidebarModule } from 'primeng/sidebar';
import { DropdownModule } from 'primeng/dropdown';
import { LanguageNamesPipe } from 'src/app/_pipes/language-names.pipe';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';

describe('RevisionPageComponent', () => {
let component: RevisionPageComponent;
let fixture: ComponentFixture<RevisionPageComponent>;

beforeEach(() => {
TestBed.configureTestingModule({
declarations: [RevisionPageComponent]
declarations: [
RevisionPageComponent,
NavBarComponent,
FooterComponent,
ReviewInfoComponent,
RevisionsListComponent,
ReviewPageLayoutComponent,
LanguageNamesPipe
],
imports: [
BrowserAnimationsModule,
HttpClientTestingModule,
MenubarModule,
MenuModule,
ContextMenuModule,
DropdownModule,
SidebarModule,
ReactiveFormsModule,
FormsModule
],
providers: [
{
provide: ActivatedRoute,
useValue: {
snapshot: {
paramMap: convertToParamMap({ reviewId: 'test' })
}
}
},
MessageService
]
});
fixture = TestBed.createComponent(RevisionPageComponent);
component = fixture.componentInstance;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export class RevisionPageComponent {

openLatestAPIReivisonForReview() {
const apiRevision = this.apiRevisions.find(x => x.apiRevisionType === "Automatic") ?? this.apiRevisions[0];
this.apiRevisionsService.openAPIRevisionPage(apiRevision, this.router.url);
this.apiRevisionsService.openAPIRevisionPage(apiRevision, this.route);
}

handleApiRevisionsEmitter(apiRevisions: APIRevision[]) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Component, EventEmitter, Input, OnChanges, OnInit, Output, SimpleChanges, ViewChild } from '@angular/core';
import { FormBuilder, FormGroup, Validators } from '@angular/forms';
import { Router } from '@angular/router';
import { ActivatedRoute, Router } from '@angular/router';
import { MenuItem, MessageService, SortEvent } from 'primeng/api';
import { FileSelectEvent, FileUpload } from 'primeng/fileupload';
import { Table, TableFilterEvent, TableLazyLoadEvent } from 'primeng/table';
Expand Down Expand Up @@ -77,7 +77,7 @@ export class RevisionsListComponent implements OnInit, OnChanges {

constructor(private apiRevisionsService: RevisionsService, private userProfileService: UserProfileService,
private configService: ConfigService, private fb: FormBuilder, private reviewsService: ReviewsService,
private router: Router, private messageService: MessageService) { }
private route: ActivatedRoute, private messageService: MessageService) { }

ngOnInit(): void {
this.createRevisionFilters();
Expand Down Expand Up @@ -240,14 +240,14 @@ export class RevisionsListComponent implements OnInit, OnChanges {
viewDiffOfSelectedAPIRevisions() {
if (this.selectedRevisions.length == 2)
{
this.apiRevisionsService.openDiffOfAPIRevisions(this.selectedRevisions[0], this.selectedRevisions[1], this.router.url);
this.apiRevisionsService.openDiffOfAPIRevisions(this.selectedRevisions[0], this.selectedRevisions[1], this.route);
}
}

viewRevision(apiRevision: APIRevision) {
if (!this.showDeletedAPIRevisions)
{
this.apiRevisionsService.openAPIRevisionPage(apiRevision, this.router.url);
this.apiRevisionsService.openAPIRevisionPage(apiRevision, this.route);
}
}

Expand Down Expand Up @@ -480,7 +480,7 @@ export class RevisionsListComponent implements OnInit, OnChanges {
this.createRevisionSidebarVisible = false;
this.creatingRevision = false;
this.crButtonText = "Create Review";
this.apiRevisionsService.openAPIRevisionPage(response, this.router.url);
this.apiRevisionsService.openAPIRevisionPage(response, this.route);
}
},
error: (error: any) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,34 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';

import { ReviewPageLayoutComponent } from './review-page-layout.component';
import { NavBarComponent } from '../nav-bar/nav-bar.component';
import { HttpClientTestingModule } from '@angular/common/http/testing';
import { ReviewInfoComponent } from '../review-info/review-info.component';
import { MenubarModule } from 'primeng/menubar';
import { MenuModule } from 'primeng/menu';
import { FooterComponent } from '../footer/footer.component';
import { LanguageNamesPipe } from 'src/app/_pipes/language-names.pipe';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';

describe('ReviewPageLayoutComponent', () => {
let component: ReviewPageLayoutComponent;
let fixture: ComponentFixture<ReviewPageLayoutComponent>;

beforeEach(() => {
TestBed.configureTestingModule({
declarations: [ReviewPageLayoutComponent]
declarations: [
ReviewPageLayoutComponent,
ReviewInfoComponent,
NavBarComponent,
FooterComponent,
LanguageNamesPipe
],
imports: [
BrowserAnimationsModule,
HttpClientTestingModule,
MenubarModule,
MenuModule
],
});
fixture = TestBed.createComponent(ReviewPageLayoutComponent);
component = fixture.componentInstance;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import { ActivatedRoute } from "@angular/router";
import { SCROLL_TO_NODE_QUERY_PARAM } from "./common-helpers";

export const REVIEW_PAGE_ROUTE_REGEX = "\/[a-z]+?\/[a-zA-Z0-9]+";
export const INDEX_PAGE_NAME = "Index";
export const REVIEW_PAGE_NAME = "Review";
export const CONVERSATION_PAGE_NAME = "Conversation";
export const REVISION_PAGE_NAME = "Revision";

export function getQueryParams(route: ActivatedRoute, excludedKeys: string[] = [SCROLL_TO_NODE_QUERY_PARAM]) {
return route.snapshot.queryParamMap.keys.reduce((params: { [key: string]: any; }, key) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { HttpClient, HttpHeaders, HttpParams } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { Observable, map } from 'rxjs';
import { Observable, map, take } from 'rxjs';


import { PaginatedResult } from 'src/app/_models/pagination';
import { APIRevision } from 'src/app/_models/revision';
import { ConfigService } from '../config/config.service';
import { REVIEW_PAGE_ROUTE_REGEX } from 'src/app/_helpers/router-helpers';

import { ActivatedRoute } from '@angular/router';
import { INDEX_PAGE_NAME } from 'src/app/_helpers/router-helpers';

@Injectable({
providedIn: 'root'
Expand Down Expand Up @@ -127,25 +127,30 @@ export class RevisionsService {
});
}

openDiffOfAPIRevisions(activeAPIRevision: APIRevision, diffAPIRevision: APIRevision, currentRoute: string) {
const target = (currentRoute.match(REVIEW_PAGE_ROUTE_REGEX)) ? '_self' : '_blank';

if (activeAPIRevision.files[0].parserStyle === "tree") {
window.open(`/review/${activeAPIRevision.reviewId}?activeApiRevisionId=${activeAPIRevision.id}&diffApiRevisionId=${diffAPIRevision.id}`, target);
} else {
window.open(this.configService.webAppUrl + `Assemblies/Review/${activeAPIRevision.reviewId}?revisionId=${activeAPIRevision.id}&diffOnly=False&doc=False&diffRevisionId=${diffAPIRevision.id}`, target);
}
openDiffOfAPIRevisions(activeAPIRevision: APIRevision, diffAPIRevision: APIRevision, currentRoute: ActivatedRoute) {
this.isIndexPage(currentRoute).pipe(take(1)).subscribe(
isIndexPage => {
const target = isIndexPage ? '_blank' : '_self';
if (activeAPIRevision.files[0].parserStyle === "tree") {
window.open(`/review/${activeAPIRevision.reviewId}?activeApiRevisionId=${activeAPIRevision.id}&diffApiRevisionId=${diffAPIRevision.id}`, target);
} else {
window.open(this.configService.webAppUrl + `Assemblies/Review/${activeAPIRevision.reviewId}?revisionId=${activeAPIRevision.id}&diffOnly=False&doc=False&diffRevisionId=${diffAPIRevision.id}`, target);
}
}
);
}

openAPIRevisionPage(apiRevision: APIRevision, currentRoute: string) {
console.log(currentRoute);
const target = (currentRoute.match(REVIEW_PAGE_ROUTE_REGEX)) ? '_self' : '_blank';

if (apiRevision.files[0].parserStyle === "tree") {
window.open(`/review/${apiRevision.reviewId}?activeApiRevisionId=${apiRevision.id}`, target);
} else {
window.open(this.configService.webAppUrl + `Assemblies/Review/${apiRevision.reviewId}?revisionId=${apiRevision.id}`, target);
}
openAPIRevisionPage(apiRevision: APIRevision, currentRoute: ActivatedRoute) {
this.isIndexPage(currentRoute).pipe(take(1)).subscribe(
isIndexPage => {
const target = isIndexPage ? '_blank' : '_self';
if (apiRevision.files[0].parserStyle === "tree") {
window.open(`/review/${apiRevision.reviewId}?activeApiRevisionId=${apiRevision.id}`, target);
} else {
window.open(this.configService.webAppUrl + `Assemblies/Review/${apiRevision.reviewId}?revisionId=${apiRevision.id}`, target);
}
}
);
}

updateSelectedReviewers(reviewId: string, apiRevisionId: string, reviewers: Set<string>): Observable<APIRevision> {
Expand All @@ -160,4 +165,14 @@ export class RevisionsService {
withCredentials: true,
});
}

private isIndexPage(currentRoute: ActivatedRoute): Observable<boolean> {
return currentRoute.data.pipe(
map(data => {
const pageName = data['pageName'];
console.log("Page Name", pageName);
return data['pageName'] === INDEX_PAGE_NAME;
})
);
}
}
10 changes: 5 additions & 5 deletions src/dotnet/APIView/ClientSPA/src/app/app-routing.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@ import { RouterModule, Routes } from '@angular/router';
import { IndexPageComponent } from './_components/index-page/index-page.component';
import { AuthGuard } from './_guards/auth.guard';
import { FeaturesGuard } from './_guards/features.guard';
import { ReviewPageComponent } from './_components/review-page/review-page.component';
import { CONVERSATION_PAGE_NAME, INDEX_PAGE_NAME, REVIEW_PAGE_NAME, REVISION_PAGE_NAME } from './_helpers/router-helpers';

const routes: Routes = [
{ path: '', component: IndexPageComponent, canActivate: [AuthGuard, FeaturesGuard] },
{ path: '', component: IndexPageComponent, canActivate: [AuthGuard, FeaturesGuard], data: { pageName: INDEX_PAGE_NAME } },
{ path: '',
runGuardsAndResolvers: 'always',
canActivate: [AuthGuard],
children: [
{ path: 'review/:reviewId', loadChildren: () => import('./_modules/review-page.module').then(m => m.ReviewPageModule) }, // Lazy load review page module
{ path: 'conversation/:reviewId', loadChildren: () => import('./_modules/conversation-page.module').then(m => m.ConversationPageModule) },
{ path: 'revision/:reviewId', loadChildren: () => import('./_modules/revision-page.module').then(m => m.RevisionPageModule) }
{ path: 'review/:reviewId', loadChildren: () => import('./_modules/review-page.module').then(m => m.ReviewPageModule), data: { pageName: REVIEW_PAGE_NAME } }, // Lazy load review page module
{ path: 'conversation/:reviewId', loadChildren: () => import('./_modules/conversation-page.module').then(m => m.ConversationPageModule), data: { pageName: CONVERSATION_PAGE_NAME} },
{ path: 'revision/:reviewId', loadChildren: () => import('./_modules/revision-page.module').then(m => m.RevisionPageModule), data: { pageName: REVISION_PAGE_NAME } }
]
},
{ path: '**', component: IndexPageComponent, pathMatch: 'full' }
Expand Down

0 comments on commit f33dfff

Please sign in to comment.