Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ import { of } from 'rxjs';
import { FakeFormatDateTimePipe } from 'app/core/testing/classes/fake-format-datetime.pipe';
import { mockCall, mockApi } from 'app/core/testing/utils/mock-api.utils';
import { mockAuth } from 'app/core/testing/utils/mock-auth.utils';
import { BootEnvironment } from 'app/interfaces/boot-environment.interface';
import { DialogService } from 'app/modules/dialog/dialog.service';
import { BasicSearchComponent } from 'app/modules/forms/search-input/components/basic-search/basic-search.component';
import { IxIconHarness } from 'app/modules/ix-icon/ix-icon.harness';
import { IxTableHarness } from 'app/modules/ix-table/components/ix-table/ix-table.harness';
import { LocaleService } from 'app/modules/language/locale.service';
import { PageHeaderComponent } from 'app/modules/page-header/page-title-header/page-header.component';
Expand All @@ -23,6 +25,23 @@ describe('BootEnvironmentListComponent', () => {
let api: ApiService;
let table: IxTableHarness;

const bootEnvironmentsWithKeep = [
...fakeBootEnvironmentsDataSource,
{
id: '25.04.0-MASTER-20241020-084512',
dataset: 'boot-pool/ROOT/25.04.0-MASTER-20241020-084512',
active: false,
activated: false,
created: {
$date: 1729411512000,
},
used_bytes: 3100000000,
used: '2.88 GiB',
keep: true,
can_activate: true,
} as BootEnvironment,
];

const createComponent = createComponentFactory({
component: BootEnvironmentListComponent,
imports: [
Expand All @@ -37,7 +56,8 @@ describe('BootEnvironmentListComponent', () => {
timezone: 'America/Los_Angeles',
}),
mockApi([
mockCall('boot.environment.query', fakeBootEnvironmentsDataSource),
mockCall('boot.environment.query', bootEnvironmentsWithKeep),
mockCall('boot.environment.keep'),
]),
mockProvider(DialogService, {
confirm: jest.fn(() => of(true)),
Expand Down Expand Up @@ -80,9 +100,58 @@ describe('BootEnvironmentListComponent', () => {
'No',
'',
],
[
'',
'25.04.0-MASTER-20241020-084512',
'No',
'2024-10-20 01:05:12',
'2.89 GiB',
'Yes',
'',
],
];

expect(api.call).toHaveBeenCalledWith('boot.environment.query');
expect(cells).toEqual(expectedRows);
});

it('shows "Keep" action with outline bookmark icon when keep is false', async () => {
const keepIcon = await table.getHarnessInCell(IxIconHarness.with({ name: 'bookmark_border' }), 1, 6);
expect(keepIcon).toBeDefined();
});

it('shows "Unkeep" action with filled bookmark icon when keep is true', async () => {
const unkeepIcon = await table.getHarnessInCell(IxIconHarness.with({ name: 'bookmark' }), 3, 6);
expect(unkeepIcon).toBeDefined();
});

it('calls API to set keep flag when Keep action is clicked', async () => {
const keepIcon = await table.getHarnessInCell(IxIconHarness.with({ name: 'bookmark_border' }), 1, 6);
await keepIcon.click();

expect(spectator.inject(DialogService).confirm).toHaveBeenCalledWith({
title: 'Keep',
message: 'Keep this Boot Environment?',
buttonText: 'Set Keep Flag',
});

expect(api.call).toHaveBeenCalledWith('boot.environment.keep', [
{ id: '25.04.0-MASTER-20241105-224807', value: true },
]);
});

it('calls API to remove keep flag when Unkeep action is clicked', async () => {
const unkeepIcon = await table.getHarnessInCell(IxIconHarness.with({ name: 'bookmark' }), 3, 6);
await unkeepIcon.click();

expect(spectator.inject(DialogService).confirm).toHaveBeenCalledWith({
title: 'Unkeep',
message: 'No longer keep this Boot Environment?',
buttonText: 'Remove Keep Flag',
});

expect(api.call).toHaveBeenCalledWith('boot.environment.keep', [
{ id: '25.04.0-MASTER-20241020-084512', value: false },
]);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -160,14 +160,14 @@ export class BootEnvironmentListComponent implements OnInit {
onClick: (row) => this.doActivate(row),
},
{
iconName: iconMarker('bookmark'),
iconName: iconMarker('bookmark_border'),
requiredRoles: this.requiredRoles,
tooltip: this.translate.instant('Keep'),
hidden: (row) => of(row.keep),
onClick: (row) => this.toggleKeep(row),
},
{
iconName: iconMarker('bookmark_border'),
iconName: iconMarker('bookmark'),
requiredRoles: this.requiredRoles,
tooltip: this.translate.instant('Unkeep'),
hidden: (row) => of(!row.keep),
Expand Down
Loading