From 9c6c05be242e2548e7fd8d143a7bca794fc29c90 Mon Sep 17 00:00:00 2001 From: Matthew Bystedt Date: Wed, 20 Sep 2023 13:59:27 -0700 Subject: [PATCH] fix: workflows and spec files --- .github/workflows/pr-open.yml | 65 +++++++++++-------- .../{merge-main.yml => tag-main.yml} | 14 ++-- ui/src/app/app.component.spec.ts | 10 +-- .../delete-confirm-dialog.component.spec.ts | 7 ++ .../inspector/inspector.component.spec.ts | 5 +- .../vertex-form-field.component.spec.ts | 7 +- .../action-content.component.ts | 3 +- .../page-not-found.component.spec.ts | 6 +- ui/src/app/preferences.service.spec.ts | 3 +- ui/src/app/service/graph-api.service.spec.ts | 3 +- 10 files changed, 69 insertions(+), 54 deletions(-) rename .github/workflows/{merge-main.yml => tag-main.yml} (88%) diff --git a/.github/workflows/pr-open.yml b/.github/workflows/pr-open.yml index 3f2a3403..1be8c7f1 100644 --- a/.github/workflows/pr-open.yml +++ b/.github/workflows/pr-open.yml @@ -35,17 +35,17 @@ jobs: uses: actions/checkout@v3 - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v2 + uses: docker/setup-buildx-action@v3 - name: Log in to the Container registry - uses: docker/login-action@v2 + uses: docker/login-action@v3 with: registry: ${{ env.REGISTRY }} username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} - name: Build and push Backend Docker image - uses: docker/build-push-action@v4 + uses: docker/build-push-action@v5 with: context: ./ push: true @@ -56,37 +56,27 @@ jobs: REPO_LOCATION= tests-backend: - name: Backend Unit Tests + name: Backend Tests runs-on: ubuntu-latest steps: - name: Checkout repository uses: actions/checkout@v3 - - name: Get npm cache directory - id: npm-cache-dir-backend - run: | - echo "::set-output name=dir::$(npm config get cache)" - - uses: actions/cache@v3 - id: npm-cache-backend # use this to check for `cache-hit` ==> if: steps.npm-cache.outputs.cache-hit != 'true' + - name: Use Node.js + uses: actions/setup-node@v3 with: - path: ${{ steps.npm-cache-dir-backend.outputs.dir }} - key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }} - restore-keys: | - ${{ runner.os }}-node- - - - name: Cache for test results - id: cache-backend - uses: actions/cache@v3 - with: - path: coverage - key: backend-coverage-${{ github.run_number }} - restore-keys: | - backend-coverage- + node-version: 18 + cache: 'npm' + + - name: npm ci + run: npm ci + + - name: lint + if: ${{ github.actor != 'dependabot[bot]' }} + run: npm run lint - - name: Tests - run: | - npm ci - npm run test:cov + - name: unit test + run: npm run test:cov - name: Report code coverage if: ${{ github.actor != 'dependabot[bot]' }} @@ -96,3 +86,24 @@ jobs: delete-old-comments: true github-token: ${{ secrets.GITHUB_TOKEN }} lcov-file: ./coverage/lcov.info + + # tests-frontend: + # name: Frontend Tests + # runs-on: ubuntu-latest + # steps: + # - name: Checkout repository + # uses: actions/checkout@v3 + + # - name: Use Node.js + # uses: actions/setup-node@v3 + # with: + # node-version: 18 + # cache: 'npm' + + # - name: npm ci + # run: npm ci + # working-directory: ./ui + + # - name: unit test + # run: npm run test + # working-directory: ./ui diff --git a/.github/workflows/merge-main.yml b/.github/workflows/tag-main.yml similarity index 88% rename from .github/workflows/merge-main.yml rename to .github/workflows/tag-main.yml index 4523315c..9c8a5057 100644 --- a/.github/workflows/merge-main.yml +++ b/.github/workflows/tag-main.yml @@ -1,4 +1,4 @@ -name: Main Merge +name: Tag Main on: push: @@ -49,8 +49,8 @@ jobs: - name: Perform CodeQL Analysis uses: github/codeql-action/analyze@v2 - build-backend: - name: Backend Image Build + build-image: + name: Build Image runs-on: ubuntu-latest permissions: contents: read @@ -66,21 +66,19 @@ jobs: images: ${{ secrets.ARTIFACTORY_REGISTRY }}/${{ github.repository }}-backend - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v2 + uses: docker/setup-buildx-action@v3 - name: Log in to the Container registry - uses: docker/login-action@v2 + uses: docker/login-action@v3 with: registry: ${{ secrets.ARTIFACTORY_REGISTRY }} username: ${{ secrets.ARTIFACTORY_USERNAME }} password: ${{ secrets.ARTIFACTORY_PASSWORD }} - name: Build and push Backend Docker image - uses: docker/build-push-action@v4 + uses: docker/build-push-action@v5 with: context: . push: true tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} - cache-from: type=gha - cache-to: type=gha,mode=max diff --git a/ui/src/app/app.component.spec.ts b/ui/src/app/app.component.spec.ts index f53e2a5b..63974615 100644 --- a/ui/src/app/app.component.spec.ts +++ b/ui/src/app/app.component.spec.ts @@ -5,8 +5,8 @@ import { AppComponent } from './app.component'; describe('AppComponent', () => { beforeEach(async () => { await TestBed.configureTestingModule({ - imports: [RouterTestingModule, AppComponent] -}).compileComponents(); + imports: [RouterTestingModule, AppComponent], + }).compileComponents(); }); it('should create the app', () => { @@ -15,12 +15,6 @@ describe('AppComponent', () => { expect(app).toBeTruthy(); }); - it(`should have as title 'ui'`, () => { - const fixture = TestBed.createComponent(AppComponent); - const app = fixture.componentInstance; - expect(app.title).toEqual('ui'); - }); - it('should render title', () => { const fixture = TestBed.createComponent(AppComponent); fixture.detectChanges(); diff --git a/ui/src/app/graph/delete-confirm-dialog/delete-confirm-dialog.component.spec.ts b/ui/src/app/graph/delete-confirm-dialog/delete-confirm-dialog.component.spec.ts index 3e466295..d246aa10 100644 --- a/ui/src/app/graph/delete-confirm-dialog/delete-confirm-dialog.component.spec.ts +++ b/ui/src/app/graph/delete-confirm-dialog/delete-confirm-dialog.component.spec.ts @@ -1,4 +1,5 @@ import { ComponentFixture, TestBed } from '@angular/core/testing'; +import { MatDialogRef } from '@angular/material/dialog'; import { DeleteConfirmDialogComponent } from './delete-confirm-dialog.component'; @@ -9,6 +10,12 @@ describe('DeleteConfirmDialogComponent', () => { beforeEach(() => { TestBed.configureTestingModule({ imports: [DeleteConfirmDialogComponent], + providers: [ + { + provide: MatDialogRef, + useValue: {}, + }, + ], }); fixture = TestBed.createComponent(DeleteConfirmDialogComponent); component = fixture.componentInstance; diff --git a/ui/src/app/graph/inspector/inspector.component.spec.ts b/ui/src/app/graph/inspector/inspector.component.spec.ts index c5001c4e..6c2df22f 100644 --- a/ui/src/app/graph/inspector/inspector.component.spec.ts +++ b/ui/src/app/graph/inspector/inspector.component.spec.ts @@ -1,4 +1,5 @@ import { ComponentFixture, TestBed } from '@angular/core/testing'; +import { HttpClientModule } from '@angular/common/http'; import { InspectorComponent } from './inspector.component'; @@ -8,8 +9,8 @@ describe('InspectorComponent', () => { beforeEach(async () => { await TestBed.configureTestingModule({ - imports: [InspectorComponent] -}).compileComponents(); + imports: [InspectorComponent, HttpClientModule], + }).compileComponents(); fixture = TestBed.createComponent(InspectorComponent); component = fixture.componentInstance; diff --git a/ui/src/app/graph/vertex-form-field/vertex-form-field.component.spec.ts b/ui/src/app/graph/vertex-form-field/vertex-form-field.component.spec.ts index 92da7dfc..c9c306a9 100644 --- a/ui/src/app/graph/vertex-form-field/vertex-form-field.component.spec.ts +++ b/ui/src/app/graph/vertex-form-field/vertex-form-field.component.spec.ts @@ -1,6 +1,7 @@ import { ComponentFixture, TestBed } from '@angular/core/testing'; import { VertexFormFieldComponent } from './vertex-form-field.component'; +import { FormGroup } from '@angular/forms'; describe('VertexFormFieldComponent', () => { let component: VertexFormFieldComponent; @@ -8,9 +9,9 @@ describe('VertexFormFieldComponent', () => { beforeEach(async () => { await TestBed.configureTestingModule({ - imports: [VertexFormFieldComponent] -}) - .compileComponents(); + imports: [VertexFormFieldComponent], + providers: [{ provide: FormGroup, useValue: new FormGroup([]) }], + }).compileComponents(); fixture = TestBed.createComponent(VertexFormFieldComponent); component = fixture.componentInstance; diff --git a/ui/src/app/intention/action-content/action-content.component.ts b/ui/src/app/intention/action-content/action-content.component.ts index 49a5f3bf..be71037e 100644 --- a/ui/src/app/intention/action-content/action-content.component.ts +++ b/ui/src/app/intention/action-content/action-content.component.ts @@ -16,8 +16,9 @@ export class ActionContentComponent implements OnInit { values: string[] = []; ngOnInit(): void { + const actions = this.intention?.actions ?? []; const valueSet = new Set( - this.intention.actions.map((action: any) => { + actions.map((action: any) => { return get(action, this.key); }), ); diff --git a/ui/src/app/page-not-found/page-not-found.component.spec.ts b/ui/src/app/page-not-found/page-not-found.component.spec.ts index cf4947cb..15b41844 100644 --- a/ui/src/app/page-not-found/page-not-found.component.spec.ts +++ b/ui/src/app/page-not-found/page-not-found.component.spec.ts @@ -1,4 +1,5 @@ import { ComponentFixture, TestBed } from '@angular/core/testing'; +import { RouterTestingModule } from '@angular/router/testing'; import { PageNotFoundComponent } from './page-not-found.component'; @@ -8,9 +9,8 @@ describe('PageNotFoundComponent', () => { beforeEach(async () => { await TestBed.configureTestingModule({ - imports: [PageNotFoundComponent] -}) - .compileComponents(); + imports: [RouterTestingModule, PageNotFoundComponent], + }).compileComponents(); fixture = TestBed.createComponent(PageNotFoundComponent); component = fixture.componentInstance; diff --git a/ui/src/app/preferences.service.spec.ts b/ui/src/app/preferences.service.spec.ts index b0d7d5ea..6c47dafb 100644 --- a/ui/src/app/preferences.service.spec.ts +++ b/ui/src/app/preferences.service.spec.ts @@ -1,4 +1,5 @@ import { TestBed } from '@angular/core/testing'; +import { HttpClientModule } from '@angular/common/http'; import { PreferencesService } from './preferences.service'; @@ -6,7 +7,7 @@ describe('PreferencesService', () => { let service: PreferencesService; beforeEach(() => { - TestBed.configureTestingModule({}); + TestBed.configureTestingModule({ imports: [HttpClientModule] }); service = TestBed.inject(PreferencesService); }); diff --git a/ui/src/app/service/graph-api.service.spec.ts b/ui/src/app/service/graph-api.service.spec.ts index ef46598d..85808cdb 100644 --- a/ui/src/app/service/graph-api.service.spec.ts +++ b/ui/src/app/service/graph-api.service.spec.ts @@ -1,4 +1,5 @@ import { TestBed } from '@angular/core/testing'; +import { HttpClientModule } from '@angular/common/http'; import { GraphApiService } from './graph-api.service'; @@ -6,7 +7,7 @@ describe('GraphApiService', () => { let service: GraphApiService; beforeEach(() => { - TestBed.configureTestingModule({}); + TestBed.configureTestingModule({ imports: [HttpClientModule] }); service = TestBed.inject(GraphApiService); });