-
Notifications
You must be signed in to change notification settings - Fork 309
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
NAS-132332 / 25.04 / Adding proxies to containers (#11010)
- Loading branch information
Showing
110 changed files
with
2,436 additions
and
210 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 4 additions & 1 deletion
5
.../virtualization/components/all-instances/instance-details/instance-details.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,9 @@ | ||
<div class="cards"> | ||
<div class="scroll-window"> | ||
<ix-instance-devices [instance]="instance()"></ix-instance-devices> | ||
<ix-instance-general-info [instance]="instance()"></ix-instance-general-info> | ||
|
||
<ix-instance-devices></ix-instance-devices> | ||
|
||
<ix-instance-proxies></ix-instance-proxies> | ||
</div> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 18 additions & 2 deletions
20
...omponents/all-instances/instance-details/instance-devices/instance-devices.component.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,19 @@ | ||
mat-card-content p { | ||
margin: 0 0 6px; | ||
.device { | ||
align-items: center; | ||
display: flex; | ||
justify-content: space-between; | ||
} | ||
|
||
.delete-button { | ||
opacity: 0.8; | ||
|
||
&:focus, | ||
&:hover { | ||
opacity: 1; | ||
} | ||
|
||
ix-icon { | ||
height: 20px; | ||
width: 20px; | ||
} | ||
} |
99 changes: 50 additions & 49 deletions
99
...onents/all-instances/instance-details/instance-devices/instance-devices.component.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,71 +1,72 @@ | ||
import { MatProgressSpinner } from '@angular/material/progress-spinner'; | ||
import { createComponentFactory, Spectator } from '@ngneat/spectator/jest'; | ||
import { MockComponents } from 'ng-mocks'; | ||
import { HarnessLoader } from '@angular/cdk/testing'; | ||
import { TestbedHarnessEnvironment } from '@angular/cdk/testing/testbed'; | ||
import { createComponentFactory, mockProvider, Spectator } from '@ngneat/spectator/jest'; | ||
import { of } from 'rxjs'; | ||
import { mockCall, mockWebSocket } from 'app/core/testing/utils/mock-websocket.utils'; | ||
import { VirtualizationDeviceType, VirtualizationStatus, VirtualizationType } from 'app/enums/virtualization.enum'; | ||
import { | ||
VirtualizationDevice, | ||
VirtualizationInstance, | ||
} from 'app/interfaces/virtualization.interface'; | ||
import { VirtualizationDeviceType } from 'app/enums/virtualization.enum'; | ||
import { VirtualizationProxy, VirtualizationUsb } from 'app/interfaces/virtualization.interface'; | ||
import { DialogService } from 'app/modules/dialog/dialog.service'; | ||
import { IxIconHarness } from 'app/modules/ix-icon/ix-icon.harness'; | ||
import { SnackbarService } from 'app/modules/snackbar/services/snackbar.service'; | ||
import { | ||
InstanceDevicesComponent, | ||
} from 'app/pages/virtualization/components/all-instances/instance-details/instance-devices/instance-devices.component'; | ||
import { VirtualizationInstancesStore } from 'app/pages/virtualization/stores/virtualization-instances.store'; | ||
import { WebSocketService } from 'app/services/ws.service'; | ||
|
||
describe('InstanceDevicesComponent', () => { | ||
let spectator: Spectator<InstanceDevicesComponent>; | ||
|
||
const demoInstance = { | ||
id: 'demo', | ||
name: 'Demo', | ||
type: VirtualizationType.Container, | ||
status: VirtualizationStatus.Running, | ||
cpu: '525', | ||
autostart: true, | ||
image: { | ||
archs: ['amd64'], | ||
description: 'Almalinux 8 amd64 (20241030_23:38)', | ||
os: 'Almalinux', | ||
release: '8', | ||
}, | ||
memory: 131072000, | ||
} as VirtualizationInstance; | ||
|
||
const devices = [ | ||
{ dev_type: VirtualizationDeviceType.Gpu }, | ||
{ dev_type: VirtualizationDeviceType.Usb }, | ||
] as VirtualizationDevice[]; | ||
|
||
let loader: HarnessLoader; | ||
const createComponent = createComponentFactory({ | ||
component: InstanceDevicesComponent, | ||
declarations: [ | ||
MockComponents( | ||
MatProgressSpinner, | ||
), | ||
], | ||
providers: [ | ||
mockProvider(DialogService, { | ||
confirm: jest.fn(() => of(true)), | ||
}), | ||
mockWebSocket([ | ||
mockCall('virt.instance.device_list', devices), | ||
mockCall('virt.instance.device_delete'), | ||
]), | ||
mockProvider(SnackbarService), | ||
mockProvider(VirtualizationInstancesStore, { | ||
isLoadingDevices: () => false, | ||
selectedInstance: () => ({ id: 'my-instance' }), | ||
selectedInstanceDevices: () => [ | ||
{ | ||
dev_type: VirtualizationDeviceType.Usb, | ||
name: 'usb1', | ||
} as VirtualizationUsb, | ||
{ | ||
dev_type: VirtualizationDeviceType.Gpu, | ||
name: 'gpu1', | ||
}, | ||
{ | ||
name: 'proxy2', | ||
} as VirtualizationProxy, | ||
], | ||
loadDevices: jest.fn(), | ||
}), | ||
], | ||
}); | ||
|
||
beforeEach(() => { | ||
spectator = createComponent({ | ||
props: { | ||
instance: demoInstance, | ||
}, | ||
}); | ||
spectator = createComponent(); | ||
loader = TestbedHarnessEnvironment.loader(spectator.fixture); | ||
}); | ||
|
||
it('checks card title', () => { | ||
const title = spectator.query('h3'); | ||
expect(title).toHaveText('Devices'); | ||
it('shows a list of USB or GPU devices', () => { | ||
const devices = spectator.queryAll('.device'); | ||
|
||
expect(devices).toHaveLength(2); | ||
expect(devices[0]).toHaveText('usb1'); | ||
expect(devices[1]).toHaveText('gpu1'); | ||
}); | ||
|
||
it('renders details in card', () => { | ||
const chartExtra = spectator.query('mat-card-content').querySelectorAll('p'); | ||
expect(chartExtra).toHaveLength(2); | ||
expect(chartExtra[0]).toHaveText('Device Type: Gpu'); | ||
expect(chartExtra[1]).toHaveText('Device Type: Usb'); | ||
it('deletes a device with confirmation and reloads the list when delete icon is pressed', async () => { | ||
const deleteIcon = await loader.getHarness(IxIconHarness.with({ name: 'mdi-close' })); | ||
await deleteIcon.click(); | ||
|
||
expect(spectator.inject(DialogService).confirm).toHaveBeenCalled(); | ||
expect(spectator.inject(WebSocketService).call).toHaveBeenCalledWith('virt.instance.device_delete', ['my-instance', 'usb1']); | ||
expect(spectator.inject(VirtualizationInstancesStore).loadDevices).toHaveBeenCalled(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.