paperless-ngx/src-ui/src/app/components/common/system-status-dialog/system-status-dialog.component.spec.ts

107 lines
3.3 KiB
TypeScript
Raw Normal View History

2024-12-13 00:27:30 -08:00
import { Clipboard, ClipboardModule } from '@angular/cdk/clipboard'
import { provideHttpClient, withInterceptorsFromDi } from '@angular/common/http'
import { provideHttpClientTesting } from '@angular/common/http/testing'
2024-03-04 09:26:25 -08:00
import {
ComponentFixture,
TestBed,
fakeAsync,
tick,
} from '@angular/core/testing'
import {
NgbActiveModal,
NgbModalModule,
NgbPopoverModule,
NgbProgressbarModule,
} from '@ng-bootstrap/ng-bootstrap'
2024-12-13 00:27:30 -08:00
import { NgxBootstrapIconsModule, allIcons } from 'ngx-bootstrap-icons'
2024-03-04 09:26:25 -08:00
import {
InstallType,
SystemStatus,
2024-12-13 00:27:30 -08:00
SystemStatusItemStatus,
2024-03-04 09:26:25 -08:00
} from 'src/app/data/system-status'
2024-06-26 20:57:39 -07:00
import { FileSizePipe } from 'src/app/pipes/file-size.pipe'
2024-12-13 00:27:30 -08:00
import { SystemStatusDialogComponent } from './system-status-dialog.component'
2024-03-04 09:26:25 -08:00
const status: SystemStatus = {
pngx_version: '2.4.3',
server_os: 'macOS-14.1.1-arm64-arm-64bit',
install_type: InstallType.BareMetal,
storage: { total: 494384795648, available: 13573525504 },
database: {
type: 'sqlite',
url: '/paperless-ngx/data/db.sqlite3',
status: SystemStatusItemStatus.ERROR,
error: null,
migration_status: {
latest_migration: 'socialaccount.0006_alter_socialaccount_extra_data',
unapplied_migrations: [],
},
},
tasks: {
redis_url: 'redis://localhost:6379',
redis_status: SystemStatusItemStatus.ERROR,
redis_error: 'Error 61 connecting to localhost:6379. Connection refused.',
celery_status: SystemStatusItemStatus.ERROR,
index_status: SystemStatusItemStatus.OK,
index_last_modified: new Date().toISOString(),
index_error: null,
classifier_status: SystemStatusItemStatus.OK,
classifier_last_trained: new Date().toISOString(),
classifier_error: null,
},
}
describe('SystemStatusDialogComponent', () => {
let component: SystemStatusDialogComponent
let fixture: ComponentFixture<SystemStatusDialogComponent>
let clipboard: Clipboard
beforeEach(async () => {
await TestBed.configureTestingModule({
2024-06-26 20:57:39 -07:00
declarations: [SystemStatusDialogComponent, FileSizePipe],
2024-03-04 09:26:25 -08:00
imports: [
NgbModalModule,
ClipboardModule,
NgxBootstrapIconsModule.pick(allIcons),
NgbPopoverModule,
NgbProgressbarModule,
],
2024-06-26 20:57:39 -07:00
providers: [
NgbActiveModal,
provideHttpClient(withInterceptorsFromDi()),
provideHttpClientTesting(),
],
2024-03-04 09:26:25 -08:00
}).compileComponents()
fixture = TestBed.createComponent(SystemStatusDialogComponent)
component = fixture.componentInstance
component.status = status
clipboard = TestBed.inject(Clipboard)
fixture.detectChanges()
})
it('should close the active modal', () => {
const closeSpy = jest.spyOn(component.activeModal, 'close')
component.close()
expect(closeSpy).toHaveBeenCalled()
})
it('should copy the system status to clipboard', fakeAsync(() => {
jest.spyOn(clipboard, 'copy')
component.copy()
expect(clipboard.copy).toHaveBeenCalledWith(
2024-05-17 14:30:03 -07:00
JSON.stringify(component.status, null, 4)
2024-03-04 09:26:25 -08:00
)
expect(component.copied).toBeTruthy()
tick(3000)
expect(component.copied).toBeFalsy()
}))
it('should calculate if date is stale', () => {
const date = new Date()
date.setHours(date.getHours() - 25)
expect(component.isStale(date.toISOString())).toBeTruthy()
expect(component.isStale(date.toISOString(), 26)).toBeFalsy()
})
})