[CST-12109] tests & translations

This commit is contained in:
Alisa Ismailati
2024-01-23 17:51:12 +01:00
parent 2f43bb71a0
commit ac6c890d78
7 changed files with 96 additions and 17 deletions

View File

@@ -17,13 +17,14 @@ describe('ItemAlertsComponent', () => {
let dsoWithdrawnReinstateModalService;
let correctionTypeDataService;
const itemMock = Object.assign(new Item(), {
uuid: 'item-uuid',
id: 'item-uuid',
});
beforeEach(waitForAsync(() => {
authorizationService = jasmine.createSpyObj('authorizationService', {
isAuthorized: of(true)
});
dsoWithdrawnReinstateModalService = jasmine.createSpyObj('dsoWithdrawnReinstateModalService', {
openCreateWithdrawnReinstateModal: {}
});
authorizationService = jasmine.createSpyObj('authorizationService', ['isAuthorized']);
dsoWithdrawnReinstateModalService = jasmine.createSpyObj('dsoWithdrawnReinstateModalService',['openCreateWithdrawnReinstateModal']);
correctionTypeDataService = jasmine.createSpyObj('correctionTypeDataService', {
findByItem: of({})
});
@@ -43,6 +44,7 @@ describe('ItemAlertsComponent', () => {
beforeEach(() => {
fixture = TestBed.createComponent(ItemAlertsComponent);
component = fixture.componentInstance;
component.item = itemMock;
fixture.detectChanges();
});
@@ -105,4 +107,47 @@ describe('ItemAlertsComponent', () => {
expect(privateWarning).toBeNull();
});
});
describe('show reinstate button', () => {
it('should return false if user is an admin', () => {
const isAdmin$ = of(true);
authorizationService.isAuthorized.and.returnValue(isAdmin$);
const result$ = component.showReinstateButton$();
result$.subscribe((result) => {
expect(result).toBe(false);
});
});
it('should return false if no correction types are found', () => {
const isAdmin$ = of(false);
authorizationService.isAuthorized.and.returnValue(isAdmin$);
correctionTypeDataService.findByItem.and.returnValue(of([]));
const result$ = component.showReinstateButton$();
result$.subscribe((result) => {
expect(result).toBe(false);
});
});
it('should return false if no correction type with topic "REQUEST_REINSTATE" is found', () => {
const isAdmin$ = of(false);
authorizationService.isAuthorized.and.returnValue(isAdmin$);
correctionTypeDataService.findByItem.and.returnValue(of([{ topic: 'OTHER_TOPIC' }]));
const result$ = component.showReinstateButton$();
result$.subscribe((result) => {
expect(result).toBe(false);
});
});
it('should return true if user is not an admin and correction type with topic "REQUEST_REINSTATE" is found', () => {
const isAdmin$ = of(false);
authorizationService.isAuthorized.and.returnValue(isAdmin$);
correctionTypeDataService.findByItem.and.returnValue(of([{ topic: 'REQUEST_REINSTATE' }]));
const result$ = component.showReinstateButton$();
result$.subscribe((result) => {
expect(result).toBe(true);
});
});
});
});

View File

@@ -34,7 +34,7 @@
<tbody>
<tr *ngFor="let sourceElement of (sources$ | async); let i = index">
<td>{{sourceElement.id}}</td>
<td>{{sourceElement.lastEvent}}</td>
<td>{{formatDate(sourceElement.lastEvent)}}</td>
<td>
<div class="btn-group edit-field">
<button

View File

@@ -8,7 +8,7 @@ import { PaginationComponentOptions } from '../../../shared/pagination/paginatio
import { NotificationsStateService } from '../../notifications-state.service';
import { AdminQualityAssuranceSourcePageParams } from '../../../admin/admin-notifications/admin-quality-assurance-source-page-component/admin-quality-assurance-source-page-resolver.service';
import { hasValue } from '../../../shared/empty.util';
import { format } from 'date-fns';
/**
* Component to display the Quality Assurance source list.
*/
@@ -65,6 +65,20 @@ export class QualityAssuranceSourceComponent implements OnInit {
this.totalElements$ = this.notificationsStateService.getQualityAssuranceSourceTotals();
}
/**
* Formats the given date string into the format 'yyyy-MM-dd HH:mm:ss'.
* If the date is falsy, an empty string is returned.
*
* @param date - The date string to be formatted.
* @returns The formatted date string.
*/
formatDate(date: string): string {
if (!date) {
return '';
}
return format(new Date(date), 'yyyy-MM-dd HH:mm:ss');
}
/**
* First Quality Assurance source loading after view initialization.
*/

View File

@@ -38,7 +38,7 @@
<tbody>
<tr *ngFor="let topicElement of (topics$ | async); let i = index">
<td>{{topicElement.name}}</td>
<td>{{topicElement.lastEvent}}</td>
<td>{{formatDate(topicElement.lastEvent)}}</td>
<td>
<div class="btn-group edit-field">
<button

View File

@@ -20,6 +20,7 @@ import { getFirstCompletedRemoteData, getRemoteDataPayload } from '../../../core
import { Item } from '../../../core/shared/item.model';
import { getItemPageRoute } from '../../../item-page/item-page-routing-paths';
import { getNotificatioQualityAssuranceRoute } from '../../../admin/admin-routing-paths';
import { format } from 'date-fns';
/**
* Component to display the Quality Assurance topic list.
@@ -201,6 +202,20 @@ export class QualityAssuranceTopicsComponent implements OnInit {
return getNotificatioQualityAssuranceRoute();
}
/**
* Formats the given date string into the format 'yyyy-MM-dd HH:mm:ss'.
* If the date is falsy, an empty string is returned.
*
* @param date - The date string to format.
* @returns The formatted date string.
*/
formatDate(date: string): string {
if (!date) {
return '';
}
return format(new Date(date), 'yyyy-MM-dd HH:mm:ss');
}
/**
* Unsubscribe from all subscriptions.
*/

View File

@@ -38,7 +38,7 @@ export class DsoWithdrawnReinstateModalService {
/**
* Open the create withdrawn modal for the provided dso
*/
openCreateWithdrawnReinstateModal(dso: Item, correctionType: string, state: boolean): void {
openCreateWithdrawnReinstateModal(dso: Item, correctionType: 'request-reinstate' | 'request-withdrawn', state: boolean): void {
const target = dso.id;
// Open modal
const activeModal = this.modalService.open(ItemWithdrawnReinstateModalComponent);
@@ -63,16 +63,17 @@ export class DsoWithdrawnReinstateModalService {
* Reloads the current page in order to update the withdrawn/reinstate button.
* and desplay a notification box.
*/
sendQARequest(target: string, correctionType: string, reason: string): void {
sendQARequest(target: string, correctionType: 'request-reinstate' | 'request-withdrawn', reason: string): void {
this.qaEventDataService.postData(target, correctionType, '', reason)
.pipe (
getFirstCompletedRemoteData()
)
.subscribe((res: RemoteData<QualityAssuranceEventObject>) => {
if (res.hasSucceeded) {
const withdrawnMessage = 'Withdrawn request sent.';
const reinstateMessage = 'Reinstate request sent.';
const message = (correctionType === 'request-withdrawn') ? withdrawnMessage : reinstateMessage;
)
.subscribe((res: RemoteData<QualityAssuranceEventObject>) => {
if (res.hasSucceeded) {
const message = (correctionType === 'request-withdrawn')
? 'correction-type.manage-relation.action.notification.withdrawn'
: 'correction-type.manage-relation.action.notification.reinstate';
this.notificationsService.success(this.translateService.get(message));
this.authorizationService.invalidateAuthorizationsRequestCache();
this.reloadPage(true);

View File

@@ -2648,6 +2648,10 @@
"item.qa.withdrawn.modal.submitted.header": "Sending withdrawn request...",
"correction-type.manage-relation.action.notification.reinstate": "Reinstate request sent.",
"correction-type.manage-relation.action.notification.withdrawn": "Withdraw request sent.",
"qa-event-notification.check.notification-withdrawn": "You have requested to withdraw this item.",
"qa-event-notification.check.notification-reinstate": "You have requested to reinstate this item.",