|
| 1 | +/********************************************************************* |
| 2 | + * Copyright (c) Intel Corporation 2022 |
| 3 | + * SPDX-License-Identifier: Apache-2.0 |
| 4 | + **********************************************************************/ |
| 5 | + |
| 6 | +import { ComponentFixture, TestBed } from '@angular/core/testing' |
| 7 | +import { NoopAnimationsModule } from '@angular/platform-browser/animations' |
| 8 | +import { provideTranslateService } from '@ngx-translate/core' |
| 9 | +import { IderStatusComponent } from './ider-status.component' |
| 10 | + |
| 11 | +describe('IderStatusComponent', () => { |
| 12 | + let component: IderStatusComponent |
| 13 | + let fixture: ComponentFixture<IderStatusComponent> |
| 14 | + |
| 15 | + beforeEach(async () => { |
| 16 | + await TestBed.configureTestingModule({ |
| 17 | + imports: [NoopAnimationsModule, IderStatusComponent], |
| 18 | + providers: [provideTranslateService()] |
| 19 | + }).compileComponents() |
| 20 | + |
| 21 | + fixture = TestBed.createComponent(IderStatusComponent) |
| 22 | + component = fixture.componentInstance |
| 23 | + }) |
| 24 | + |
| 25 | + it('should create', () => { |
| 26 | + expect(component).toBeTruthy() |
| 27 | + }) |
| 28 | + |
| 29 | + it('formatBytes formats byte counts into human-readable units', () => { |
| 30 | + expect(component.formatBytes(0)).toBe('0 B') |
| 31 | + expect(component.formatBytes(512)).toBe('512 B') |
| 32 | + expect(component.formatBytes(2048)).toBe('2.0 KB') |
| 33 | + expect(component.formatBytes(5 * 1024 * 1024)).toBe('5.0 MB') |
| 34 | + }) |
| 35 | + |
| 36 | + it('formatBytes returns 0 B for invalid input', () => { |
| 37 | + expect(component.formatBytes(-1)).toBe('0 B') |
| 38 | + expect(component.formatBytes(NaN)).toBe('0 B') |
| 39 | + }) |
| 40 | + |
| 41 | + it('shows the not-connected state by default', () => { |
| 42 | + fixture.detectChanges() |
| 43 | + const el = fixture.nativeElement |
| 44 | + expect(el.querySelector('mat-icon').textContent.trim()).toBe('storage') |
| 45 | + expect(el.querySelector('mat-spinner')).toBeNull() |
| 46 | + }) |
| 47 | + |
| 48 | + it('shows the transferred total when active', () => { |
| 49 | + fixture.componentRef.setInput('active', true) |
| 50 | + fixture.componentRef.setInput('bytes', 2048) |
| 51 | + fixture.detectChanges() |
| 52 | + const el = fixture.nativeElement |
| 53 | + expect(el.querySelector('mat-icon').textContent.trim()).toBe('check_circle') |
| 54 | + expect(el.textContent).toContain('2.0 KB') |
| 55 | + }) |
| 56 | + |
| 57 | + it('shows a spinner while transferring', () => { |
| 58 | + fixture.componentRef.setInput('active', true) |
| 59 | + fixture.componentRef.setInput('transferring', true) |
| 60 | + fixture.detectChanges() |
| 61 | + const el = fixture.nativeElement |
| 62 | + expect(el.querySelector('mat-spinner')).toBeTruthy() |
| 63 | + expect(el.querySelector('mat-icon')).toBeNull() |
| 64 | + }) |
| 65 | + |
| 66 | + it('shows the idle hint when provided and idle', () => { |
| 67 | + fixture.componentRef.setInput('idleHint', 'ider.status.attachHelp.value') |
| 68 | + fixture.detectChanges() |
| 69 | + expect(fixture.nativeElement.textContent).toContain('ider.status.attachHelp.value') |
| 70 | + }) |
| 71 | +}) |
0 commit comments