Skip to content

Commit

Permalink
Code review fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Romuald Caplier committed Apr 29, 2024
1 parent 651d488 commit dd46dc9
Show file tree
Hide file tree
Showing 14 changed files with 53 additions and 19 deletions.
13 changes: 3 additions & 10 deletions apps/datahub-e2e/src/e2e/datasetDetailPage.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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)
})
})
})
Expand All @@ -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')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
</ng-container>

<ng-template #userFeedbacksSection>
<ng-container *ngIf="activeUser; else annonymousUser">
<ng-container *ngIf="activeUser; else anonymousUser">
<div class="flex flex-col h-auto w-full">
<div class="flex flex-row items-center w-full h-auto gap-3 px-6">
<mat-icon class="material-symbols-outlined grow-0">edit</mat-icon>
Expand Down Expand Up @@ -64,12 +64,12 @@
</div>
</div>
</ng-container>
<ng-template #annonymousUser>
<ng-template #anonymousUser>
<div class="flex flex-row items-center gap-3 w-full h-auto px-6">
<mat-icon class="material-symbols-outlined grow-0">edit</mat-icon>
<span translate>record.metadata.userFeedbacks.anonymousUser</span>
<a
[href]="this.loginUrl"
[href]="loginUrl"
class="gn-ui-btn-primary uppercase flex flex-row items-center gap-2 ml-auto"
translate
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<void>

const activeUser = USER_FIXTURE()

const mdViewFacadeMock: Partial<MdViewFacade> = {
isAllUserFeedbackLoading$: new BehaviorSubject(false),
isAddUserFeedbackLoading$: new BehaviorSubject(false),
loadUserFeedbacks: jest.fn(),
userFeedbacks$: of(allUserFeedbacks),
addUserFeedback: jest.fn(),
}

const gn4PlatformMapperMock: Partial<Gn4PlatformMapper> = {
Expand All @@ -48,7 +54,7 @@ describe('RelatedRecordsComponent', () => {

const platformServiceInterfaceMock: Partial<PlatformServiceInterface> = {
getUserFeedbacks: jest.fn(),
getMe: jest.fn(() => new BehaviorSubject(USER_FIXTURE())),
getMe: jest.fn(() => new BehaviorSubject(activeUser)),
}

let component: RecordUserFeedbacksComponent
Expand Down Expand Up @@ -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
)
})
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export class Gn4PlatformMapper {
})
}

userFeedbacksFromApi(userFeedback: UserFeedbackDTOApiModel): UserFeedback {
userFeedbacksFromApi(userFeedback: any): UserFeedback {
return {
uuid: userFeedback.uuid,
metadataUUID: userFeedback.metadataUUID,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
>
<mat-icon
Expand Down
1 change: 1 addition & 0 deletions translations/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,7 @@
"record.metadata.userFeedbacks.sortSelector.choices.oldestFirst": "",
"record.metadata.userFeedbacks.newComment.placeholder": "",
"record.metadata.userFeedbacks.newAnswer.placeholder": "",
"record.metadata.userFeedbacks.newAnswer.buttonTitle": "",
"record.metadata.sheet": "Weitere Informationen verfügbar unter:",
"record.metadata.status": "Status",
"record.metadata.technical": "Technische Informationen",
Expand Down
1 change: 1 addition & 0 deletions translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,7 @@
"record.metadata.userFeedbacks.sortSelector.choices.oldestFirst": "Oldest comments first",
"record.metadata.userFeedbacks.newComment.placeholder": "Write your comment here...",
"record.metadata.userFeedbacks.newAnswer.placeholder": "Answer...",
"record.metadata.userFeedbacks.newAnswer.buttonTitle": "Publish",
"record.metadata.sheet": "Original metadata",
"record.metadata.status": "Status",
"record.metadata.technical": "Technical information",
Expand Down
1 change: 1 addition & 0 deletions translations/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,7 @@
"record.metadata.userFeedbacks.sortSelector.choices.oldestFirst": "",
"record.metadata.userFeedbacks.newComment.placeholder": "",
"record.metadata.userFeedbacks.newAnswer.placeholder": "",
"record.metadata.userFeedbacks.newAnswer.buttonTitle": "",
"record.metadata.sheet": "",
"record.metadata.status": "",
"record.metadata.technical": "",
Expand Down
1 change: 1 addition & 0 deletions translations/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,7 @@
"record.metadata.userFeedbacks.sortSelector.choices.oldestFirst": "Les plus anciens en premier",
"record.metadata.userFeedbacks.newComment.placeholder": "Rédiger votre commentaire ici...",
"record.metadata.userFeedbacks.newAnswer.placeholder": "Répondre...",
"record.metadata.userFeedbacks.newAnswer.buttonTitle": "Publier",
"record.metadata.sheet": "Fiche de métadonnées d'origine",
"record.metadata.status": "Statut",
"record.metadata.technical": "Informations techniques",
Expand Down
1 change: 1 addition & 0 deletions translations/it.json
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,7 @@
"record.metadata.userFeedbacks.sortSelector.choices.oldestFirst": "",
"record.metadata.userFeedbacks.newComment.placeholder": "",
"record.metadata.userFeedbacks.newAnswer.placeholder": "",
"record.metadata.userFeedbacks.newAnswer.buttonTitle": "",
"record.metadata.sheet": "Origine del metadata",
"record.metadata.status": "Stato",
"record.metadata.technical": "Informazioni tecniche",
Expand Down
1 change: 1 addition & 0 deletions translations/nl.json
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,7 @@
"record.metadata.userFeedbacks.sortSelector.choices.oldestFirst": "",
"record.metadata.userFeedbacks.newComment.placeholder": "",
"record.metadata.userFeedbacks.newAnswer.placeholder": "",
"record.metadata.userFeedbacks.newAnswer.buttonTitle": "",
"record.metadata.sheet": "",
"record.metadata.status": "",
"record.metadata.technical": "",
Expand Down
1 change: 1 addition & 0 deletions translations/pt.json
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,7 @@
"record.metadata.userFeedbacks.sortSelector.choices.oldestFirst": "",
"record.metadata.userFeedbacks.newComment.placeholder": "",
"record.metadata.userFeedbacks.newAnswer.placeholder": "",
"record.metadata.userFeedbacks.newAnswer.buttonTitle": "",
"record.metadata.sheet": "",
"record.metadata.status": "",
"record.metadata.technical": "",
Expand Down
1 change: 1 addition & 0 deletions translations/sk.json
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,7 @@
"record.metadata.userFeedbacks.sortSelector.choices.oldestFirst": "",
"record.metadata.userFeedbacks.newComment.placeholder": "",
"record.metadata.userFeedbacks.newAnswer.placeholder": "",
"record.metadata.userFeedbacks.newAnswer.buttonTitle": "",
"record.metadata.sheet": "Ďalšie metadáta sú k dispozícii na:",
"record.metadata.status": "Stav",
"record.metadata.technical": "",
Expand Down

0 comments on commit dd46dc9

Please sign in to comment.