Skip to content

Commit

Permalink
replace more cases
Browse files Browse the repository at this point in the history
  • Loading branch information
DenysVuika committed Aug 2, 2024
1 parent a19d966 commit db7e0ac
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 61 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ describe('ContentManagementService', () => {
let newVersionUploaderService: NewVersionUploaderService;
let showErrorSpy: jasmine.Spy;
let showInfoSpy: jasmine.Spy;
let showWarningSpy: jasmine.Spy;

beforeEach(() => {
TestBed.configureTestingModule({
Expand All @@ -94,6 +95,7 @@ describe('ContentManagementService', () => {
notificationService = TestBed.inject(NotificationService);
showErrorSpy = spyOn(notificationService, 'showError');
showInfoSpy = spyOn(notificationService, 'showInfo');
showWarningSpy = spyOn(notificationService, 'showWarning');
nodeActions = TestBed.inject(NodeActionsService);
translationService = TestBed.inject(TranslationService);
nodesApiService = TestBed.inject(NodesApiService);
Expand Down Expand Up @@ -927,14 +929,7 @@ describe('ContentManagementService', () => {
});

describe('notification', () => {
it('raises warning on multiple fail and one success', (done) => {
actions$
.pipe(
ofType<SnackbarWarningAction>(SnackbarActionTypes.Warning),
map((action) => expect(action).toBeDefined())
)
.subscribe(() => done());

it('raises warning on multiple fail and one success', () => {
spyOn(contentApi, 'purgeDeletedNode').and.callFake((id) => {
if (id === '1') {
return of({});
Expand All @@ -958,16 +953,10 @@ describe('ContentManagementService', () => {
];

store.dispatch(new PurgeDeletedNodesAction(selection));
expect(showWarningSpy).toHaveBeenCalled();
});

it('raises warning on multiple success and multiple fail', (done) => {
actions$
.pipe(
ofType<SnackbarWarningAction>(SnackbarActionTypes.Warning),
map((action) => expect(action).toBeDefined())
)
.subscribe(() => done());

it('raises warning on multiple success and multiple fail', () => {
spyOn(contentApi, 'purgeDeletedNode').and.callFake((id) => {
if (id === '1') {
return of({});
Expand Down Expand Up @@ -996,46 +985,28 @@ describe('ContentManagementService', () => {
];

store.dispatch(new PurgeDeletedNodesAction(selection));
expect(showWarningSpy).toHaveBeenCalled();
});

it('raises info on one selected node success', (done) => {
actions$
.pipe(
ofType<SnackbarInfoAction>(SnackbarActionTypes.Info),
map((action) => expect(action).toBeDefined())
)
.subscribe(() => done());

it('raises info on one selected node success', () => {
spyOn(contentApi, 'purgeDeletedNode').and.returnValue(of({}));

const selection: any[] = [{ entry: { id: '1', name: 'name1' } }];

store.dispatch(new PurgeDeletedNodesAction(selection));
expect(showInfoSpy).toHaveBeenCalled();
});

it('raises error on one selected node fail', (done) => {
actions$
.pipe(
ofType<SnackbarErrorAction>(SnackbarActionTypes.Error),
map((action) => expect(action).toBeDefined())
)
.subscribe(() => done());

it('raises error on one selected node fail', () => {
spyOn(contentApi, 'purgeDeletedNode').and.returnValue(throwError({}));

const selection: any[] = [{ entry: { id: '1', name: 'name1' } }];

store.dispatch(new PurgeDeletedNodesAction(selection));
expect(showErrorSpy).toHaveBeenCalled();
});

it('raises info on all nodes success', (done) => {
actions$
.pipe(
ofType<SnackbarInfoAction>(SnackbarActionTypes.Info),
map((action) => expect(action).toBeDefined())
)
.subscribe(() => done());

it('raises info on all nodes success', () => {
spyOn(contentApi, 'purgeDeletedNode').and.callFake((id) => {
if (id === '1') {
return of({});
Expand All @@ -1051,16 +1022,10 @@ describe('ContentManagementService', () => {
const selection: any[] = [{ entry: { id: '1', name: 'name1' } }, { entry: { id: '2', name: 'name2' } }];

store.dispatch(new PurgeDeletedNodesAction(selection));
expect(showInfoSpy).toHaveBeenCalled();
});

it('raises error on all nodes fail', (done) => {
actions$
.pipe(
ofType<SnackbarErrorAction>(SnackbarActionTypes.Error),
map((action) => expect(action).toBeDefined())
)
.subscribe(() => done());

it('raises error on all nodes fail', () => {
spyOn(contentApi, 'purgeDeletedNode').and.callFake((id) => {
if (id === '1') {
return throwError({});
Expand All @@ -1076,6 +1041,7 @@ describe('ContentManagementService', () => {
const selection: any[] = [{ entry: { id: '1', name: 'name1' } }, { entry: { id: '2', name: 'name2' } }];

store.dispatch(new PurgeDeletedNodesAction(selection));
expect(showErrorSpy).toHaveBeenCalled();
});
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -763,10 +763,8 @@ export class ContentManagementService {
if (status.success.length) {
this.store.dispatch(new ReloadDocumentListAction());
}
const message = this.getPurgeMessage(status);
if (message) {
this.store.dispatch(message);
}

this.sendPurgeMessage(status);
});
}

Expand Down Expand Up @@ -828,38 +826,36 @@ export class ContentManagementService {
}, status);
}

private getPurgeMessage(status: DeleteStatus): SnackbarAction {
private sendPurgeMessage(status: DeleteStatus): void {
if (status.oneSucceeded && status.someFailed && !status.oneFailed) {
return new SnackbarWarningAction('APP.MESSAGES.INFO.TRASH.NODES_PURGE.PARTIAL_SINGULAR', {
this.notificationService.showWarning('APP.MESSAGES.INFO.TRASH.NODES_PURGE.PARTIAL_SINGULAR', null, {
name: status.success[0].name,
failed: status.fail.length
});
}

if (status.someSucceeded && !status.oneSucceeded && status.someFailed) {
return new SnackbarWarningAction('APP.MESSAGES.INFO.TRASH.NODES_PURGE.PARTIAL_PLURAL', {
this.notificationService.showWarning('APP.MESSAGES.INFO.TRASH.NODES_PURGE.PARTIAL_PLURAL', null, {
number: status.success.length,
failed: status.fail.length
});
}

if (status.oneSucceeded) {
return new SnackbarInfoAction('APP.MESSAGES.INFO.TRASH.NODES_PURGE.SINGULAR', { name: status.success[0].name });
this.notificationService.showInfo('APP.MESSAGES.INFO.TRASH.NODES_PURGE.SINGULAR', null, { name: status.success[0].name });
}

if (status.oneFailed) {
return new SnackbarErrorAction('APP.MESSAGES.ERRORS.TRASH.NODES_PURGE.SINGULAR', { name: status.fail[0].name });
this.notificationService.showError('APP.MESSAGES.ERRORS.TRASH.NODES_PURGE.SINGULAR', null, { name: status.fail[0].name });
}

if (status.allSucceeded) {
return new SnackbarInfoAction('APP.MESSAGES.INFO.TRASH.NODES_PURGE.PLURAL', { number: status.success.length });
this.notificationService.showInfo('APP.MESSAGES.INFO.TRASH.NODES_PURGE.PLURAL', null, { number: status.success.length });
}

if (status.allFailed) {
return new SnackbarErrorAction('APP.MESSAGES.ERRORS.TRASH.NODES_PURGE.PLURAL', { number: status.fail.length });
this.notificationService.showError('APP.MESSAGES.ERRORS.TRASH.NODES_PURGE.PLURAL', null, { number: status.fail.length });
}

return null;
}

private showRestoreNotification(status: DeleteStatus): void {
Expand Down

0 comments on commit db7e0ac

Please sign in to comment.