Skip to content

Commit

Permalink
Added proper alert messages
Browse files Browse the repository at this point in the history
  • Loading branch information
cremertim committed Oct 12, 2024
1 parent a1c3562 commit 0ab7a91
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 8 deletions.
18 changes: 13 additions & 5 deletions src/main/webapp/app/faq/faq-update.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export class FaqUpdateComponent implements OnInit {
existingCategories: FaqCategory[];
faqCategories: FaqCategory[];
courseId: number;
isAtleastInstructor: boolean = false;
isAtLeastInstructor: boolean = false;
domainActionsDescription = [new FormulaAction()];

// Icons
Expand All @@ -59,7 +59,7 @@ export class FaqUpdateComponent implements OnInit {
if (course) {
this.faq.course = course;
this.loadCourseFaqCategories(course.id);
this.isAtleastInstructor = this.accountService.isAtLeastInstructorInCourse(course);
this.isAtLeastInstructor = this.accountService.isAtLeastInstructorInCourse(course);
}
this.faqCategories = faq?.categories ? faq.categories : [];
});
Expand All @@ -81,7 +81,7 @@ export class FaqUpdateComponent implements OnInit {
*/
save() {
this.isSaving = true;
this.faq.faqState = this.isAtleastInstructor ? FaqState.ACCEPTED : FaqState.PROPOSED;
this.faq.faqState = this.isAtLeastInstructor ? FaqState.ACCEPTED : FaqState.PROPOSED;
if (this.faq.id !== undefined) {
this.subscribeToSaveResponse(this.faqService.update(this.courseId, this.faq));
} else {
Expand Down Expand Up @@ -111,13 +111,21 @@ export class FaqUpdateComponent implements OnInit {
if (faqBody) {
this.faq = faqBody;
}
this.alertService.success(this.translateService.instant('artemisApp.faq.created', { id: faq.id }));
if (this.isAtLeastInstructor) {
this.alertService.success(this.translateService.instant('artemisApp.faq.created', { id: faq.id }));
} else {
this.alertService.success(this.translateService.instant('artemisApp.faq.proposed', { id: faq.id }));
}
this.router.navigate(['course-management', this.courseId, 'faqs']);
},
});
} else {
this.isSaving = false;
this.alertService.success(this.translateService.instant('artemisApp.faq.updated', { id: faq.id }));
if (this.isAtLeastInstructor) {
this.alertService.success(this.translateService.instant('artemisApp.faq.updated', { id: faq.id }));
} else {
this.alertService.success(this.translateService.instant('artemisApp.faq.proposedChange', { id: faq.id }));
}
this.router.navigate(['course-management', this.courseId, 'faqs']);
}
}
Expand Down
6 changes: 4 additions & 2 deletions src/main/webapp/i18n/de/faq.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,17 @@
"title": "FAQ",
"createLabel": "FAQ erstellen",
"proposeLabel": "FAQ vorschlagen",
"accept": "FAQ aktzeptieren",
"accept": "FAQ akzeptieren",
"reject": "FAQ ablehnen",
"filterLabel": "Filter",
"createOrEditLabel": "FAQ erstellen oder bearbeiten"
},
"created": "Das FAQ mit der ID {{ id }} wurde erfolgreich erstellt",
"updated": "Das FAQ mit der ID {{ id }} wurde erfolgreich aktualisiert",
"proposed": "Das FAQ mit der ID {{ id }} wurde erfolgreich vorgeschlagen",
"proposedChange": "Die Änderungen am FAQ mit der ID {{ id }} wurde erfolgreich vorgeschlagen",
"deleted": "Das FAQ mit der ID {{ param }} wurde erfolgreich gelöscht",
"accepted": "Das FAQ mit der ID {{ id }} wurde erfolgreich aktzeptiert",
"accepted": "Das FAQ mit der ID {{ id }} wurde erfolgreich akzeptieren",
"rejected": "Das FAQ mit der ID {{ id }} wurde erfolgreich abgelehnt",
"delete": {
"question": "Soll die FAQ <strong>{{ title }}</strong> wirklich dauerhaft gelöscht werden? Diese Aktion kann NICHT rückgängig gemacht werden!",
Expand Down
2 changes: 2 additions & 0 deletions src/main/webapp/i18n/en/faq.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
},
"created": "The FAQ with ID {{ id }} was successfully created",
"updated": "The FAQ with ID {{ id }} was successfully updated",
"proposed": "The FAQ with ID {{ id }} was successfully proposed",
"proposedChange": "The changes to the FAQ with the ID {{ id }} have been successfully proposed",
"deleted": "The FAQ with ID {{ param }} was successfully deleted",
"accepted": "The FAQ with ID {{ id }} was successfully accepted",
"rejected": "The FAQ with ID {{ id }} was successfully rejected",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,32 @@ describe('FaqUpdateComponent', () => {

it('should create faq', fakeAsync(() => {
faqUpdateComponent.faq = { questionTitle: 'test1' } as Faq;
faqUpdateComponent.isAtLeastInstructor = true;
const createSpy = jest.spyOn(faqService, 'create').mockReturnValue(
of(
new HttpResponse({
body: {
id: 3,
questionTitle: 'test1',
course: {
id: 1,
},
} as Faq,
}),
),
);

faqUpdateComponentFixture.detectChanges();
faqUpdateComponent.save();
tick();

expect(createSpy).toHaveBeenCalledExactlyOnceWith(courseId, { questionTitle: 'test1', faqState: 'ACCEPTED' });
expect(faqUpdateComponent.isSaving).toBeFalse();
}));

it('should propose faq', fakeAsync(() => {
faqUpdateComponent.faq = { questionTitle: 'test1' } as Faq;
faqUpdateComponent.isAtLeastInstructor = false;
const createSpy = jest.spyOn(faqService, 'create').mockReturnValue(
of(
new HttpResponse({
Expand All @@ -117,7 +143,7 @@ describe('FaqUpdateComponent', () => {

it('should edit a faq', fakeAsync(() => {
activatedRoute.parent!.data = of({ course: { id: 1 }, faq: { id: 6 } });

faqUpdateComponent.isAtLeastInstructor = true;
faqUpdateComponentFixture.detectChanges();
faqUpdateComponent.faq = { id: 6, questionTitle: 'test1Updated' } as Faq;

Expand All @@ -139,7 +165,33 @@ describe('FaqUpdateComponent', () => {
faqUpdateComponent.save();
tick();
faqUpdateComponentFixture.detectChanges();
expect(updateSpy).toHaveBeenCalledExactlyOnceWith(courseId, { id: 6, questionTitle: 'test1Updated', faqState: 'ACCEPTED' });
}));

it('should propose to edit a faq', fakeAsync(() => {
activatedRoute.parent!.data = of({ course: { id: 1 }, faq: { id: 6 } });
faqUpdateComponent.isAtLeastInstructor = false;
faqUpdateComponentFixture.detectChanges();
faqUpdateComponent.faq = { id: 6, questionTitle: 'test1Updated' } as Faq;

const updateSpy = jest.spyOn(faqService, 'update').mockReturnValue(
of<HttpResponse<Faq>>(
new HttpResponse({
body: {
id: 6,
questionTitle: 'test1Updated',
questionAnswer: 'answer',
course: {
id: 1,
},
} as Faq,
}),
),
);

faqUpdateComponent.save();
tick();
faqUpdateComponentFixture.detectChanges();
expect(updateSpy).toHaveBeenCalledExactlyOnceWith(courseId, { id: 6, questionTitle: 'test1Updated', faqState: 'PROPOSED' });
}));

Expand Down

0 comments on commit 0ab7a91

Please sign in to comment.