Add in differing buttons for differing environments (branches)

and fix tests
This commit is contained in:
alicia pritchett 2022-03-01 12:20:46 -05:00
parent f96e23c8ec
commit bff86487b2
5 changed files with 142 additions and 24 deletions

View File

@ -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 { 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', () => { describe('GitMergeDialogComponent', () => {
let component: GitMergeDialogComponent; let component: GitMergeDialogComponent;
let fixture: ComponentFixture<GitMergeDialogComponent>; let fixture: ComponentFixture<GitMergeDialogComponent>;
const mockRouter = {navigate: jasmine.createSpy('navigate')};
beforeEach(async () => { beforeEach(waitForAsync(() => {
await TestBed.configureTestingModule({ TestBed.configureTestingModule({
declarations: [ GitMergeDialogComponent ] 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(); .compileComponents();
}); }));
beforeEach(() => { beforeEach(() => {
fixture = TestBed.createComponent(GitMergeDialogComponent); fixture = TestBed.createComponent(GitMergeDialogComponent);

View File

@ -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 { 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', () => { describe('GitRepoDialogComponent', () => {
let component: GitRepoDialogComponent; let component: GitRepoDialogComponent;
let fixture: ComponentFixture<GitRepoDialogComponent>; let fixture: ComponentFixture<GitRepoDialogComponent>;
beforeEach(async () => { const mockRouter = {navigate: jasmine.createSpy('navigate')};
await TestBed.configureTestingModule({
declarations: [ GitRepoDialogComponent ] 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(); .compileComponents();
}); }));
beforeEach(() => { beforeEach(() => {
fixture = TestBed.createComponent(GitRepoDialogComponent); fixture = TestBed.createComponent(GitRepoDialogComponent);

View File

@ -8,10 +8,20 @@
<label><input matInput type="search" placeholder="Search Workflows" fxLayoutAlign="start" style="margin-top: 0;" class="form-control" [formControl]="searchField"></label> <label><input matInput type="search" placeholder="Search Workflows" fxLayoutAlign="start" style="margin-top: 0;" class="form-control" [formControl]="searchField"></label>
</mat-form-field> </mat-form-field>
</div> </div>
<div fxLayoutAlign="end center" fxLayoutGap="5px"> <div fxLayoutAlign="end center" fxLayoutGap="5px" *ngIf="branch === 'testing'">
<button mat-raised-button color="accent" (click)="gitPush()" >Publish</button>
</div>
<div fxLayoutAlign="end center" fxLayoutGap="5px" *ngIf="branch === 'staging'">
<button mat-raised-button color="accent" (click)="gitPush()" >Publish</button>
<button mat-raised-button color="primary" (click)="gitMerge(true)"> Pull Testing State</button>
</div>
<div fxLayoutAlign="end center" fxLayoutGap="5px" *ngIf="branch === 'production'">
<button mat-raised-button color="accent" (click)="gitMerge(true)"> Pull Staging State</button>
</div>
<div fxLayoutAlign="end center" fxLayoutGap="5px" *ngIf="branch !=='production' && branch !=='staging' && branch !=='testing'">
<button mat-raised-button color="accent" (click)="gitPush()" >Push</button> <button mat-raised-button color="accent" (click)="gitPush()" >Push</button>
<button mat-raised-button color="accent" (click)="gitPull()"> Pull</button> <button mat-raised-button color="accent" (click)="gitPull()"> Pull</button>
<button mat-raised-button color="primary" (click)="gitMerge()"> Merge from {{merge_branch}}</button> <button mat-raised-button color="primary" (click)="gitMerge(false)"> Merge </button>
</div> </div>
</div> </div>
<mat-drawer-container class="example-container" autosize> <mat-drawer-container class="example-container" autosize>

View File

@ -137,6 +137,9 @@ describe('WorkflowSpecListComponent', () => {
specReq.flush(mockWorkflowSpecs); specReq.flush(mockWorkflowSpecs);
fixture.detectChanges(); fixture.detectChanges();
expect(component.workflowSpecs.length).toBeGreaterThan(0); expect(component.workflowSpecs.length).toBeGreaterThan(0);
const gitReq = httpMock.expectOne('apiRoot/git_repo');
expect(gitReq.request.method).toEqual('GET');
}); });
afterEach(() => { afterEach(() => {

View File

@ -6,7 +6,6 @@ import { cloneDeep } from 'lodash';
import { import {
ApiErrorsComponent, ApiErrorsComponent,
ApiService, ApiService,
isNumberDefined,
// moveArrayElementDown, // moveArrayElementDown,
// moveArrayElementUp, // moveArrayElementUp,
WorkflowSpec, WorkflowSpec,
@ -60,6 +59,7 @@ export class WorkflowSpecListComponent implements OnInit {
searchField: FormControl; searchField: FormControl;
library_toggle: boolean; library_toggle: boolean;
merge_branch: string = 'branch' merge_branch: string = 'branch'
branch: string = 'branch'
constructor( constructor(
private api: ApiService, private api: ApiService,
@ -82,9 +82,12 @@ export class WorkflowSpecListComponent implements OnInit {
}); });
this.api.gitRepo().subscribe(gitRepo => { this.api.gitRepo().subscribe(gitRepo => {
if (gitRepo.merge_branch && gitRepo.merge_branch != 'all') { if (gitRepo.merge_branch) {
this.merge_branch = gitRepo.merge_branch; this.merge_branch = gitRepo.merge_branch;
} }
if (gitRepo.branch) {
this.branch = gitRepo.branch;
}
}) })
this.searchField = new FormControl(); this.searchField = new FormControl();
@ -109,10 +112,12 @@ export class WorkflowSpecListComponent implements OnInit {
} }
setCatByID(cat_id: string) { setCatByID(cat_id: string) {
if (cat_id) {
this.api.getWorkflowSpecCategory(cat_id).subscribe(cat => { this.api.getWorkflowSpecCategory(cat_id).subscribe(cat => {
this.selectedCat = cat; this.selectedCat = cat;
}) })
} }
}
isSelected(cat: WorkflowSpecCategoryGroup) { isSelected(cat: WorkflowSpecCategoryGroup) {
return this.selectedCat && this.selectedCat.id === cat.id; return this.selectedCat && this.selectedCat.id === cat.id;
@ -129,7 +134,7 @@ export class WorkflowSpecListComponent implements OnInit {
editWorkflowSpec(state: String, selectedSpec?: WorkflowSpec) { editWorkflowSpec(state: String, selectedSpec?: WorkflowSpec) {
const hasDisplayOrder = selectedSpec && isNumberDefined(selectedSpec.display_order); const hasDisplayOrder = selectedSpec && selectedSpec.display_order;
const dialogData: WorkflowSpecDialogData = { const dialogData: WorkflowSpecDialogData = {
id: selectedSpec ? selectedSpec.id : '', id: selectedSpec ? selectedSpec.id : '',
display_name: selectedSpec ? selectedSpec.display_name : '', display_name: selectedSpec ? selectedSpec.display_name : '',
@ -246,9 +251,13 @@ export class WorkflowSpecListComponent implements OnInit {
editCategoryDisplayOrder(catId: string, direction: string) { editCategoryDisplayOrder(catId: string, direction: string) {
this.api.reorderWorkflowCategory(catId, direction).subscribe(cat_change => { this.api.reorderWorkflowCategory(catId, direction).subscribe(cat_change => {
this.workflowSpecsByCategory = this.workflowSpecsByCategory.map(cat => { this.workflowSpecsByCategory = this.workflowSpecsByCategory.map(cat => {
let new_cat = (cat_change.find(i2 => i2.id === cat.id)); if (typeof cat_change.find == 'function') {
let new_cat = cat_change.find(i2 => i2.id === cat.id);
cat.display_order = new_cat.display_order; cat.display_order = new_cat.display_order;
return cat; return cat;
} else {
return cat;
}
}); });
this.workflowSpecsByCategory.sort((x,y) => x.display_order - y.display_order); 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`); this._displayMessage(`Successfully pulled the Git state`);
} }
gitMerge() { gitMerge(pull?: boolean) {
const dialogRef = this.dialog.open(GitMergeDialogComponent, { const dialogRef = this.dialog.open(GitMergeDialogComponent, {
height: '75vh', height: '75vh',
width: '40vw', width: '40vw',
@ -416,6 +425,9 @@ export class WorkflowSpecListComponent implements OnInit {
this._displayMessage('Merged in new branch.'); this._displayMessage('Merged in new branch.');
}); });
} }
if (pull) {
this.gitPull();
}
}); });
} }