Skip to content

Commit

Permalink
Merged in DSC-1403 (pull request DSpace#1066)
Browse files Browse the repository at this point in the history
[CST-12522] removed isAuthenticated from context-menu.component.html

Approved-by: Giuseppe Digilio
  • Loading branch information
abollini authored and atarix83 committed Nov 30, 2023
2 parents 53906d1 + 0eb4104 commit f5740f8
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 41 deletions.
2 changes: 1 addition & 1 deletion src/app/shared/context-menu/context-menu.component.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<div class="d-flex space-children-mr justify-content-end" *ngIf="((isAuthenticated | async) || isItem()) && contextMenuObject">
<div class="d-flex space-children-mr justify-content-end" *ngIf="contextMenuObject">
<ng-container *ngFor="let entry of (getStandAloneMenuEntries() | async)">
<ng-container *ngComponentOutlet="entry; injector: objectInjector;"></ng-container>
</ng-container>
Expand Down
36 changes: 10 additions & 26 deletions src/app/shared/context-menu/context-menu.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { BrowserDynamicTestingModule } from '@angular/platform-browser-dynamic/t
import { By } from '@angular/platform-browser';

import { NgbDropdownModule } from '@ng-bootstrap/ng-bootstrap';
import { cold } from 'jasmine-marbles';
import { TranslateLoader, TranslateModule } from '@ngx-translate/core';
import { Store } from '@ngrx/store';
import { of } from 'rxjs';
Expand Down Expand Up @@ -155,13 +154,13 @@ describe('ContextMenuComponent', () => {
done();
});

it('should display d-none', (done) => {
it('should use d-none', (done) => {
const menu = fixture.debugElement.query(By.css('div.d-none'));
expect(menu).not.toBeNull();
done();
});

it('should not display d-inline-block', (done) => {
it('should not use d-inline-block', (done) => {
const menu = fixture.debugElement.query(By.css('div.d-inline-block'));
expect(menu).toBeNull();
done();
Expand All @@ -173,11 +172,6 @@ describe('ContextMenuComponent', () => {
done();
});

it('should check the authorization of the current user', (done) => {
expect(component.isAuthenticated).toBeObservable(cold('a', { a: true }));
done();
});

it('should not have menu entries when are disabled on rest side', (done) => {
component.contextMenuObjectType = DSpaceObjectType.COMMUNITY;
configurationDataService.findByPropertyName.and.returnValues(
Expand Down Expand Up @@ -218,34 +212,29 @@ describe('ContextMenuComponent', () => {
done();
});

it('should not display context menu', (done) => {
it('should display context menu', (done) => {
const menu = fixture.debugElement.query(By.css('button#context-menu'));
expect(menu).not.toBeNull();
done();
});

it('should display d-none', (done) => {
it('should use d-none', (done) => {
const menu = fixture.debugElement.query(By.css('div.d-none'));
expect(menu).not.toBeNull();
done();
});

it('should not display d-inline-block', (done) => {
it('should not use d-inline-block', (done) => {
const menu = fixture.debugElement.query(By.css('div.d-inline-block'));
expect(menu).toBeNull();
done();
});

it('should not display stand alone buttons', (done) => {
it('should display stand alone buttons', (done) => {
const menu = fixture.debugElement.query(By.css('button.btn-primary'));
expect(menu).not.toBeNull();
done();
});

it('should check the authorization of the current user', (done) => {
expect(component.isAuthenticated).toBeObservable(cold('a', { a: false }));
done();
});
});

describe('and the object type is not ITEM', () => {
Expand All @@ -259,9 +248,9 @@ describe('ContextMenuComponent', () => {
done();
});

it('should not display context menu', (done) => {
it('should display context menu', (done) => {
const menu = fixture.debugElement.query(By.css('button#context-menu'));
expect(menu).toBeNull();
expect(menu).not.toBeNull();
done();
});

Expand All @@ -271,14 +260,9 @@ describe('ContextMenuComponent', () => {
done();
});

it('should not display d-none', (done) => {
it('should display d-none', (done) => {
const menu = fixture.debugElement.query(By.css('div.d-none'));
expect(menu).toBeNull();
done();
});

it('should check the authorization of the current user', (done) => {
expect(component.isAuthenticated).toBeObservable(cold('a', { a: false }));
expect(menu).not.toBeNull();
done();
});
});
Expand Down
16 changes: 2 additions & 14 deletions src/app/shared/context-menu/context-menu.component.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
import { ChangeDetectorRef, Component, Inject, Injector, Input, OnInit } from '@angular/core';
import { DOCUMENT } from '@angular/common';

import { select, Store } from '@ngrx/store';
import { from, Observable } from 'rxjs';
import { concatMap, filter, map, reduce, take } from 'rxjs/operators';

import { CoreState } from '../../core/core-state.model';
import { isAuthenticated } from '../../core/auth/selectors';
import { DSpaceObject } from '../../core/shared/dspace-object.model';
import { DSpaceObjectType } from '../../core/shared/dspace-object-type.model';
import { ContextMenuEntryRenderOptions, getContextMenuEntriesForDSOType } from './context-menu.decorator';
Expand Down Expand Up @@ -39,12 +36,6 @@ export class ContextMenuComponent implements OnInit {
*/
@Input() contextMenuObjectType: DSpaceObjectType;

/**
* Whether user is authenticated.
* @type {Observable<string>}
*/
public isAuthenticated: Observable<boolean>;

/**
* Injector to inject a menu entry component with the @Input parameters
* @type {Injector}
Expand All @@ -61,16 +52,15 @@ export class ContextMenuComponent implements OnInit {
* Initialize instance variables
*
* @param {Document} _document
* @param {ChangeDetectorRef} cdr
* @param {ConfigurationDataService} configurationService
* @param {Injector} injector
* @param {Store<CoreState>} store
*/
constructor(
@Inject(DOCUMENT) private _document: Document,
private cdr: ChangeDetectorRef,
private configurationService: ConfigurationDataService,
private injector: Injector,
private store: Store<CoreState>
private injector: Injector
) {
}

Expand All @@ -82,8 +72,6 @@ export class ContextMenuComponent implements OnInit {
],
parent: this.injector
});
// set isAuthenticated
this.isAuthenticated = this.store.pipe(select(isAuthenticated));
}

/**
Expand Down

0 comments on commit f5740f8

Please sign in to comment.