From 09a064008900b4c084d593c4db2d9ffb765d75e1 Mon Sep 17 00:00:00 2001 From: David Steinberg Date: Mon, 9 Sep 2019 09:56:22 -0700 Subject: [PATCH] Turn back on tests for snapshotting (#779) * Turn tests back on * Fixing tests * Change refresh logic * Handle browsing away properly add some types lint * Better message for snapshots too * remove unused * It should have none to start * Rename test and make positive test for button * Snapshot/snapshot and requested/create Fix test Use proper type for booleans --- cypress/integration/group2/myworkflows.ts | 38 ++++++++-------- .../immutableDatabaseTests/workflowDetails.ts | 7 +-- src/app/workflow/view/view.component.ts | 29 ------------ src/app/workflow/view/view.service.ts | 44 +++++++++++-------- 4 files changed, 49 insertions(+), 69 deletions(-) diff --git a/cypress/integration/group2/myworkflows.ts b/cypress/integration/group2/myworkflows.ts index 8f91f3ba7f..229b5d26da 100644 --- a/cypress/integration/group2/myworkflows.ts +++ b/cypress/integration/group2/myworkflows.ts @@ -70,24 +70,26 @@ describe('Dockstore my workflows', () => { cy.get('[data-cy=save-version').click(); cy.get('[data-cy=save-version').should('not.be.visible'); }); - // TODO turn back on - // it('Should be able to snapshot', () => { - // cy.visit('/my-workflows/github.com/A/l'); - // cy.url().should('eq', Cypress.config().baseUrl + '/my-workflows/github.com/A/l'); - // goToTab('Versions'); - // cy.get('[data-cy=dockstore-snapshot-locked]').should('have.length', 0); - // - // cy.get('[data-cy=dockstore-snapshot-unlocked]') - // .its('length') - // .should('be.gt', 0); - // - // cy.get('[data-cy=dockstore-snapshot]') - // .first() - // .click(); - // - // cy.wait(250); - // cy.get('[data-cy=dockstore-snapshot-locked').should('have.length', 1); - // }); + + it('Should be able to snapshot', () => { + cy.visit('/my-workflows/github.com/A/l'); + cy.url().should('eq', Cypress.config().baseUrl + '/my-workflows/github.com/A/l'); + goToTab('Versions'); + cy.get('[data-cy=dockstore-snapshot-locked]').should('have.length', 0); + + cy.get('[data-cy=dockstore-snapshot-unlocked]') + .its('length') + .should('be.gt', 0); + + cy.get('[data-cy=dockstore-snapshot]') + .first() + .click(); + + cy.get('[data-cy=confirm-dialog-button]').click(); + + cy.wait(250); + cy.get('[data-cy=dockstore-snapshot-locked').should('have.length', 1); + }); }); describe('Look at an invalid workflow', () => { diff --git a/cypress/integration/immutableDatabaseTests/workflowDetails.ts b/cypress/integration/immutableDatabaseTests/workflowDetails.ts index 9f491d7d95..9277fcd5ae 100644 --- a/cypress/integration/immutableDatabaseTests/workflowDetails.ts +++ b/cypress/integration/immutableDatabaseTests/workflowDetails.ts @@ -61,19 +61,20 @@ describe('Dockstore Workflow Details', () => { cy.url().should('eq', Cypress.config().baseUrl + '/workflows/github.com/A/l:master?tab=launch'); }); - it('Change tab to versions and not see snapshot', () => { + it('Change tab to versions and not see snapshotted version', () => { goToTab('Versions'); cy .get('tbody>tr') .should('have.length', 1); // 1 Version and no warning line cy.url().should('eq', Cypress.config().baseUrl + '/workflows/github.com/A/l:master?tab=versions'); + // Buttons to create snapshots are hidden on public + cy.get('[data-cy=dockstore-snapshot]').should('not.be.visible'); cy.get('[data-cy=dockstore-snapshot-locked]').should('have.length', 0); cy.get('[data-cy=dockstore-snapshot-unlocked]') .its('length') .should('be.gt', 0); - cy.get('[data-cy=dockstore-snapshot]') - .should('not.be.visible'); + }); describe('Change tab to files', () => { diff --git a/src/app/workflow/view/view.component.ts b/src/app/workflow/view/view.component.ts index 451979221f..4bb457885e 100644 --- a/src/app/workflow/view/view.component.ts +++ b/src/app/workflow/view/view.component.ts @@ -18,7 +18,6 @@ import { Component, Input, OnInit } from '@angular/core'; import { MatDialog } from '@angular/material'; import { EntryType } from 'app/shared/enum/entry-type'; import { BioWorkflow } from 'app/shared/swagger/model/bioWorkflow'; -import { WorkflowVersion } from 'app/shared/swagger/model/workflowVersion'; import { Service } from 'app/shared/swagger/model/service'; import { Observable } from 'rxjs'; import { takeUntil } from 'rxjs/operators'; @@ -97,34 +96,6 @@ export class ViewWorkflowComponent extends View implements OnInit { }); } - /** - * Updates the workflow version and alerts the Dockstore User with success - * or failure. - * - * @private - * @memberof ViewWorkflowComponent - */ - private updateWorkflowToSnapshot(version): void { - // Clear sourcefiles to shrink version - version.sourceFiles = []; - - this.workflowsService.updateWorkflowVersion(this.workflow.id, [version]).subscribe( - workflowVersions => { - this.alertService.detailedSuccess('Snapshot successfully created!'); - const workflow = { ...this.workflowQuery.getActive() }; - workflow.workflowVersions = workflowVersions; - this.workflowService.setWorkflow(workflow); - }, - error => { - if (error) { - this.alertService.detailedError(error); - } else { - this.alertService.simpleError(); - } - } - ); - } - /** * Handles the create DOI button being clicked * diff --git a/src/app/workflow/view/view.service.ts b/src/app/workflow/view/view.service.ts index e94861a371..eb942c4979 100644 --- a/src/app/workflow/view/view.service.ts +++ b/src/app/workflow/view/view.service.ts @@ -17,12 +17,10 @@ import { Injectable } from '@angular/core'; import { HttpErrorResponse } from '@angular/common/http'; import { MatDialog } from '@angular/material'; import { BehaviorSubject, Observable, of as observableOf, Subject } from 'rxjs'; -import { concatMap } from 'rxjs/operators'; import { AlertService } from '../../shared/alert/state/alert.service'; import { RefreshService } from '../../shared/refresh.service'; import { WorkflowQuery } from '../../shared/state/workflow.query'; import { WorkflowsService } from '../../shared/swagger/api/workflows.service'; -import { SourceFile } from '../../shared/swagger/model/sourceFile'; import { WorkflowService } from '../../shared/state/workflow.service'; import { Workflow, WorkflowVersion } from '../../shared/swagger'; import { ConfirmationDialogService } from '../../confirmation-dialog/confirmation-dialog.service'; @@ -37,9 +35,7 @@ export class ViewService { private confirmationDialogService: ConfirmationDialogService, private workflowQuery: WorkflowQuery, private workflowService: WorkflowService, - private workflowsService: WorkflowsService, - private refreshService: RefreshService, - private matDialog: MatDialog + private workflowsService: WorkflowsService ) {} /** @@ -52,13 +48,16 @@ export class ViewService { private updateWorkflowToSnapshot(workflow: Workflow, version: WorkflowVersion, cb: Function): void { const snapshot: WorkflowVersion = { ...version, frozen: true }; this.workflowsService.updateWorkflowVersion(workflow.id, [snapshot]).subscribe( - workflowVersions => { + (workflowVersions: Array) => { + this.alertService.detailedSuccess(`A snapshot was created for workflow + "${workflow.workflowName}" version "${version.name}"!`); + const selectedWorkflow = { ...this.workflowQuery.getActive() }; + if (selectedWorkflow.id === workflow.id) { + this.workflowService.setWorkflow({ ...selectedWorkflow, workflowVersions: workflowVersions }); + } cb(workflowVersions); - const activeWorkflow = { ...this.workflowQuery.getActive() }; - workflow.workflowVersions = workflowVersions; - this.workflowService.setWorkflow(activeWorkflow); }, - error => { + (error: HttpErrorResponse) => { if (error) { this.alertService.detailedError(error); } else { @@ -102,7 +101,8 @@ export class ViewService { private showRequestDOIDialog(workflow: Workflow, version: WorkflowVersion): void { const dialogData: ConfirmationDialogData = { message: `A Digital Object Identifier (DOI) allows a version to be easily cited in publications and can't be - undone, though some metadata will remain editable. Are you sure you'd like to create a DOI for version + undone, though some metadata will remain editable. It can take some time to request a DOI. + Are you sure you'd like to create a DOI for version ${version.name}?`, title: 'Issue DOI', confirmationButtonText: 'Issue DOI', @@ -114,8 +114,8 @@ export class ViewService { this.workflowsService .requestDOIForWorkflowVersion(workflow.id, version.id) .subscribe( - versions => this.requestDOISuccess(version, versions), - errorResponse => this.alertService.detailedError(errorResponse) + (versions: Array) => this.requestDOISuccess({ ...workflow, workflowVersions: versions }, version), + (errorResponse: HttpErrorResponse) => this.alertService.detailedError(errorResponse) ); } else { this.alertService.detailedSuccess('You cancelled DOI issuance.'); @@ -129,10 +129,13 @@ export class ViewService { * @private * @memberof ViewService */ - private requestDOISuccess(version: WorkflowVersion, workflowVersions: Array): void { - const newSelectedVersion = workflowVersions.find(v => v.id === version.id); - this.workflowService.setWorkflowVersion(newSelectedVersion); - this.alertService.simpleSuccess(); + private requestDOISuccess(workflow: Workflow, version: WorkflowVersion): void { + const selectedWorkflow = { ...this.workflowQuery.getActive() }; + if (selectedWorkflow.id === workflow.id) { + this.workflowService.setWorkflow(workflow); + } + this.alertService.detailedSuccess(`A Digital Object Identifier (DOI) was created for workflow + "${workflow.workflowName}" version "${version.name}"!`); } /** @@ -153,9 +156,12 @@ export class ViewService { confirmationButtonText: 'Snapshot Version', cancelButtonText: 'Cancel' }; - this.confirmationDialogService.openDialog(dialogData, bootstrap4mediumModalSize).subscribe(confirmationResult => { + this.confirmationDialogService.openDialog(dialogData, bootstrap4mediumModalSize).subscribe((confirmationResult: boolean) => { if (confirmationResult) { - this.updateWorkflowToSnapshot(workflow, version, () => this.alertService.detailedSuccess('Snapshot successfully created!')); + this.updateWorkflowToSnapshot(workflow, version, () => { + this.alertService.detailedSuccess(`A snapshot was created for workflow + "${workflow.workflowName}" version "${version.name}"!`); + }); } else { this.alertService.detailedSuccess('You cancelled creating a snapshot.'); }