diff --git a/apps/datahub-e2e/src/e2e/datasetDetailPage.cy.ts b/apps/datahub-e2e/src/e2e/datasetDetailPage.cy.ts index 253060e2bc..8c0f0dda1c 100644 --- a/apps/datahub-e2e/src/e2e/datasetDetailPage.cy.ts +++ b/apps/datahub-e2e/src/e2e/datasetDetailPage.cy.ts @@ -703,7 +703,7 @@ describe('userFeedback', () => { cy.get('@commentText') .first() .then((div) => { - const premierCommentaireAvantTri = div.text().trim() + const firstCommentBeforeSort = div.text().trim() cy.get('@userFeedback') .find('gn-ui-dropdown-selector') .openDropdown() @@ -718,10 +718,8 @@ describe('userFeedback', () => { .find('[data-cy="commentText"]') .first() .then((div) => { - const premierCommentaireApresTri = div.text().trim() - expect(premierCommentaireAvantTri).to.not.eq( - premierCommentaireApresTri - ) + const firstCommentAfterSort = div.text().trim() + expect(firstCommentBeforeSort).to.not.eq(firstCommentAfterSort) }) }) }) @@ -736,11 +734,6 @@ describe('userFeedback', () => { beforeEach(() => { cy.login() cy.visit('/dataset/accroche_velos') - cy.get('datahub-record-user-feedbacks').as('userFeedback') - - cy.get('gn-ui-user-feedback-item') - .find('[data-cy="commentText"]') - .as('commentText') }) it('should publish a comment', () => { cy.get('datahub-record-user-feedbacks') diff --git a/apps/datahub/src/app/record/record-user-feedbacks/record-user-feedbacks.component.html b/apps/datahub/src/app/record/record-user-feedbacks/record-user-feedbacks.component.html index 80165511e5..29a7f9c157 100644 --- a/apps/datahub/src/app/record/record-user-feedbacks/record-user-feedbacks.component.html +++ b/apps/datahub/src/app/record/record-user-feedbacks/record-user-feedbacks.component.html @@ -21,7 +21,7 @@ - +
edit @@ -64,12 +64,12 @@
- +
edit record.metadata.userFeedbacks.anonymousUser diff --git a/apps/datahub/src/app/record/record-user-feedbacks/record-user-feedbacks.component.spec.ts b/apps/datahub/src/app/record/record-user-feedbacks/record-user-feedbacks.component.spec.ts index 282a87f9b0..2ccbb630f3 100644 --- a/apps/datahub/src/app/record/record-user-feedbacks/record-user-feedbacks.component.spec.ts +++ b/apps/datahub/src/app/record/record-user-feedbacks/record-user-feedbacks.component.spec.ts @@ -19,18 +19,24 @@ import { SOME_USER_FEEDBACKS, USER_FIXTURE, } from '@geonetwork-ui/common/fixtures' -import { UserFeedbackViewModel } from '@geonetwork-ui/common/domain/model/record' +import { + UserFeedback, + UserFeedbackViewModel, +} from '@geonetwork-ui/common/domain/model/record' import { Gn4PlatformMapper } from '@geonetwork-ui/api/repository' describe('RelatedRecordsComponent', () => { const allUserFeedbacks = SOME_USER_FEEDBACKS let mockDestroy$: Subject + const activeUser = USER_FIXTURE() + const mdViewFacadeMock: Partial = { isAllUserFeedbackLoading$: new BehaviorSubject(false), isAddUserFeedbackLoading$: new BehaviorSubject(false), loadUserFeedbacks: jest.fn(), userFeedbacks$: of(allUserFeedbacks), + addUserFeedback: jest.fn(), } const gn4PlatformMapperMock: Partial = { @@ -48,7 +54,7 @@ describe('RelatedRecordsComponent', () => { const platformServiceInterfaceMock: Partial = { getUserFeedbacks: jest.fn(), - getMe: jest.fn(() => new BehaviorSubject(USER_FIXTURE())), + getMe: jest.fn(() => new BehaviorSubject(activeUser)), } let component: RecordUserFeedbacksComponent @@ -127,4 +133,28 @@ describe('RelatedRecordsComponent', () => { ).toBe(2) }) }) + + describe('publishNewComment()', () => { + it('should publish the new userFeedback', () => { + const expectedNewUserFeedback: UserFeedback = { + uuid: undefined, + comment: 'TEST', + metadataUUID: 'accroche_velos', + parentUuid: null, + published: true, + date: expect.any(Date), + authorUserId: activeUser.id, + authorEmail: activeUser.email, + authorName: `${activeUser.name} ${activeUser.surname}`, + } + + component.newComment = 'TEST' + component.metadataUuid = 'accroche_velos' + fixture.detectChanges() + component.publishNewComment() + expect(mdViewFacadeMock.addUserFeedback).toHaveBeenCalledWith( + expectedNewUserFeedback + ) + }) + }) }) diff --git a/apps/datahub/src/app/record/record-user-feedbacks/record-user-feedbacks.component.ts b/apps/datahub/src/app/record/record-user-feedbacks/record-user-feedbacks.component.ts index 9492858153..7561f56215 100644 --- a/apps/datahub/src/app/record/record-user-feedbacks/record-user-feedbacks.component.ts +++ b/apps/datahub/src/app/record/record-user-feedbacks/record-user-feedbacks.component.ts @@ -18,6 +18,7 @@ import { DropdownChoice } from '@geonetwork-ui/ui/inputs' import { MdViewFacade } from '@geonetwork-ui/feature/record' import { TranslateService } from '@ngx-translate/core' import { AuthService, Gn4PlatformMapper } from '@geonetwork-ui/api/repository' +import { UserApiModel } from '@geonetwork-ui/data-access/gn4' type UserFeedbackSortingFunction = ( userFeedbackA: UserFeedback, @@ -175,8 +176,8 @@ export class RecordUserFeedbacksComponent implements OnInit, OnDestroy { } onNewUserFeedbackAnswer(newUserFeedback: UserFeedbackViewModel) { - delete newUserFeedback.avatarUrl - this.newUserFeedback(newUserFeedback) + const userFeedBack = this.mapper.userFeedbacksFromApi(newUserFeedback) + this.newUserFeedback(userFeedBack) } publishNewComment() { diff --git a/libs/api/repository/src/lib/gn4/platform/gn4-platform.mapper.ts b/libs/api/repository/src/lib/gn4/platform/gn4-platform.mapper.ts index f9d23f6c51..db5a54dfa1 100644 --- a/libs/api/repository/src/lib/gn4/platform/gn4-platform.mapper.ts +++ b/libs/api/repository/src/lib/gn4/platform/gn4-platform.mapper.ts @@ -73,7 +73,7 @@ export class Gn4PlatformMapper { }) } - userFeedbacksFromApi(userFeedback: UserFeedbackDTOApiModel): UserFeedback { + userFeedbacksFromApi(userFeedback: any): UserFeedback { return { uuid: userFeedback.uuid, metadataUUID: userFeedback.metadataUUID, diff --git a/libs/ui/elements/src/lib/user-feedback-item/user-feedback-item.component.html b/libs/ui/elements/src/lib/user-feedback-item/user-feedback-item.component.html index de422e844a..f91bd17d7e 100644 --- a/libs/ui/elements/src/lib/user-feedback-item/user-feedback-item.component.html +++ b/libs/ui/elements/src/lib/user-feedback-item/user-feedback-item.component.html @@ -52,7 +52,9 @@ [disabled]="isAddUserFeedbackLoading" [type]="'outline'" (buttonClick)="publishNewAnswer()" - title="Publish" + [title]=" + 'record.metadata.userFeedbacks.newAnswer.buttonTitle' | translate + " extraClass="!p-[0.5em] text-primary-darker border-primary-darker h-9" >