Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

[#46150] Fixes for tests

Eric Schubert93a19fd57d9a
diff --git a/frontend/src/app/core/apiv3/endpoints/work_packages/work-package-cache.spec.ts b/frontend/src/app/core/apiv3/endpoints/work_packages/work-package-cache.spec.ts
index 1c7195d1ad4..3fb69bc4a3b 100644
--- a/frontend/src/app/core/apiv3/endpoints/work_packages/work-package-cache.spec.ts
+++ b/frontend/src/app/core/apiv3/endpoints/work_packages/work-package-cache.spec.ts
@@ -40,8 +40,6 @@ import { WorkPackagesActivityService } from 'core-app/features/work-packages/com
import { ConfigurationService } from 'core-app/core/config/configuration.service';
import { WorkPackageNotificationService } from 'core-app/features/work-packages/services/notifications/work-package-notification.service';
import { WorkPackageCache } from 'core-app/core/apiv3/endpoints/work_packages/work-package.cache';
-import { OpenProjectFileUploadService } from 'core-app/core/file-upload/op-file-upload.service';
-import { OpenProjectDirectFileUploadService } from 'core-app/core/file-upload/op-direct-file-upload.service';
import { TimezoneService } from 'core-app/core/datetime/timezone.service';
import { HalResourceNotificationService } from 'core-app/features/hal/services/hal-resource-notification.service';
import { OpenprojectHalModule } from 'core-app/features/hal/openproject-hal.module';
@@ -73,8 +71,6 @@ describe('WorkPackageCache', () => {
{ provide: ToastService, useValue: {} },
{ provide: HalResourceNotificationService, useValue: { handleRawError: () => false } },
{ provide: WorkPackageNotificationService, useValue: {} },
- { provide: OpenProjectFileUploadService, useValue: {} },
- { provide: OpenProjectDirectFileUploadService, useValue: {} },
],
});
diff --git a/frontend/src/app/core/state/attachments/attachments.service.ts b/frontend/src/app/core/state/attachments/attachments.service.ts
index fb5ba78b2f8..fc180a7e27f 100644
--- a/frontend/src/app/core/state/attachments/attachments.service.ts
+++ b/frontend/src/app/core/state/attachments/attachments.service.ts
@@ -126,15 +126,16 @@ export class AttachmentsResourceService extends ResourceCollectionService<IAttac
* @param resource The HAL resource to attach the files to
* @param files The upload files to be attached.
*/
- attachFiles(resource:HalResource, files:IUploadFile[]):Observable<IAttachment[]> {
+ attachFiles(resource:HalResource, files:File[]):Observable<IAttachment[]> {
const identifier = AttachmentsResourceService.getAttachmentsSelfLink(resource) || HAL_NEW_RESOURCE_ID;
const href = this.getUploadTarget(resource);
+ const uploadFiles = files.map((file) => ({ file }));
return this
.addAttachments(
identifier,
href,
- files,
+ uploadFiles,
);
}
diff --git a/frontend/src/app/features/hal/resources/mixins/attachable-mixin.ts b/frontend/src/app/features/hal/resources/mixins/attachable-mixin.ts
index 8ce0889f188..9c235c83d6a 100644
--- a/frontend/src/app/features/hal/resources/mixins/attachable-mixin.ts
+++ b/frontend/src/app/features/hal/resources/mixins/attachable-mixin.ts
@@ -47,5 +47,18 @@ export function Attachable<TBase extends Constructor<HalResource>>(Base:TBase) {
public get canAddAttachments():boolean {
return !!((this as HalResource).$links as unknown&{ addAttachment?:HalLink }).addAttachment || isNewResource(this);
}
+
+ /**
+ * Try to find an existing file's download URL given its filename
+ * @param file
+ */
+ public lookupDownloadLocationByName(file:string):string|null {
+ if (!(this.attachments && this.attachments.elements)) {
+ return null;
+ }
+
+ const match = this.attachments.elements.find((res:HalResource) => res.name === file);
+ return !match ? null : (match.staticDownloadLocation as HalLink)?.href;
+ }
};
}
diff --git a/frontend/src/app/features/hal/resources/work-package-resource.spec.ts b/frontend/src/app/features/hal/resources/work-package-resource.spec.ts
index 53f3bc90513..65f7c800edf 100644
--- a/frontend/src/app/features/hal/resources/work-package-resource.spec.ts
+++ b/frontend/src/app/features/hal/resources/work-package-resource.spec.ts
@@ -41,8 +41,6 @@ import { WorkPackageCreateService } from 'core-app/features/work-packages/compon
import { WorkPackageNotificationService } from 'core-app/features/work-packages/services/notifications/work-package-notification.service';
import { WorkPackagesActivityService } from 'core-app/features/work-packages/components/wp-single-view-tabs/activity-panel/wp-activity.service';
import { ApiV3Service } from 'core-app/core/apiv3/api-v3.service';
-import { OpenProjectFileUploadService } from 'core-app/core/file-upload/op-file-upload.service';
-import { OpenProjectDirectFileUploadService } from 'core-app/core/file-upload/op-direct-file-upload.service';
import { TimezoneService } from 'core-app/core/datetime/timezone.service';
import { AttachmentCollectionResource } from 'core-app/features/hal/resources/attachment-collection-resource';
import { OpenprojectHalModule } from 'core-app/features/hal/openproject-hal.module';
@@ -83,8 +81,6 @@ describe('WorkPackage', () => {
WorkPackagesActivityService,
{ provide: WeekdayService, useValue: WeekdayServiceStub },
ConfigurationService,
- OpenProjectFileUploadService,
- OpenProjectDirectFileUploadService,
LoadingIndicatorService,
PathHelperService,
I18nService,
@@ -155,68 +151,4 @@ describe('WorkPackage', () => {
createWorkPackage();
});
});
-
- describe('when using removeAttachment', () => {
- let file:any;
- let attachment:any;
-
- beforeEach(() => {
- file = {};
- attachment = {
- $isHal: true,
- delete: () => undefined,
- };
-
- createWorkPackage();
- workPackage.attachments.elements = [attachment];
- });
-
- describe('when the attachment is an attachment resource', () => {
- beforeEach(() => {
- attachment.delete = jasmine.createSpy('delete').and.returnValue(Promise.resolve());
- spyOn(workPackage, 'updateAttachments');
- });
-
- it('should call its delete method', (done) => {
- workPackage.removeAttachment(attachment).then(() => {
- expect(attachment.delete).toHaveBeenCalled();
- done();
- });
- });
-
- describe('when the deletion gets resolved', () => {
- it('should call updateAttachments()', (done) => {
- workPackage.removeAttachment(attachment).then(() => {
- expect(workPackage.updateAttachments).toHaveBeenCalled();
- done();
- });
- });
- });
-
- describe('when an error occurs', () => {
- let errorStub:jasmine.Spy;
-
- beforeEach(() => {
- attachment.delete = jasmine.createSpy('delete')
- .and.returnValue(Promise.reject({ foo: 'bar' }));
-
- errorStub = spyOn(halResourceNotification, 'handleRawError');
- });
-
- it('should call the handleRawError notification', (done) => {
- workPackage.removeAttachment(attachment).then(() => {
- expect(errorStub).toHaveBeenCalled();
- done();
- });
- });
-
- it('should not remove the attachment from the elements array', (done) => {
- workPackage.removeAttachment(attachment).then(() => {
- expect(workPackage.attachments.elements.length).toEqual(1);
- done();
- });
- });
- });
- });
- });
});
diff --git a/frontend/src/app/features/work-packages/components/wp-edit-form/work-package-filter-values.spec.ts b/frontend/src/app/features/work-packages/components/wp-edit-form/work-package-filter-values.spec.ts
index ee5d7bbd2c2..b16a60b3813 100644
--- a/frontend/src/app/features/work-packages/components/wp-edit-form/work-package-filter-values.spec.ts
+++ b/frontend/src/app/features/work-packages/components/wp-edit-form/work-package-filter-values.spec.ts
@@ -51,8 +51,6 @@ import { IsolatedQuerySpace } from 'core-app/features/work-packages/directives/q
import { HalEventsService } from 'core-app/features/hal/services/hal-events.service';
import { WorkPackageChangeset } from 'core-app/features/work-packages/components/wp-edit/work-package-changeset';
import { WorkPackageNotificationService } from 'core-app/features/work-packages/services/notifications/work-package-notification.service';
-import { OpenProjectFileUploadService } from 'core-app/core/file-upload/op-file-upload.service';
-import { OpenProjectDirectFileUploadService } from 'core-app/core/file-upload/op-direct-file-upload.service';
import { TimezoneService } from 'core-app/core/datetime/timezone.service';
import { WeekdayService } from 'core-app/core/days/weekday.service';
import { of } from 'rxjs';
@@ -90,8 +88,6 @@ describe('WorkPackageFilterValues', () => {
ConfigurationService,
CurrentUserService,
HookService,
- OpenProjectFileUploadService,
- OpenProjectDirectFileUploadService,
LoadingIndicatorService,
HalResourceService,
ToastService,
diff --git a/frontend/src/app/shared/components/attachments/attachments.component.ts b/frontend/src/app/shared/components/attachments/attachments.component.ts
index 8981144f77b..e34dc86cfd0 100644
--- a/frontend/src/app/shared/components/attachments/attachments.component.ts
+++ b/frontend/src/app/shared/components/attachments/attachments.component.ts
@@ -49,7 +49,7 @@ import { UntilDestroyedMixin } from 'core-app/shared/helpers/angular/until-destr
import { populateInputsFromDataset } from 'core-app/shared/components/dataset-inputs';
import { AttachmentsResourceService } from 'core-app/core/state/attachments/attachments.service';
import { ToastService } from 'core-app/shared/components/toaster/toast.service';
-import { IUploadFile, OpUploadService } from 'core-app/core/upload/upload.service';
+import { OpUploadService } from 'core-app/core/upload/upload.service';
import { TimezoneService } from 'core-app/core/datetime/timezone.service';
import { IAttachment } from 'core-app/core/state/attachments/attachment.model';
import isNewResource from 'core-app/features/hal/helpers/is-new-resource';
@@ -239,11 +239,9 @@ export class OpAttachmentsComponent extends UntilDestroyedMixin implements OnIni
return;
}
- const uploadFiles:IUploadFile[] = filesWithoutFolders.map((file) => ({ file }));
-
this
.attachmentsResourceService
- .attachFiles(this.resource, uploadFiles)
+ .attachFiles(this.resource, filesWithoutFolders)
.subscribe();
}
diff --git a/spec/features/forums/attachment_upload_spec.rb b/spec/features/forums/attachment_upload_spec.rb
index 240996e6351..99fbb933db2 100644
--- a/spec/features/forums/attachment_upload_spec.rb
+++ b/spec/features/forums/attachment_upload_spec.rb
@@ -56,6 +56,7 @@ describe 'Upload attachment to forum message', js: true do
create_page.set_subject 'A new message'
# adding an image
+ sleep 20
editor.drag_attachment image_fixture.path, 'Image uploaded on creation'
expect(page).to have_selector('[data-qa-selector="op-attachment-list-item"]', text: 'image.png')
diff --git a/spec/features/wiki/attachment_upload_spec.rb b/spec/features/wiki/attachment_upload_spec.rb
index 43ab7b7d4ba..99593e31721 100644
--- a/spec/features/wiki/attachment_upload_spec.rb
+++ b/spec/features/wiki/attachment_upload_spec.rb
@@ -78,7 +78,7 @@ describe 'Upload attachment to wiki page', js: true do
editor.in_editor do |container, _|
# Expect URL is mapped to the correct URL
- expect(container).to have_selector('img[src^="/api/v3/attachments/"]')
+ expect(container).to have_selector('img[src^="/api/v3/attachments/"]', count: 2)
expect(container).not_to have_selector('img[src="image.png"]')
container.find('img[src^="/api/v3/attachments/"]', match: :first).click