Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions .github/workflows/build-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -84,3 +84,24 @@
for OPTS_NAME in ANMS_COMPOSE_OPTS TESTENV_COMPOSE_OPTS; do
${DOCKER_CMD} compose ${!OPTS_NAME} down --remove-orphans
done

anms-ui-unit-test:
runs-on: ubuntu-24.04
name: ANMS UI Unit Tests
steps:
- name: Checkout repository
uses: actions/checkout@v6
with:
submodules: true
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 22
cache: 'npm'
cache-dependency-path: anms-ui/package-lock.json
- name: Install dependencies
working-directory: anms-ui
run: npm ci

Check warning on line 104 in .github/workflows/build-test.yaml

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Omitting "--ignore-scripts" allows lifecycle scripts to run during package installation.

See more on https://sonarcloud.io/project/issues?id=NASA-AMMOS_anms&issues=AaAbiuURT_B-vhx75xJr&open=AaAbiuURT_B-vhx75xJr&pullRequest=397
- name: Run unit tests
working-directory: anms-ui
run: npx ng test --runner=vitest --no-watch

Check warning on line 107 in .github/workflows/build-test.yaml

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Define exact package version to avoid installing unverified releases.

See more on https://sonarcloud.io/project/issues?id=NASA-AMMOS_anms&issues=AaAbiuURT_B-vhx75xJt&open=AaAbiuURT_B-vhx75xJt&pullRequest=397

Check warning on line 107 in .github/workflows/build-test.yaml

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

"npx" can install packages on-demand and run their lifecycle scripts.

See more on https://sonarcloud.io/project/issues?id=NASA-AMMOS_anms&issues=AaAbiuURT_B-vhx75xJs&open=AaAbiuURT_B-vhx75xJs&pullRequest=397
6 changes: 4 additions & 2 deletions anms-ui/src/app/app.spec.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import { provideRouter } from '@angular/router';
import { TestBed } from '@angular/core/testing';
import { App } from './app';

describe('App', () => {
beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [App],
providers: [provideRouter([])],
}).compileComponents();
});

Expand All @@ -14,10 +16,10 @@ describe('App', () => {
expect(app).toBeTruthy();
});

it('should render title', async () => {
it('should render router outlet', async () => {
const fixture = TestBed.createComponent(App);
await fixture.whenStable();
const compiled = fixture.nativeElement as HTMLElement;
expect(compiled.querySelector('h1')?.textContent).toContain('Hello, anms-ui');
expect(compiled.querySelector('router-outlet')).toBeTruthy();
});
});
6 changes: 5 additions & 1 deletion anms-ui/src/app/features/adms/adms.spec.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import { provideHttpClient } from '@angular/common/http';
import { HttpClientTestingModule } from '@angular/common/http/testing';
import { provideToastr } from 'ngx-toastr';
import { ComponentFixture, TestBed } from '@angular/core/testing';

import { Adms } from './adms';
Expand All @@ -8,7 +11,8 @@ describe('Adms', () => {

beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [Adms],
imports: [Adms, HttpClientTestingModule],
providers: [provideHttpClient(), provideToastr()],
}).compileComponents();

fixture = TestBed.createComponent(Adms);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { provideRouter } from '@angular/router';
import { ComponentFixture, TestBed } from '@angular/core/testing';

import { DashboardHome } from './dashboard-home';
Expand All @@ -9,6 +10,7 @@ describe('DashboardHome', () => {
beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [DashboardHome],
providers: [provideRouter([])],
}).compileComponents();

fixture = TestBed.createComponent(DashboardHome);
Expand Down
14 changes: 13 additions & 1 deletion anms-ui/src/app/features/dashboard/dashboard.spec.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
import { provideHttpClient } from '@angular/common/http';
import { HttpClientTestingModule } from '@angular/common/http/testing';
import { provideToastr } from 'ngx-toastr';
import { provideRouter } from '@angular/router';
import { ComponentFixture, TestBed } from '@angular/core/testing';

import { Dashboard } from './dashboard';
Expand All @@ -8,9 +12,17 @@ describe('Dashboard', () => {

beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [Dashboard],
imports: [Dashboard, HttpClientTestingModule],
providers: [
provideHttpClient(),
provideToastr(),
provideRouter([]),
],
}).compileComponents();

// Provide DOM element that sidebar.ngAfterViewInit looks for
document.body.innerHTML = '<details id="managementDetails"></details>';

fixture = TestBed.createComponent(Dashboard);
component = fixture.componentInstance;
await fixture.whenStable();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
import { provideHttpClient } from '@angular/common/http';
import { HttpClientTestingModule } from '@angular/common/http/testing';
import { provideToastr } from 'ngx-toastr';
import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog';
import { ComponentFixture, TestBed } from '@angular/core/testing';
import {AgentModal} from './agent-modal';

Expand All @@ -8,7 +12,13 @@ describe('AgentModal', () => {

beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [AgentModal],
imports: [AgentModal, HttpClientTestingModule],
providers: [
provideHttpClient(),
provideToastr(),
{ provide: MatDialogRef, useValue: { close: () => {} } },
{ provide: MAT_DIALOG_DATA, useValue: {} },
],
}).compileComponents();

fixture = TestBed.createComponent(AgentModal);
Expand Down
6 changes: 5 additions & 1 deletion anms-ui/src/app/features/management/agents/agents.spec.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import { provideHttpClient } from '@angular/common/http';
import { HttpClientTestingModule } from '@angular/common/http/testing';
import { provideToastr } from 'ngx-toastr';
import { ComponentFixture, TestBed } from '@angular/core/testing';

import { Agents } from './agents';
Expand All @@ -8,7 +11,8 @@ describe('Agents', () => {

beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [Agents],
imports: [Agents, HttpClientTestingModule],
providers: [provideHttpClient(), provideToastr()],
}).compileComponents();

fixture = TestBed.createComponent(Agents);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import { provideHttpClient } from '@angular/common/http';
import { HttpClientTestingModule } from '@angular/common/http/testing';
import { provideToastr } from 'ngx-toastr';
import { ComponentFixture, TestBed } from '@angular/core/testing';

import { Crud } from './crud';
Expand All @@ -8,7 +11,8 @@ describe('Crud', () => {

beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [Crud],
imports: [Crud, HttpClientTestingModule],
providers: [provideHttpClient(), provideToastr()],
}).compileComponents();

fixture = TestBed.createComponent(Crud);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
import { provideHttpClient } from '@angular/common/http';
import { HttpClientTestingModule } from '@angular/common/http/testing';
import { provideToastr } from 'ngx-toastr';
import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog';
import { ComponentFixture, TestBed } from '@angular/core/testing';

import { ManageAgentsDialog } from './manage-agents-dialog';
Expand All @@ -8,7 +12,13 @@ describe('ManageAgentsDialog', () => {

beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [ManageAgentsDialog],
imports: [ManageAgentsDialog, HttpClientTestingModule],
providers: [
provideHttpClient(),
provideToastr(),
{ provide: MatDialogRef, useValue: { close: () => {} } },
{ provide: MAT_DIALOG_DATA, useValue: { agents: [] } },
],
}).compileComponents();

fixture = TestBed.createComponent(ManageAgentsDialog);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import { provideHttpClient } from '@angular/common/http';
import { HttpClientTestingModule } from '@angular/common/http/testing';
import { provideToastr } from 'ngx-toastr';
import { ComponentFixture, TestBed } from '@angular/core/testing';

import { Reports } from './reports';
Expand All @@ -8,7 +11,8 @@ describe('Reports', () => {

beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [Reports],
imports: [Reports, HttpClientTestingModule],
providers: [provideHttpClient(), provideToastr()],
}).compileComponents();

fixture = TestBed.createComponent(Reports);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import { provideHttpClient } from '@angular/common/http';
import { HttpClientTestingModule } from '@angular/common/http/testing';
import { provideToastr } from 'ngx-toastr';
import { ComponentFixture, TestBed } from '@angular/core/testing';

import { Builder } from './builder';
Expand All @@ -8,7 +11,8 @@ describe('Builder', () => {

beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [Builder],
imports: [Builder, HttpClientTestingModule],
providers: [provideHttpClient(), provideToastr()],
}).compileComponents();

fixture = TestBed.createComponent(Builder);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { provideRouter } from '@angular/router';
import { ComponentFixture, TestBed } from '@angular/core/testing';

import { PageNotFound } from './page-not-found';
Expand All @@ -9,6 +10,7 @@ describe('PageNotFound', () => {
beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [PageNotFound],
providers: [provideRouter([])],
}).compileComponents();

fixture = TestBed.createComponent(PageNotFound);
Expand Down
11 changes: 10 additions & 1 deletion anms-ui/src/app/features/status/status.spec.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
import { provideHttpClient } from '@angular/common/http';
import { HttpClientTestingModule } from '@angular/common/http/testing';
import { provideToastr } from 'ngx-toastr';
import { provideRouter } from '@angular/router';
import { ComponentFixture, TestBed } from '@angular/core/testing';

import { Status } from './status';
Expand All @@ -8,7 +12,12 @@ describe('Status', () => {

beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [Status],
imports: [Status, HttpClientTestingModule],
providers: [
provideHttpClient(),
provideToastr(),
provideRouter([]),
],
}).compileComponents();

fixture = TestBed.createComponent(Status);
Expand Down
2 changes: 2 additions & 0 deletions anms-ui/src/app/layout/header/header.spec.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { provideRouter } from '@angular/router';
import { ComponentFixture, TestBed } from '@angular/core/testing';

import { Header } from './header';
Expand All @@ -9,6 +10,7 @@ describe('Header', () => {
beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [Header],
providers: [provideRouter([])],
}).compileComponents();

fixture = TestBed.createComponent(Header);
Expand Down
14 changes: 13 additions & 1 deletion anms-ui/src/app/layout/sidebar/sidebar.spec.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
import { provideHttpClient } from '@angular/common/http';
import { HttpClientTestingModule } from '@angular/common/http/testing';
import { provideToastr } from 'ngx-toastr';
import { provideRouter } from '@angular/router';
import { ComponentFixture, TestBed } from '@angular/core/testing';

import { Sidebar } from './sidebar';
Expand All @@ -8,9 +12,17 @@ describe('Sidebar', () => {

beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [Sidebar],
imports: [Sidebar, HttpClientTestingModule],
providers: [
provideHttpClient(),
provideToastr(),
provideRouter([]),
],
}).compileComponents();

// Provide DOM element that sidebar.ngAfterViewInit looks for
document.body.innerHTML = '<details id="managementDetails"></details>';

fixture = TestBed.createComponent(Sidebar);
component = fixture.componentInstance;
await fixture.whenStable();
Expand Down
8 changes: 7 additions & 1 deletion anms-ui/src/app/store/modules/service-status.spec.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import { provideHttpClient } from '@angular/common/http';
import { HttpClientTestingModule } from '@angular/common/http/testing';
import { provideToastr } from 'ngx-toastr';
import { TestBed } from '@angular/core/testing';

import {ServiceStatusService} from './service-status.service';
Expand All @@ -6,7 +9,10 @@ describe('StatusStore', () => {
let service: ServiceStatusService;

beforeEach(() => {
TestBed.configureTestingModule({});
TestBed.configureTestingModule({
imports: [HttpClientTestingModule],
providers: [provideHttpClient(), provideToastr()],
});
service = TestBed.inject(ServiceStatusService);
});

Expand Down
Loading