Skip to content

Commit

Permalink
ACS-7395: content node share as standalone
Browse files Browse the repository at this point in the history
  • Loading branch information
DenysVuika committed Jul 25, 2024
1 parent 4c3e8ee commit 6ca737a
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@
data-automation-id="adf-share-link"
class="adf-share-link__input"
matInput
cdkFocusInitial
placeholder="{{ 'SHARE.PUBLIC-LINK' | translate }}"
[attr.aria-label]="'SHARE.PUBLIC-LINK' | translate"
formControlName="sharedUrl"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
*/

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 { NotificationService } from '@alfresco/adf-core';
import { NodesApiService, RenditionService } from '../common';
Expand All @@ -33,7 +33,6 @@ import { MatSlideToggleHarness } from '@angular/material/slide-toggle/testing';
describe('ShareDialogComponent', () => {
let loader: HarnessLoader;
let node: NodeEntry;
let matDialog: MatDialog;
const notificationServiceMock = {
openSnackMessage: jasmine.createSpy('openSnackMessage')
};
Expand All @@ -56,7 +55,7 @@ describe('ShareDialogComponent', () => {

beforeEach(() => {
TestBed.configureTestingModule({
imports: [ContentTestingModule],
imports: [ContentTestingModule, MatDialogModule, ShareDialogComponent],
providers: [
{ provide: NotificationService, useValue: notificationServiceMock },
{
Expand All @@ -71,7 +70,6 @@ describe('ShareDialogComponent', () => {
fixture = TestBed.createComponent(ShareDialogComponent);
component = fixture.componentInstance;

matDialog = TestBed.inject(MatDialog);
sharedLinksApiService = TestBed.inject(SharedLinksApiService);
renditionService = TestBed.inject(RenditionService);
nodesApiService = TestBed.inject(NodesApiService);
Expand Down Expand Up @@ -179,7 +177,8 @@ describe('ShareDialogComponent', () => {
});

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();

node.entry.properties['qshare:sharedId'] = 'sharedId';
Expand All @@ -194,11 +193,12 @@ describe('ShareDialogComponent', () => {
const toggle = await loader.getHarness(MatSlideToggleHarness.with({ selector: shareToggleId }));
await toggle.toggle();

expect(matDialog.open).toHaveBeenCalled();
expect(openSpy).toHaveBeenCalled();
});

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({}));
node.entry.properties['qshare:sharedId'] = 'sharedId';

Expand All @@ -208,6 +208,7 @@ describe('ShareDialogComponent', () => {
};

fixture.detectChanges();
await fixture.whenStable();

const toggle = await loader.getHarness(MatSlideToggleHarness.with({ selector: shareToggleId }));
await toggle.toggle();
Expand All @@ -216,7 +217,8 @@ describe('ShareDialogComponent', () => {
});

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();
node.entry.properties['qshare:sharedId'] = 'sharedId';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,24 @@
*/

import { Component, Inject, OnInit, ViewEncapsulation, ViewChild, OnDestroy } from '@angular/core';
import { MAT_DIALOG_DATA, MatDialog, MatDialogRef } from '@angular/material/dialog';
import { MatSlideToggleChange } from '@angular/material/slide-toggle';
import { FormControl, FormGroup, Validators } from '@angular/forms';
import { MAT_DIALOG_DATA, MatDialog, MatDialogModule, MatDialogRef } from '@angular/material/dialog';
import { MatSlideToggleChange, MatSlideToggleModule } from '@angular/material/slide-toggle';
import { FormControl, FormGroup, ReactiveFormsModule, Validators } from '@angular/forms';
import { Subject } from 'rxjs';
import { ContentService } from '../common/services/content.service';
import { SharedLinksApiService } from './services/shared-links-api.service';
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 { RenditionService } from '../common/services/rendition.service';
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 {
sharedUrl: FormControl<string>;
Expand All @@ -35,6 +42,20 @@ interface SharedDialogFormProps {

@Component({
selector: 'adf-share-dialog',
standalone: true,
imports: [
CommonModule,
TranslateModule,
MatIconModule,
MatDialogModule,
ReactiveFormsModule,
MatSlideToggleModule,
MatFormFieldModule,
MatDatepickerModule,
MatInputModule,
ClipboardModule,
MatButtonModule
],
templateUrl: './content-node-share.dialog.html',
styleUrls: ['./content-node-share.dialog.scss'],
host: { class: 'adf-share-dialog' },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,12 @@ import { Component } from '@angular/core';
import { DOCUMENT } from '@angular/common';
import { ContentTestingModule } from '../testing/content.testing.module';
import { CoreModule } from '@alfresco/adf-core';
import { ContentNodeShareModule } from './content-node-share.module';
import { NodeSharedDirective } from '@alfresco/adf-content-services';

@Component({
selector: 'adf-node-share-test-component',
standalone: true,
imports: [NodeSharedDirective],
template: `
<button
[disabled]="!shareRef.isFile"
Expand All @@ -51,8 +53,7 @@ describe('NodeSharedDirective', () => {

beforeEach(() => {
TestBed.configureTestingModule({
imports: [CoreModule.forRoot(), ContentTestingModule, ContentNodeShareModule],
declarations: [NodeShareTestComponent]
imports: [CoreModule.forRoot(), ContentTestingModule, NodeShareTestComponent]
});
fixture = TestBed.createComponent(NodeShareTestComponent);
document = TestBed.inject(DOCUMENT);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import { takeUntil } from 'rxjs/operators';

@Directive({
selector: '[adf-share]',
standalone: true,
exportAs: 'adfShare'
})
export class NodeSharedDirective implements OnChanges, OnDestroy {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,14 @@
*/

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 { 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({
imports: [CoreModule, CommonModule, MaterialModule],
declarations: [ShareDialogComponent, NodeSharedDirective],
exports: [ShareDialogComponent, NodeSharedDirective]
imports: [...CONTENT_NODE_SHARE_DIRECTIVES],
exports: [...CONTENT_NODE_SHARE_DIRECTIVES]
})
export class ContentNodeShareModule {}
6 changes: 3 additions & 3 deletions lib/content-services/src/lib/content.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import { SearchModule } from './search/search.module';
import { BREADCRUMB_DIRECTIVES } from './breadcrumb/breadcrumb.module';
import { CONTENT_VERSION_DIRECTIVES } from './version-manager/version-manager.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_DIALOG_DIRECTIVES } from './dialogs/dialog.module';
import { CONTENT_METADATA_DIRECTIVES } from './content-metadata/content-metadata.module';
Expand Down Expand Up @@ -64,7 +64,7 @@ import { TreeViewComponent } from './tree-view';
DropdownSitesComponent,
...BREADCRUMB_DIRECTIVES,
ContentNodeSelectorModule,
ContentNodeShareModule,
...CONTENT_NODE_SHARE_DIRECTIVES,
...CONTENT_METADATA_DIRECTIVES,
...CONTENT_DIRECTIVES,
...CONTENT_PERMISSION_MANAGER_DIRECTIVES,
Expand All @@ -90,7 +90,7 @@ import { TreeViewComponent } from './tree-view';
DropdownSitesComponent,
...BREADCRUMB_DIRECTIVES,
ContentNodeSelectorModule,
ContentNodeShareModule,
...CONTENT_NODE_SHARE_DIRECTIVES,
...CONTENT_METADATA_DIRECTIVES,
...CONTENT_DIALOG_DIRECTIVES,
...CONTENT_DIRECTIVES,
Expand Down

0 comments on commit 6ca737a

Please sign in to comment.