Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@
</div>
</div>
<pr-share-preview-footer
*ngIf="!isLoggedIn"
*ngIf="!isLoggedIn && !isUnlistedShare"
[accountUserName]="shareAccount.fullName"
[closeEvent]="hideBannerObservable"
></pr-share-preview-footer>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ import { DialogCdkService } from '@root/app/dialog-cdk/dialog-cdk.service';
import { AccountVO, ArchiveVO, RecordVO } from '@root/app/models';
import { AuthResponse } from '@shared/services/api/auth.repo';
import { Subject } from 'rxjs';
import { ShareLinksService } from '@root/app/share-links/services/share-links.service';
import { ApiService } from '@shared/services/api/api.service';
import { GoogleAnalyticsService } from '@shared/services/google-analytics/google-analytics.service';
import { ShareResponse } from '@shared/services/api/share.repo';
import { CreateAccountDialogComponent } from '../create-account-dialog/create-account-dialog.component';
import { SharePreviewComponent } from './share-preview.component';

Expand All @@ -40,6 +44,10 @@ export const mockAccountService = jasmine.createSpyObj('AccountService', [
const defaultAccount = new AccountVO({ primaryEmail: '[email protected]' });
const defaultArchive = new ArchiveVO({ archiveId: 123 });

const mockGoogleAnalyticsService = {
sendEvent: jasmine.createSpy(),
};

mockAccountService.getAccount.and.returnValue(defaultAccount);
mockAccountService.getArchive.and.returnValue(defaultArchive);
mockAccountService.isLoggedIn.and.returnValue(true);
Expand All @@ -59,11 +67,17 @@ mockAccountService.setRedirect.and.stub();
mockAccountService.archiveChange = new Subject<ArchiveVO>();
mockAccountService.accountChange = new Subject<AccountVO>();

const mockShareLinksService = {
currentShareToken: null,
isUnlistedShare: () => true,
};

describe('SharePreviewComponent', () => {
let component: SharePreviewComponent;
let fixture: ComponentFixture<SharePreviewComponent>;
let dialog: DialogCdkService;
let router: Router;
let apiService: ApiService;

beforeEach(async () => {
const config: TestModuleMetadata = cloneDeep(Testing.BASE_TEST_CONFIG);
Expand Down Expand Up @@ -98,10 +112,21 @@ describe('SharePreviewComponent', () => {
useValue: mockRoute,
});

config.providers.push({
provide: ShareLinksService,
useValue: mockShareLinksService,
});

config.providers.push({
provide: GoogleAnalyticsService,
useValue: mockGoogleAnalyticsService,
});

await TestBed.configureTestingModule(config).compileComponents();

dialog = TestBed.inject(DialogCdkService);
router = TestBed.inject(Router);
apiService = TestBed.inject(ApiService);
spyOn(router, 'navigate');

fixture = TestBed.createComponent(SharePreviewComponent);
Expand All @@ -113,11 +138,22 @@ describe('SharePreviewComponent', () => {
expect(component).toBeTruthy();
});

it('should open dialog shortly after loading if user is logged out', fakeAsync(() => {
it('should mark it as unlisted share if restrictions are none', fakeAsync(() => {
spyOn(mockShareLinksService, 'isUnlistedShare').and.returnValue(true);
component.ngOnInit();

expect(mockShareLinksService.isUnlistedShare).toHaveBeenCalled();
tick(1005);

expect(component.isUnlistedShare).toEqual(true);
}));

it('should open dialog shortly after loading if user is logged out and it is not an unlisted share', fakeAsync(() => {
const dialogRefSpy = jasmine.createSpyObj('DialogRef', ['close']);
const dialogSpy = spyOn(dialog, 'open').and.returnValue(dialogRefSpy);

component.isLoggedIn = false;
component.isUnlistedShare = false;
component.showCreateAccountDialog();
tick(1005);

Expand All @@ -126,23 +162,48 @@ describe('SharePreviewComponent', () => {
});
}));

it('should not open dialog if already open', () => {
const dialogSpy = spyOn(dialog, 'open');
component.createAccountDialogIsOpen = true;
it('should not open dialog if user is logged out, but it is an unlisted share', fakeAsync(() => {
const dialogRefSpy = jasmine.createSpyObj('DialogRef', ['close']);
const dialogSpy = spyOn(dialog, 'open').and.returnValue(dialogRefSpy);

component.showCreateAccountDialog();
component.isLoggedIn = false;
component.isUnlistedShare = true;
component.ngOnInit();
tick(1005);

expect(dialogSpy).not.toHaveBeenCalled();
});
}));

it('should not open dialog if user is logged in and it is not an unlisted share', fakeAsync(() => {
const dialogRefSpy = jasmine.createSpyObj('DialogRef', ['close']);
const dialogSpy = spyOn(dialog, 'open').and.returnValue(dialogRefSpy);

component.isLoggedIn = true;
component.isUnlistedShare = false;
component.ngOnInit();
tick(1005);

expect(dialogSpy).not.toHaveBeenCalled();
}));

it('should not open dialog shortly after loading if user is logged in', fakeAsync(() => {
it('should not open dialog shortly after loading if user is logged in and share is unlisted', fakeAsync(() => {
const dialogSpy = spyOn(dialog, 'open');
component.isLoggedIn = true;
component.isUnlistedShare = true;
tick(1005);

expect(dialogSpy).not.toHaveBeenCalled();
}));

it('should not open dialog if already open', () => {
const dialogSpy = spyOn(dialog, 'open');
component.createAccountDialogIsOpen = true;

component.showCreateAccountDialog();

expect(dialogSpy).not.toHaveBeenCalled();
});

it('should open dialog when a thumbnail is clicked', fakeAsync(() => {
const dialogRefSpy = jasmine.createSpyObj('DialogRef', ['close']);
const dialogSpy = spyOn(dialog, 'open').and.returnValue(dialogRefSpy);
Expand Down Expand Up @@ -212,4 +273,61 @@ describe('SharePreviewComponent', () => {

expect(router.navigate).toHaveBeenCalledWith(['/app', 'auth', 'signup']);
});

it('should reload share preview data for link share', fakeAsync(() => {
component.isLinkShare = true;
component.isRelationshipShare = false;

const mockVO = { ShareVO: { status: 'ok', accessRole: 'editor' } };
spyOn(apiService.share, 'checkShareLink').and.returnValue(
Promise.resolve({
isSuccessful: true,
getShareByUrlVO: () => mockVO,
} as unknown as ShareResponse),
);

spyOn(component, 'checkAccess');

component.reloadSharePreviewData();
tick(1005);

expect(apiService.share.checkShareLink).toHaveBeenCalled();
expect(component.sharePreviewVO).toEqual(mockVO);
expect(component.checkAccess).toHaveBeenCalled();
}));

it('should reload share preview data for relationship share', fakeAsync(() => {
const mockVO = { ShareVO: { status: 'ok', accessRole: 'owner' } };
spyOn(apiService.share, 'getShareForPreview').and.returnValue(
Promise.resolve({
getShareVO: () => mockVO,
} as unknown as ShareResponse),
);
component.isLinkShare = false;
component.isRelationshipShare = true;

spyOn(component, 'checkAccess');

component.reloadSharePreviewData();
tick(1005);

expect(apiService.share.getShareForPreview).toHaveBeenCalled();
expect(component.sharePreviewVO).toEqual(mockVO);
expect(component.checkAccess).toHaveBeenCalled();
}));

it('should request access and not show cover', fakeAsync(() => {
component.archiveConfirmed = false;
component.chooseArchiveText = 'Choose archive';
component.shareToken = 'mock-token';
component.shareAccount = {
fullName: 'Sharer Name',
} as unknown as AccountVO;

component.onRequestAccessClick();
tick(2005);

expect(component.hasRequested).toBeTrue();
expect(component.showCover).toBeFalse();
}));
});
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ export class SharePreviewComponent implements OnInit, OnDestroy {
this.sendGaEvent('previewed');
}

if (!this.isLoggedIn) {
if (!this.isLoggedIn && !this.isUnlistedShare) {
setTimeout(() => {
this.showCreateAccountDialog();
}, 1000);
Expand Down