ACS-7395: content node share as standalone

This commit is contained in:
Denys Vuika
2024-07-25 14:33:27 -04:00
parent 4c3e8eec38
commit 6ca737a752
7 changed files with 48 additions and 25 deletions

View File

@@ -83,7 +83,6 @@
data-automation-id="adf-share-link" data-automation-id="adf-share-link"
class="adf-share-link__input" class="adf-share-link__input"
matInput matInput
cdkFocusInitial
placeholder="{{ 'SHARE.PUBLIC-LINK' | translate }}" placeholder="{{ 'SHARE.PUBLIC-LINK' | translate }}"
[attr.aria-label]="'SHARE.PUBLIC-LINK' | translate" [attr.aria-label]="'SHARE.PUBLIC-LINK' | translate"
formControlName="sharedUrl" formControlName="sharedUrl"

View File

@@ -16,7 +16,7 @@
*/ */
import { TestBed, ComponentFixture } from '@angular/core/testing'; import { TestBed, ComponentFixture } from '@angular/core/testing';
import { MatDialogRef, MAT_DIALOG_DATA, MatDialog } from '@angular/material/dialog'; import { MatDialogRef, MAT_DIALOG_DATA, MatDialog, MatDialogModule } from '@angular/material/dialog';
import { of } from 'rxjs'; import { of } from 'rxjs';
import { NotificationService } from '@alfresco/adf-core'; import { NotificationService } from '@alfresco/adf-core';
import { NodesApiService, RenditionService } from '../common'; import { NodesApiService, RenditionService } from '../common';
@@ -33,7 +33,6 @@ import { MatSlideToggleHarness } from '@angular/material/slide-toggle/testing';
describe('ShareDialogComponent', () => { describe('ShareDialogComponent', () => {
let loader: HarnessLoader; let loader: HarnessLoader;
let node: NodeEntry; let node: NodeEntry;
let matDialog: MatDialog;
const notificationServiceMock = { const notificationServiceMock = {
openSnackMessage: jasmine.createSpy('openSnackMessage') openSnackMessage: jasmine.createSpy('openSnackMessage')
}; };
@@ -56,7 +55,7 @@ describe('ShareDialogComponent', () => {
beforeEach(() => { beforeEach(() => {
TestBed.configureTestingModule({ TestBed.configureTestingModule({
imports: [ContentTestingModule], imports: [ContentTestingModule, MatDialogModule, ShareDialogComponent],
providers: [ providers: [
{ provide: NotificationService, useValue: notificationServiceMock }, { provide: NotificationService, useValue: notificationServiceMock },
{ {
@@ -71,7 +70,6 @@ describe('ShareDialogComponent', () => {
fixture = TestBed.createComponent(ShareDialogComponent); fixture = TestBed.createComponent(ShareDialogComponent);
component = fixture.componentInstance; component = fixture.componentInstance;
matDialog = TestBed.inject(MatDialog);
sharedLinksApiService = TestBed.inject(SharedLinksApiService); sharedLinksApiService = TestBed.inject(SharedLinksApiService);
renditionService = TestBed.inject(RenditionService); renditionService = TestBed.inject(RenditionService);
nodesApiService = TestBed.inject(NodesApiService); nodesApiService = TestBed.inject(NodesApiService);
@@ -179,7 +177,8 @@ describe('ShareDialogComponent', () => {
}); });
it('should open a confirmation dialog when unshare button is triggered', async () => { it('should open a confirmation dialog when unshare button is triggered', async () => {
spyOn(matDialog, 'open').and.returnValue({ beforeClosed: () => of(false) } as any); const dialog = fixture.debugElement.injector.get(MatDialog);
const openSpy = spyOn(dialog, 'open').and.returnValue({ beforeClosed: () => of(false) } as any);
spyOn(sharedLinksApiService, 'deleteSharedLink').and.callThrough(); spyOn(sharedLinksApiService, 'deleteSharedLink').and.callThrough();
node.entry.properties['qshare:sharedId'] = 'sharedId'; node.entry.properties['qshare:sharedId'] = 'sharedId';
@@ -194,11 +193,12 @@ describe('ShareDialogComponent', () => {
const toggle = await loader.getHarness(MatSlideToggleHarness.with({ selector: shareToggleId })); const toggle = await loader.getHarness(MatSlideToggleHarness.with({ selector: shareToggleId }));
await toggle.toggle(); await toggle.toggle();
expect(matDialog.open).toHaveBeenCalled(); expect(openSpy).toHaveBeenCalled();
}); });
it('should unshare file when confirmation dialog returns true', async () => { it('should unshare file when confirmation dialog returns true', async () => {
spyOn(matDialog, 'open').and.returnValue({ beforeClosed: () => of(true) } as any); const dialog = fixture.debugElement.injector.get(MatDialog);
spyOn(dialog, 'open').and.returnValue({ beforeClosed: () => of(true) } as any);
spyOn(sharedLinksApiService, 'deleteSharedLink').and.returnValue(of({})); spyOn(sharedLinksApiService, 'deleteSharedLink').and.returnValue(of({}));
node.entry.properties['qshare:sharedId'] = 'sharedId'; node.entry.properties['qshare:sharedId'] = 'sharedId';
@@ -208,6 +208,7 @@ describe('ShareDialogComponent', () => {
}; };
fixture.detectChanges(); fixture.detectChanges();
await fixture.whenStable();
const toggle = await loader.getHarness(MatSlideToggleHarness.with({ selector: shareToggleId })); const toggle = await loader.getHarness(MatSlideToggleHarness.with({ selector: shareToggleId }));
await toggle.toggle(); await toggle.toggle();
@@ -216,7 +217,8 @@ describe('ShareDialogComponent', () => {
}); });
it('should not unshare file when confirmation dialog returns false', async () => { it('should not unshare file when confirmation dialog returns false', async () => {
spyOn(matDialog, 'open').and.returnValue({ beforeClosed: () => of(false) } as any); const dialog = fixture.debugElement.injector.get(MatDialog);
spyOn(dialog, 'open').and.returnValue({ beforeClosed: () => of(false) } as any);
spyOn(sharedLinksApiService, 'deleteSharedLink').and.callThrough(); spyOn(sharedLinksApiService, 'deleteSharedLink').and.callThrough();
node.entry.properties['qshare:sharedId'] = 'sharedId'; node.entry.properties['qshare:sharedId'] = 'sharedId';

View File

@@ -16,17 +16,24 @@
*/ */
import { Component, Inject, OnInit, ViewEncapsulation, ViewChild, OnDestroy } from '@angular/core'; import { Component, Inject, OnInit, ViewEncapsulation, ViewChild, OnDestroy } from '@angular/core';
import { MAT_DIALOG_DATA, MatDialog, MatDialogRef } from '@angular/material/dialog'; import { MAT_DIALOG_DATA, MatDialog, MatDialogModule, MatDialogRef } from '@angular/material/dialog';
import { MatSlideToggleChange } from '@angular/material/slide-toggle'; import { MatSlideToggleChange, MatSlideToggleModule } from '@angular/material/slide-toggle';
import { FormControl, FormGroup, Validators } from '@angular/forms'; import { FormControl, FormGroup, ReactiveFormsModule, Validators } from '@angular/forms';
import { Subject } from 'rxjs'; import { Subject } from 'rxjs';
import { ContentService } from '../common/services/content.service'; import { ContentService } from '../common/services/content.service';
import { SharedLinksApiService } from './services/shared-links-api.service'; import { SharedLinksApiService } from './services/shared-links-api.service';
import { SharedLinkBodyCreate } from '@alfresco/js-api'; import { SharedLinkBodyCreate } from '@alfresco/js-api';
import { ConfirmDialogComponent } from '@alfresco/adf-core'; import { ClipboardModule, ConfirmDialogComponent } from '@alfresco/adf-core';
import { ContentNodeShareSettings } from './content-node-share.settings'; import { ContentNodeShareSettings } from './content-node-share.settings';
import { RenditionService } from '../common/services/rendition.service'; import { RenditionService } from '../common/services/rendition.service';
import { format, add, endOfDay, isBefore } from 'date-fns'; import { format, add, endOfDay, isBefore } from 'date-fns';
import { CommonModule } from '@angular/common';
import { TranslateModule } from '@ngx-translate/core';
import { MatIconModule } from '@angular/material/icon';
import { MatFormFieldModule } from '@angular/material/form-field';
import { MatDatepickerModule } from '@angular/material/datepicker';
import { MatInputModule } from '@angular/material/input';
import { MatButtonModule } from '@angular/material/button';
interface SharedDialogFormProps { interface SharedDialogFormProps {
sharedUrl: FormControl<string>; sharedUrl: FormControl<string>;
@@ -35,6 +42,20 @@ interface SharedDialogFormProps {
@Component({ @Component({
selector: 'adf-share-dialog', selector: 'adf-share-dialog',
standalone: true,
imports: [
CommonModule,
TranslateModule,
MatIconModule,
MatDialogModule,
ReactiveFormsModule,
MatSlideToggleModule,
MatFormFieldModule,
MatDatepickerModule,
MatInputModule,
ClipboardModule,
MatButtonModule
],
templateUrl: './content-node-share.dialog.html', templateUrl: './content-node-share.dialog.html',
styleUrls: ['./content-node-share.dialog.scss'], styleUrls: ['./content-node-share.dialog.scss'],
host: { class: 'adf-share-dialog' }, host: { class: 'adf-share-dialog' },

View File

@@ -21,10 +21,12 @@ import { Component } from '@angular/core';
import { DOCUMENT } from '@angular/common'; import { DOCUMENT } from '@angular/common';
import { ContentTestingModule } from '../testing/content.testing.module'; import { ContentTestingModule } from '../testing/content.testing.module';
import { CoreModule } from '@alfresco/adf-core'; import { CoreModule } from '@alfresco/adf-core';
import { ContentNodeShareModule } from './content-node-share.module'; import { NodeSharedDirective } from '@alfresco/adf-content-services';
@Component({ @Component({
selector: 'adf-node-share-test-component', selector: 'adf-node-share-test-component',
standalone: true,
imports: [NodeSharedDirective],
template: ` template: `
<button <button
[disabled]="!shareRef.isFile" [disabled]="!shareRef.isFile"
@@ -51,8 +53,7 @@ describe('NodeSharedDirective', () => {
beforeEach(() => { beforeEach(() => {
TestBed.configureTestingModule({ TestBed.configureTestingModule({
imports: [CoreModule.forRoot(), ContentTestingModule, ContentNodeShareModule], imports: [CoreModule.forRoot(), ContentTestingModule, NodeShareTestComponent]
declarations: [NodeShareTestComponent]
}); });
fixture = TestBed.createComponent(NodeShareTestComponent); fixture = TestBed.createComponent(NodeShareTestComponent);
document = TestBed.inject(DOCUMENT); document = TestBed.inject(DOCUMENT);

View File

@@ -26,6 +26,7 @@ import { takeUntil } from 'rxjs/operators';
@Directive({ @Directive({
selector: '[adf-share]', selector: '[adf-share]',
standalone: true,
exportAs: 'adfShare' exportAs: 'adfShare'
}) })
export class NodeSharedDirective implements OnChanges, OnDestroy { export class NodeSharedDirective implements OnChanges, OnDestroy {

View File

@@ -16,15 +16,14 @@
*/ */
import { NgModule } from '@angular/core'; import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { CoreModule } from '@alfresco/adf-core';
import { MaterialModule } from '../material.module';
import { ShareDialogComponent } from './content-node-share.dialog'; import { ShareDialogComponent } from './content-node-share.dialog';
import { NodeSharedDirective } from './content-node-share.directive'; import { NodeSharedDirective } from './content-node-share.directive';
export const CONTENT_NODE_SHARE_DIRECTIVES = [ShareDialogComponent, NodeSharedDirective] as const;
/** @deprecated use `...CONTENT_NODE_SHARE_DIRECTIVES` or import each directive individually */
@NgModule({ @NgModule({
imports: [CoreModule, CommonModule, MaterialModule], imports: [...CONTENT_NODE_SHARE_DIRECTIVES],
declarations: [ShareDialogComponent, NodeSharedDirective], exports: [...CONTENT_NODE_SHARE_DIRECTIVES]
exports: [ShareDialogComponent, NodeSharedDirective]
}) })
export class ContentNodeShareModule {} export class ContentNodeShareModule {}

View File

@@ -26,7 +26,7 @@ import { SearchModule } from './search/search.module';
import { BREADCRUMB_DIRECTIVES } from './breadcrumb/breadcrumb.module'; import { BREADCRUMB_DIRECTIVES } from './breadcrumb/breadcrumb.module';
import { CONTENT_VERSION_DIRECTIVES } from './version-manager/version-manager.module'; import { CONTENT_VERSION_DIRECTIVES } from './version-manager/version-manager.module';
import { ContentNodeSelectorModule } from './content-node-selector/content-node-selector.module'; import { ContentNodeSelectorModule } from './content-node-selector/content-node-selector.module';
import { ContentNodeShareModule } from './content-node-share/content-node-share.module'; import { CONTENT_NODE_SHARE_DIRECTIVES } from './content-node-share/content-node-share.module';
import { CONTENT_DIRECTIVES } from './directives/content-directive.module'; import { CONTENT_DIRECTIVES } from './directives/content-directive.module';
import { CONTENT_DIALOG_DIRECTIVES } from './dialogs/dialog.module'; import { CONTENT_DIALOG_DIRECTIVES } from './dialogs/dialog.module';
import { CONTENT_METADATA_DIRECTIVES } from './content-metadata/content-metadata.module'; import { CONTENT_METADATA_DIRECTIVES } from './content-metadata/content-metadata.module';
@@ -64,7 +64,7 @@ import { TreeViewComponent } from './tree-view';
DropdownSitesComponent, DropdownSitesComponent,
...BREADCRUMB_DIRECTIVES, ...BREADCRUMB_DIRECTIVES,
ContentNodeSelectorModule, ContentNodeSelectorModule,
ContentNodeShareModule, ...CONTENT_NODE_SHARE_DIRECTIVES,
...CONTENT_METADATA_DIRECTIVES, ...CONTENT_METADATA_DIRECTIVES,
...CONTENT_DIRECTIVES, ...CONTENT_DIRECTIVES,
...CONTENT_PERMISSION_MANAGER_DIRECTIVES, ...CONTENT_PERMISSION_MANAGER_DIRECTIVES,
@@ -90,7 +90,7 @@ import { TreeViewComponent } from './tree-view';
DropdownSitesComponent, DropdownSitesComponent,
...BREADCRUMB_DIRECTIVES, ...BREADCRUMB_DIRECTIVES,
ContentNodeSelectorModule, ContentNodeSelectorModule,
ContentNodeShareModule, ...CONTENT_NODE_SHARE_DIRECTIVES,
...CONTENT_METADATA_DIRECTIVES, ...CONTENT_METADATA_DIRECTIVES,
...CONTENT_DIALOG_DIRECTIVES, ...CONTENT_DIALOG_DIRECTIVES,
...CONTENT_DIRECTIVES, ...CONTENT_DIRECTIVES,