-
Notifications
You must be signed in to change notification settings - Fork 4
[NAE-2416] AbstractFileDefaultFieldComponent does not push upload event #326
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: release/7.0.0-rev10
Are you sure you want to change the base?
Changes from all commits
c3755d2
4d83a81
1a5e592
7594f6a
340d259
b859995
26db136
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,8 +1,8 @@ | ||
| import {ComponentFixture, TestBed, waitForAsync} from "@angular/core/testing"; | ||
| import {ComponentFixture, inject, TestBed, waitForAsync} from "@angular/core/testing"; | ||
| import {MaterialModule} from "../../../material/material.module"; | ||
| import {AngularResizeEventModule} from "angular-resize-event"; | ||
| import {BrowserAnimationsModule} from "@angular/platform-browser/animations"; | ||
| import {HttpClientTestingModule} from "@angular/common/http/testing"; | ||
| import {HttpClientTestingModule, HttpTestingController} from "@angular/common/http/testing"; | ||
| import {TranslateLibModule} from "../../../translate/translate-lib.module"; | ||
| import {SnackBarModule} from "../../../snack-bar/snack-bar.module"; | ||
| import {SideMenuService} from "../../../side-menu/services/side-menu.service"; | ||
|
|
@@ -16,9 +16,6 @@ import {MockUserResourceService} from "../../../utility/tests/mocks/mock-user-re | |
| import {ConfigurationService} from "../../../configuration/configuration.service"; | ||
| import {TestConfigurationService} from "../../../utility/tests/test-config"; | ||
| import {Component, CUSTOM_ELEMENTS_SCHEMA, Inject, Optional} from "@angular/core"; | ||
| import {BrowserDynamicTestingModule} from "@angular/platform-browser-dynamic/testing"; | ||
| import {ErrorSnackBarComponent} from "../../../snack-bar/components/error-snack-bar/error-snack-bar.component"; | ||
| import {SuccessSnackBarComponent} from "../../../snack-bar/components/success-snack-bar/success-snack-bar.component"; | ||
| import {TaskResourceService} from "../../../resources/engine-endpoint/task-resource.service"; | ||
| import {LoggerService} from "../../../logger/services/logger.service"; | ||
| import {SnackBarService} from "../../../snack-bar/services/snack-bar.service"; | ||
|
|
@@ -28,6 +25,9 @@ import {DATA_FIELD_PORTAL_DATA, DataFieldPortalData} from "../../models/data-fie | |
| import {AbstractFileListDefaultFieldComponent} from "./abstract-file-list-default-field.component"; | ||
| import {FormControl} from "@angular/forms"; | ||
| import {WrappedBoolean} from "../../data-field-template/models/wrapped-boolean"; | ||
| import {FrontActionService} from "../../../actions/services/front-action.service"; | ||
| import {AbstractFileListFieldComponent} from "../abstract-file-list-field.component"; | ||
| import {NAE_INFORM_ABOUT_INVALID_DATA} from "../../models/invalid-data-policy-token"; | ||
|
|
||
| describe('AbstractFileListDefaultFieldComponent', () => { | ||
| let component: TestFileListComponent; | ||
|
|
@@ -46,6 +46,7 @@ describe('AbstractFileListDefaultFieldComponent', () => { | |
| providers: [ | ||
| SideMenuService, | ||
| EventService, | ||
| FrontActionService, | ||
| {provide: AuthenticationMethodService, useClass: MockAuthenticationMethodService}, | ||
| {provide: AuthenticationService, useClass: MockAuthenticationService}, | ||
| {provide: UserResourceService, useClass: MockUserResourceService}, | ||
|
|
@@ -79,23 +80,36 @@ describe('AbstractFileListDefaultFieldComponent', () => { | |
| expect(component).toBeTruthy(); | ||
| }); | ||
|
|
||
| it('should call download method successfully', () => { | ||
| spyOn(component, 'download').and.callThrough(); // Spy on the method | ||
| component.download("test"); // Call the method | ||
| expect(component.download).toHaveBeenCalled(); // Assert that it was called | ||
| }); | ||
|
|
||
| it('should call upload method successfully', () => { | ||
| spyOn(component, 'upload').and.callThrough(); // Spy on the method | ||
| component.upload(); // Call the method | ||
| expect(component.upload).toHaveBeenCalled(); // Assert that it was called | ||
| }); | ||
|
Comment on lines
+83
to
+93
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These tests are self-fulfilling and don’t verify behavior. On Lines 84-93, each test spies on a method, calls the same method, then asserts it was called. This still passes even if internal logic breaks. Please assert observable effects (e.g., service calls, state changes, snackbar calls, or early-return guards). 🤖 Prompt for AI Agents |
||
|
|
||
| afterEach(() => { | ||
| TestBed.resetTestingModule(); | ||
| }); | ||
| }); | ||
|
|
||
| @Component({ | ||
| selector: 'ncc-test-filelist', | ||
| template: '' | ||
| template: '<input type="file" #fileUploadInput name="fileUpload" [multiple]="true" accept="{{dataField.allowTypes}}" class="invisible-input"/>' | ||
| }) | ||
| class TestFileListComponent extends AbstractFileListDefaultFieldComponent { | ||
| constructor(taskResourceService: TaskResourceService, | ||
| log: LoggerService, | ||
| snackbar: SnackBarService, | ||
| translate: TranslateService, | ||
| eventService: EventService, | ||
| frontActionService: FrontActionService, | ||
| @Optional() @Inject(DATA_FIELD_PORTAL_DATA) dataFieldPortalData: DataFieldPortalData<FileListField>) { | ||
| super(taskResourceService, log, snackbar, translate, eventService, dataFieldPortalData); | ||
| super(taskResourceService, log, snackbar, translate, eventService, frontActionService, dataFieldPortalData); | ||
| } | ||
| } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These tests are tautological and can still miss regressions.
At Line 84 and Line 90, the spec spies on a method and then directly calls that same method, so it only proves the test invocation happened—not upload/download behavior. With
callThrough(), it can also execute real side effects and make tests flaky. Please assert observable behavior/dependency interactions (success + error paths) instead of self-invocation.🤖 Prompt for AI Agents