From bff86487b2a60dc080563f49566c3ce9fcbb59bf Mon Sep 17 00:00:00 2001 From: alicia pritchett Date: Tue, 1 Mar 2022 12:20:46 -0500 Subject: [PATCH] Add in differing buttons for differing environments (branches) and fix tests --- .../git-merge-dialog.component.spec.ts | 56 ++++++++++++++++-- .../git-repo-dialog.component.spec.ts | 57 +++++++++++++++++-- .../workflow-spec-list.component.html | 18 ++++-- .../workflow-spec-list.component.spec.ts | 3 + .../workflow-spec-list.component.ts | 32 +++++++---- 5 files changed, 142 insertions(+), 24 deletions(-) diff --git a/src/app/git-merge-dialog/git-merge-dialog.component.spec.ts b/src/app/git-merge-dialog/git-merge-dialog.component.spec.ts index 22546c5..7ea0493 100644 --- a/src/app/git-merge-dialog/git-merge-dialog.component.spec.ts +++ b/src/app/git-merge-dialog/git-merge-dialog.component.spec.ts @@ -1,17 +1,63 @@ -import { ComponentFixture, TestBed } from '@angular/core/testing'; +import {ComponentFixture, TestBed, waitForAsync} from '@angular/core/testing'; import { GitMergeDialogComponent } from './git-merge-dialog.component'; +import {HttpClientTestingModule, HttpTestingController} from "@angular/common/http/testing"; +import {BrowserAnimationsModule, NoopAnimationsModule} from "@angular/platform-browser/animations"; +import {FormsModule, ReactiveFormsModule} from "@angular/forms"; +import {MAT_DIALOG_DATA, MatDialog, MatDialogModule, MatDialogRef} from "@angular/material/dialog"; +import {MatFormFieldModule} from "@angular/material/form-field"; +import {MatIconModule} from "@angular/material/icon"; +import {MatInputModule} from "@angular/material/input"; +import {RouterTestingModule} from "@angular/router/testing"; +import {OpenFileDialogComponent} from "../_dialogs/open-file-dialog/open-file-dialog.component"; +import {ApiService, MockEnvironment} from "../../../../sartography-libraries/dist/sartography-workflow-lib"; +import {APP_BASE_HREF} from "@angular/common"; +import {Router} from "@angular/router"; describe('GitMergeDialogComponent', () => { let component: GitMergeDialogComponent; let fixture: ComponentFixture; + const mockRouter = {navigate: jasmine.createSpy('navigate')}; - beforeEach(async () => { - await TestBed.configureTestingModule({ - declarations: [ GitMergeDialogComponent ] + beforeEach(waitForAsync(() => { + TestBed.configureTestingModule({ + imports: [ + BrowserAnimationsModule, + FormsModule, + HttpClientTestingModule, + MatDialogModule, + MatFormFieldModule, + MatIconModule, + MatInputModule, + NoopAnimationsModule, + ReactiveFormsModule, + RouterTestingModule, + ], + declarations: [ OpenFileDialogComponent ], + providers: [ + ApiService, + {provide: 'APP_ENVIRONMENT', useClass: MockEnvironment}, + {provide: APP_BASE_HREF, useValue: ''}, + { + provide: MatDialogRef, + useValue: { + close: (dialogResult: any) => { + } + } + }, + { + provide: MatDialog, + useValue: { + close: (dialogResult: any) => { + } + } + }, + {provide: MAT_DIALOG_DATA, useValue: []}, + {provide: Router, useValue: mockRouter}, + ] }) .compileComponents(); - }); + })); beforeEach(() => { fixture = TestBed.createComponent(GitMergeDialogComponent); diff --git a/src/app/git-repo-dialog/git-repo-dialog.component.spec.ts b/src/app/git-repo-dialog/git-repo-dialog.component.spec.ts index 78341e2..30ee5b7 100644 --- a/src/app/git-repo-dialog/git-repo-dialog.component.spec.ts +++ b/src/app/git-repo-dialog/git-repo-dialog.component.spec.ts @@ -1,17 +1,64 @@ -import { ComponentFixture, TestBed } from '@angular/core/testing'; +import {ComponentFixture, TestBed, waitForAsync} from '@angular/core/testing'; import { GitRepoDialogComponent } from './git-repo-dialog.component'; +import {BrowserAnimationsModule, NoopAnimationsModule} from "@angular/platform-browser/animations"; +import {FormsModule, ReactiveFormsModule} from "@angular/forms"; +import {HttpClientTestingModule} from "@angular/common/http/testing"; +import {MAT_DIALOG_DATA, MatDialog, MatDialogModule, MatDialogRef} from "@angular/material/dialog"; +import {MatFormFieldModule} from "@angular/material/form-field"; +import {MatIconModule} from "@angular/material/icon"; +import {MatInputModule} from "@angular/material/input"; +import {RouterTestingModule} from "@angular/router/testing"; +import {OpenFileDialogComponent} from "../_dialogs/open-file-dialog/open-file-dialog.component"; +import {ApiService, MockEnvironment} from "../../../../sartography-libraries/dist/sartography-workflow-lib"; +import {APP_BASE_HREF} from "@angular/common"; +import {Router} from "@angular/router"; describe('GitRepoDialogComponent', () => { let component: GitRepoDialogComponent; let fixture: ComponentFixture; - beforeEach(async () => { - await TestBed.configureTestingModule({ - declarations: [ GitRepoDialogComponent ] +const mockRouter = {navigate: jasmine.createSpy('navigate')}; + + beforeEach(waitForAsync(() => { + TestBed.configureTestingModule({ + imports: [ + BrowserAnimationsModule, + FormsModule, + HttpClientTestingModule, + MatDialogModule, + MatFormFieldModule, + MatIconModule, + MatInputModule, + NoopAnimationsModule, + ReactiveFormsModule, + RouterTestingModule, + ], + declarations: [ OpenFileDialogComponent ], + providers: [ + ApiService, + {provide: 'APP_ENVIRONMENT', useClass: MockEnvironment}, + {provide: APP_BASE_HREF, useValue: ''}, + { + provide: MatDialogRef, + useValue: { + close: (dialogResult: any) => { + } + } + }, + { + provide: MatDialog, + useValue: { + close: (dialogResult: any) => { + } + } + }, + {provide: MAT_DIALOG_DATA, useValue: []}, + {provide: Router, useValue: mockRouter}, + ] }) .compileComponents(); - }); + })); beforeEach(() => { fixture = TestBed.createComponent(GitRepoDialogComponent); diff --git a/src/app/workflow-spec-list/workflow-spec-list.component.html b/src/app/workflow-spec-list/workflow-spec-list.component.html index bf02d35..1812c8c 100644 --- a/src/app/workflow-spec-list/workflow-spec-list.component.html +++ b/src/app/workflow-spec-list/workflow-spec-list.component.html @@ -8,10 +8,20 @@ -
- - - +
+ +
+
+ + +
+
+ +
+
+ + +
diff --git a/src/app/workflow-spec-list/workflow-spec-list.component.spec.ts b/src/app/workflow-spec-list/workflow-spec-list.component.spec.ts index 36b8caa..8008ac8 100644 --- a/src/app/workflow-spec-list/workflow-spec-list.component.spec.ts +++ b/src/app/workflow-spec-list/workflow-spec-list.component.spec.ts @@ -137,6 +137,9 @@ describe('WorkflowSpecListComponent', () => { specReq.flush(mockWorkflowSpecs); fixture.detectChanges(); expect(component.workflowSpecs.length).toBeGreaterThan(0); + + const gitReq = httpMock.expectOne('apiRoot/git_repo'); + expect(gitReq.request.method).toEqual('GET'); }); afterEach(() => { diff --git a/src/app/workflow-spec-list/workflow-spec-list.component.ts b/src/app/workflow-spec-list/workflow-spec-list.component.ts index 7d54dc7..84cd722 100644 --- a/src/app/workflow-spec-list/workflow-spec-list.component.ts +++ b/src/app/workflow-spec-list/workflow-spec-list.component.ts @@ -6,7 +6,6 @@ import { cloneDeep } from 'lodash'; import { ApiErrorsComponent, ApiService, - isNumberDefined, // moveArrayElementDown, // moveArrayElementUp, WorkflowSpec, @@ -60,6 +59,7 @@ export class WorkflowSpecListComponent implements OnInit { searchField: FormControl; library_toggle: boolean; merge_branch: string = 'branch' + branch: string = 'branch' constructor( private api: ApiService, @@ -82,9 +82,12 @@ export class WorkflowSpecListComponent implements OnInit { }); this.api.gitRepo().subscribe(gitRepo => { - if (gitRepo.merge_branch && gitRepo.merge_branch != 'all') { + if (gitRepo.merge_branch) { this.merge_branch = gitRepo.merge_branch; } + if (gitRepo.branch) { + this.branch = gitRepo.branch; + } }) this.searchField = new FormControl(); @@ -109,9 +112,11 @@ export class WorkflowSpecListComponent implements OnInit { } setCatByID(cat_id: string) { - this.api.getWorkflowSpecCategory(cat_id).subscribe( cat => { - this.selectedCat = cat; - }) + if (cat_id) { + this.api.getWorkflowSpecCategory(cat_id).subscribe(cat => { + this.selectedCat = cat; + }) + } } isSelected(cat: WorkflowSpecCategoryGroup) { @@ -129,7 +134,7 @@ export class WorkflowSpecListComponent implements OnInit { editWorkflowSpec(state: String, selectedSpec?: WorkflowSpec) { - const hasDisplayOrder = selectedSpec && isNumberDefined(selectedSpec.display_order); + const hasDisplayOrder = selectedSpec && selectedSpec.display_order; const dialogData: WorkflowSpecDialogData = { id: selectedSpec ? selectedSpec.id : '', display_name: selectedSpec ? selectedSpec.display_name : '', @@ -246,9 +251,13 @@ export class WorkflowSpecListComponent implements OnInit { editCategoryDisplayOrder(catId: string, direction: string) { this.api.reorderWorkflowCategory(catId, direction).subscribe(cat_change => { this.workflowSpecsByCategory = this.workflowSpecsByCategory.map(cat => { - let new_cat = (cat_change.find(i2 => i2.id === cat.id)); - cat.display_order = new_cat.display_order; - return cat; + if (typeof cat_change.find == 'function') { + let new_cat = cat_change.find(i2 => i2.id === cat.id); + cat.display_order = new_cat.display_order; + return cat; + } else { + return cat; + } }); this.workflowSpecsByCategory.sort((x,y) => x.display_order - y.display_order); }); @@ -404,7 +413,7 @@ export class WorkflowSpecListComponent implements OnInit { this._displayMessage(`Successfully pulled the Git state`); } - gitMerge() { + gitMerge(pull?: boolean) { const dialogRef = this.dialog.open(GitMergeDialogComponent, { height: '75vh', width: '40vw', @@ -416,6 +425,9 @@ export class WorkflowSpecListComponent implements OnInit { this._displayMessage('Merged in new branch.'); }); } + if (pull) { + this.gitPull(); + } }); }