Skip to content
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

Communication: Highlight solution answer in thread #9998

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,15 @@
}}
</span>
</span>
@if (isResolvesPostSet()) {
<span class="post-header-solution">
<span
class="badge bg-info ms-2"
jhiTranslate="artemisApp.metis.post.resolvesPost"
ngbTooltip="{{ 'artemisApp.metis.post.resolvesPost' | artemisTranslate }}"
></span>
</span>
}
@if (!!isCommunicationPage && (!lastReadDate || (lastReadDate && posting.creationDate && posting.creationDate.isAfter(lastReadDate))) && !isAuthorOfPosting) {
<span jhiTranslate="global.generic.new" class="badge bg-secondary hideAfter5Seconds"></span>
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,9 @@ export class AnswerPostHeaderComponent extends PostingHeaderDirective<AnswerPost
this.setUserProperties();
this.setUserAuthorityIconAndTooltip();
}

isResolvesPostSet(): boolean {
//Check if the post is a resolves post and if the attribute is not set return false
return this.posting.resolvesPost !== undefined && this.posting.resolvesPost;
}
}
1 change: 1 addition & 0 deletions src/main/webapp/i18n/de/metis.json
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@
"collapseContent": "Inhalt einklappen",
"addReaction": "Reaktion hinzufügen",
"pinMessage": "Nachricht anheften",
"resolvesPost": "Lösung",
"unpinMessage": "Nachricht lösen",
"editMessage": "Nachricht bearbeiten",
"deleteMessage": "Nachricht löschen",
Expand Down
1 change: 1 addition & 0 deletions src/main/webapp/i18n/en/metis.json
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@
"collapseContent": "Collapse content",
"addReaction": "Add reaction",
"pinMessage": "Pin message",
"resolvesPost": "Solution",
"unpinMessage": "Unpin message",
"editMessage": "Edit message",
"deleteMessage": "Delete message",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import { metisAnswerPostUser2, metisResolvingAnswerPostUser1, metisUser1 } from
import { AccountService } from 'app/core/auth/account.service';
import { MockAccountService } from '../../../../../helpers/mocks/service/mock-account.service';
import { ProfilePictureComponent } from 'app/shared/profile-picture/profile-picture.component';
import { By } from '@angular/platform-browser';

describe('AnswerPostHeaderComponent', () => {
let component: AnswerPostHeaderComponent;
Expand Down Expand Up @@ -92,6 +93,15 @@ describe('AnswerPostHeaderComponent', () => {
expect(getElement(debugElement, '#today-flag')).toBeNull();
});

it('should display solution when answerPost resolves post', () => {
const isResolvesPostSetSpy = jest.spyOn(component, 'isResolvesPostSet');
component.posting = metisResolvingAnswerPostUser1;
fixture.detectChanges();
const solution = debugElement.query(By.css('.post-header-solution'));
expect(isResolvesPostSetSpy).toHaveReturnedWith(true);
expect(solution).not.toBeNull();
});
Comment on lines +96 to +103
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Enhance test coverage for the solution badge feature.

While the current test verifies the positive case, we should add more test cases:

     it('should display solution when answerPost resolves post', () => {
         const isResolvesPostSetSpy = jest.spyOn(component, 'isResolvesPostSet');
         component.posting = metisResolvingAnswerPostUser1;
         fixture.detectChanges();
         const solution = debugElement.query(By.css('.post-header-solution'));
         expect(isResolvesPostSetSpy).toHaveReturnedWith(true);
         expect(solution).not.toBeNull();
+        const badge = solution.query(By.css('.badge'));
+        expect(badge.nativeElement.getAttribute('aria-label')).toBeTruthy();
     });
+
+    it('should not display solution badge when post does not resolve', () => {
+        component.posting = { ...metisResolvingAnswerPostUser1, resolvesPost: false };
+        fixture.detectChanges();
+        const solution = debugElement.query(By.css('.post-header-solution'));
+        expect(solution).toBeNull();
+    });
+
+    it('should display correct translation in solution badge', () => {
+        component.posting = metisResolvingAnswerPostUser1;
+        fixture.detectChanges();
+        const badge = debugElement.query(By.css('.badge'));
+        expect(badge.attributes['jhiTranslate']).toBe('artemisApp.metis.post.resolvesPost');
+    });

These additional tests will:

  1. Verify the accessibility attributes
  2. Test the negative case
  3. Ensure correct translation key usage

Committable suggestion skipped: line range outside the PR's diff.


it('should initialize answer post not marked as resolved and not show the check to mark it as such', () => {
// user, that is not author of original post, should not see the check to mark an answer post as resolving
metisServiceUserIsAtLeastTutorMock.mockReturnValue(false);
Expand Down
Loading