-
Notifications
You must be signed in to change notification settings - Fork 319
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
NAS-130332 / 25.04 / Fix remarks (#10439)
* NAS-130332: Fix remarks * NAS-130332: Rename SetTailLinesDialog to LogsDetailsDialog * NAS-130332: Add unit tests --------- Co-authored-by: Boris Vasilenko <[email protected]>
- Loading branch information
1 parent
aff8262
commit 014b60d
Showing
101 changed files
with
295 additions
and
333 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
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
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
77 changes: 77 additions & 0 deletions
77
src/app/pages/apps/components/installed-apps/pod-logs/pod-logs.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 |
---|---|---|
@@ -0,0 +1,77 @@ | ||
import { MatDialog, MatDialogRef } from '@angular/material/dialog'; | ||
import { ActivatedRoute } from '@angular/router'; | ||
import { Spectator, createComponentFactory, mockProvider } from '@ngneat/spectator/jest'; | ||
import { MockComponent, MockModule } from 'ng-mocks'; | ||
import { of } from 'rxjs'; | ||
import { mockAuth } from 'app/core/testing/utils/mock-auth.utils'; | ||
import { ToolbarSliderComponent } from 'app/modules/forms/toolbar-slider/toolbar-slider.component'; | ||
import { PageHeaderModule } from 'app/modules/page-header/page-header.module'; | ||
import { PodLogsComponent } from 'app/pages/apps/components/installed-apps/pod-logs/pod-logs.component'; | ||
import { LogsDetailsDialogComponent } from 'app/pages/apps/components/logs-details-dialog/logs-details-dialog.component'; | ||
import { WebSocketService } from 'app/services/ws.service'; | ||
|
||
describe('PodLogsComponent', () => { | ||
let spectator: Spectator<PodLogsComponent>; | ||
|
||
const createComponent = createComponentFactory({ | ||
component: PodLogsComponent, | ||
imports: [ | ||
MockModule(PageHeaderModule), | ||
], | ||
declarations: [ | ||
MockComponent(ToolbarSliderComponent), | ||
], | ||
providers: [ | ||
mockProvider(MatDialog, { | ||
open: jest.fn(() => ({ | ||
afterClosed: () => of({ | ||
tail_lines: 650, | ||
} as LogsDetailsDialogComponent['form']['value']), | ||
}) as unknown as MatDialogRef<LogsDetailsDialogComponent>), | ||
}), | ||
mockProvider(WebSocketService, { | ||
subscribeToLogs: jest.fn(() => of({ | ||
fields: { | ||
timestamp: '[12:34]', | ||
data: 'Some logs.', | ||
}, | ||
})), | ||
}), | ||
mockAuth(), | ||
{ | ||
provide: ActivatedRoute, | ||
useValue: { | ||
parent: { | ||
params: of({ appId: 'ix-test-app' }), | ||
}, | ||
params: of({ containerId: 'ix-test-container' }), | ||
}, | ||
}, | ||
], | ||
}); | ||
|
||
beforeEach(() => { | ||
spectator = createComponent(); | ||
}); | ||
|
||
it('subscribes to logs updates', () => { | ||
expect(spectator.inject(MatDialog).open).toHaveBeenCalledWith(LogsDetailsDialogComponent, { width: '400px' }); | ||
|
||
expect(spectator.inject(WebSocketService).subscribeToLogs).toHaveBeenCalledWith( | ||
'app.container_log_follow: {"app_name":"ix-test-app","container_id":"ix-test-container","tail_lines":650}', | ||
); | ||
}); | ||
|
||
it('shows meta data', () => { | ||
expect(spectator.queryAll('.meta-data .name').map((name) => name.textContent.trim())).toEqual([ | ||
'ix-test-app', | ||
'ix-test-container', | ||
]); | ||
}); | ||
|
||
it('shows logs', () => { | ||
expect(spectator.queryAll('.log-row').map((name) => name.textContent.trim())).toEqual([ | ||
'[12:34]Some logs.', | ||
]); | ||
}); | ||
}); |
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
31 changes: 31 additions & 0 deletions
31
src/app/pages/apps/components/logs-details-dialog/logs-details-dialog.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 |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<h1 mat-dialog-title>{{ 'Logs Details' | translate }}</h1> | ||
|
||
<form class="ix-form-container" [formGroup]="form"> | ||
<ix-input | ||
formControlName="tail_lines" | ||
type="number" | ||
[label]="'Tail Lines' | translate" | ||
[required]="true" | ||
></ix-input> | ||
|
||
<div mat-dialog-actions align="end"> | ||
<button | ||
mat-button | ||
type="button" | ||
matDialogClose | ||
ixTest="cancel" | ||
> | ||
{{ 'Cancel' | translate }} | ||
</button> | ||
<button | ||
mat-button | ||
type="submit" | ||
color="primary" | ||
ixTest="choose" | ||
[disabled]="form.invalid" | ||
[matDialogClose]="this.form.value" | ||
> | ||
{{ 'Connect' | translate }} | ||
</button> | ||
</div> | ||
</form> |
46 changes: 46 additions & 0 deletions
46
src/app/pages/apps/components/logs-details-dialog/logs-details-dialog.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 |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import { HarnessLoader } from '@angular/cdk/testing'; | ||
import { TestbedHarnessEnvironment } from '@angular/cdk/testing/testbed'; | ||
import { ReactiveFormsModule } from '@angular/forms'; | ||
import { MatButtonHarness } from '@angular/material/button/testing'; | ||
import { MatDialogRef } from '@angular/material/dialog'; | ||
import { createComponentFactory, mockProvider, Spectator } from '@ngneat/spectator/jest'; | ||
import { IxFormsModule } from 'app/modules/forms/ix-forms/ix-forms.module'; | ||
import { IxFormHarness } from 'app/modules/forms/ix-forms/testing/ix-form.harness'; | ||
import { LogsDetailsDialogComponent } from 'app/pages/apps/components/logs-details-dialog/logs-details-dialog.component'; | ||
|
||
describe('LogsDetailsDialogComponent', () => { | ||
let loader: HarnessLoader; | ||
let form: IxFormHarness; | ||
let spectator: Spectator<LogsDetailsDialogComponent>; | ||
const createComponent = createComponentFactory({ | ||
component: LogsDetailsDialogComponent, | ||
imports: [ | ||
ReactiveFormsModule, | ||
IxFormsModule, | ||
], | ||
providers: [ | ||
mockProvider(MatDialogRef), | ||
], | ||
}); | ||
|
||
beforeEach(async () => { | ||
spectator = createComponent(); | ||
loader = TestbedHarnessEnvironment.loader(spectator.fixture); | ||
form = await loader.getHarness(IxFormHarness); | ||
}); | ||
|
||
it('dialog should be closed when Reconnect is pressed', async () => { | ||
await form.fillForm({ 'Tail Lines': 600 }); | ||
const valueLogsForm = await form.getValues(); | ||
|
||
expect(valueLogsForm).toEqual({ | ||
'Tail Lines': '600', | ||
}); | ||
|
||
const connectButton = await loader.getHarness(MatButtonHarness.with({ text: 'Connect' })); | ||
await connectButton.click(); | ||
expect(spectator.inject(MatDialogRef).close).toHaveBeenCalledWith({ | ||
tail_lines: 600, | ||
}); | ||
}); | ||
}); |
21 changes: 21 additions & 0 deletions
21
src/app/pages/apps/components/logs-details-dialog/logs-details-dialog.component.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 |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { | ||
ChangeDetectionStrategy, Component, | ||
} from '@angular/core'; | ||
import { FormBuilder, Validators } from '@angular/forms'; | ||
import { UntilDestroy } from '@ngneat/until-destroy'; | ||
|
||
@UntilDestroy() | ||
@Component({ | ||
selector: 'ix-logs-details-dialog', | ||
templateUrl: './logs-details-dialog.component.html', | ||
changeDetection: ChangeDetectionStrategy.OnPush, | ||
}) | ||
export class LogsDetailsDialogComponent { | ||
form = this.fb.group({ | ||
tail_lines: [500, [Validators.required]], | ||
}); | ||
|
||
constructor( | ||
private fb: FormBuilder, | ||
) {} | ||
} |
59 changes: 0 additions & 59 deletions
59
src/app/pages/apps/components/pod-select-logs/pod-select-logs-dialog.component.html
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.