Skip to content
This repository was archived by the owner on Mar 8, 2020. It is now read-only.
Merged
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
7 changes: 7 additions & 0 deletions packages/composer-common/lib/querymanager.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,13 @@ class QueryManager {
return [];
}

/**
* Remove the Query
*/
deleteQueryFile() {
delete this.queryFile;
}

/**
* Get the named Query associated with this QueryManager
* @param {string} name - the name of the query
Expand Down
14 changes: 13 additions & 1 deletion packages/composer-common/test/querymanager.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const ModelManager = require('../lib/modelmanager');
const path = require('path');

const chai = require('chai');
chai.should();
const should = chai.should();
chai.use(require('chai-things'));
const sinon = require('sinon');

Expand Down Expand Up @@ -82,6 +82,18 @@ describe('QueryManager', () => {
});
});

describe('#deleteQueryFile', () => {

it('should delete the query file', () => {
let qm = new QueryManager(modelManager);
qm.setQueryFile(queryFile);
qm.getQueryFile().should.equal(queryFile);
qm.deleteQueryFile();
should.not.exist(qm.getQueryFile());
});

});

describe('#getQuery', () => {

it('should return a named query', () => {
Expand Down
24 changes: 24 additions & 0 deletions packages/composer-playground/e2e/component/add-file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,24 @@ export class AddFile {
});
}

// Select ACL file via Radio Button
static selectAddAclViaRadioOption() {
// AddFile modal should be present
return browser.wait(ExpectedConditions.visibilityOf(element(by.css('.import'))), 10000)
.then(() => {
return OperationsHelper.click(element(by.css('[for="file-type-acl"]')));
});
}

// Select Query file via Radio Button
static selectAddQueryViaRadioOption() {
// AddFile modal should be present
return browser.wait(ExpectedConditions.visibilityOf(element(by.css('.import'))), 10000)
.then(() => {
return OperationsHelper.click(element(by.css('[for="file-type-qry"]')));
});
}

// Select BND from BNA file drop
static selectFromFile(filePath: string) {
// Import modal should be present
Expand All @@ -70,4 +88,10 @@ export class AddFile {
});
}

// Get all radio buttons
static retrieveAddFileRadioButtons() {
return OperationsHelper.retriveMatchingElementsByCSS('.file-types-list', '[type="radio"]')
.map((elm) => { return {name: elm.getAttribute('id'), enabled: elm.isEnabled()}; });
}

}
134 changes: 126 additions & 8 deletions packages/composer-playground/e2e/specs/editor-define.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ describe('Editor Define', (() => {

it('should enable cancel of BNA import', (() => {
// Select BNA
Import.selectBusinessNetworkDefinitionFromFile('./e2e/data/bna/unnamed-network.bna');
Import.selectBusinessNetworkDefinitionFromFile('./e2e/data/bna/empty-network.bna');

// Replace confirm should show, cancel it
Replace.cancelReplace();
Expand Down Expand Up @@ -94,7 +94,7 @@ describe('Editor Define', (() => {

it('should enable empty BNA import via file selection', (() => {
// Select BNA
Import.selectBusinessNetworkDefinitionFromFile('./e2e/data/bna/unnamed-network.bna');
Import.selectBusinessNetworkDefinitionFromFile('./e2e/data/bna/empty-network.bna');

// Replace confirm should show, confirm it
Replace.confirmReplace();
Expand Down Expand Up @@ -193,13 +193,9 @@ describe('Editor Define', (() => {
});
});

afterAll(() => {
afterEach(() => {
// Reset network
Editor.clickImportBND();
Import.selectBusinessNetworkDefinitionFromFile('./e2e/data/bna/basic-sample-network.bna');
Replace.confirmReplace();
Import.waitToDisappear();
OperationsHelper.processExpectedSuccess();
OperationsHelper.importBusinessNetworkArchive('./e2e/data/bna/basic-sample-network.bna');
});

it('should bring up an AddFile modal that can be closed by cancel button', (() => {
Expand Down Expand Up @@ -489,6 +485,60 @@ describe('Editor Define', (() => {
});
}));

it('should enable the addition of an ACL file via radio button selection', (() => {
AddFile.clickCancelAdd();
OperationsHelper.importBusinessNetworkArchive('./e2e/data/bna/empty-network.bna');

Editor.clickAddFile();
AddFile.waitToAppear();

Editor.retrieveNavigatorFileNames()
.then((names) => {
// Select radio option
AddFile.selectAddAclViaRadioOption();
// Add option becomes enabled
AddFile.clickConfirmAdd();
return names;
})
.then((startFiles) => {
// -active file
Editor.retrieveNavigatorActiveFile()
.then((list: any) => {
expect(list).to.be.an('array').lengthOf(1);
expect(list).to.include('Access Control\npermissions.acl');
});
// Check extracted against new template file that we should have in the list
Editor.retrieveNavigatorFileNames()
.then((filenames: any) => {
// We should have added one file
expect(filenames).to.be.an('array').lengthOf(startFiles.length + 1);
expect(filenames).to.include('Access Control\npermissions.acl');
// Previous files should still exist
startFiles.forEach((file) => {
expect(file).to.be.oneOf(filenames);
});
});
// -deploy enabled
Editor.retrieveNavigatorFileActionButtons()
.then((buttonlist: any) => {
expect(buttonlist).to.be.an('array').lengthOf(2);
expect(buttonlist[0]).to.deep.equal({text: '+ Add a file...', enabled: true});
expect(buttonlist[1]).to.deep.equal({text: 'Deploy', enabled: true});
});
// deploy new item
Editor.clickDeployBND();
// -success message
OperationsHelper.processExpectedSuccess();
// -deploy disabled
Editor.retrieveNavigatorFileActionButtons()
.then((buttonlist: any) => {
expect(buttonlist).to.be.an('array').lengthOf(2);
expect(buttonlist[0]).to.deep.equal({text: '+ Add a file...', enabled: true});
expect(buttonlist[1]).to.deep.equal({text: 'Deploy', enabled: false});
});
});
}));

it('should enable the addition of a Readme file via file input event', (() => {
Editor.retrieveNavigatorFileNames()
.then((names) => {
Expand Down Expand Up @@ -541,6 +591,54 @@ describe('Editor Define', (() => {
});
}));

it('should enable the addition of a Query file via radio button selection', (() => {
Editor.retrieveNavigatorFileNames()
.then((names) => {
// Select radio option
AddFile.selectAddQueryViaRadioOption();
// Add option becomes enabled
AddFile.clickConfirmAdd();
return names;
})
.then((startFiles) => {
// -active file
Editor.retrieveNavigatorActiveFile()
.then((list: any) => {
expect(list).to.be.an('array').lengthOf(1);
expect(list).to.include('Query File\nqueries.qry');
});
// Check extracted against new template file that we should have in the list
Editor.retrieveNavigatorFileNames()
.then((filenames: any) => {
// We should have added one file
expect(filenames).to.be.an('array').lengthOf(startFiles.length + 1);
expect(filenames).to.include('Query File\nqueries.qry');
// Previous files should still exist
startFiles.forEach((file) => {
expect(file).to.be.oneOf(filenames);
});
});
// -deploy enabled
Editor.retrieveNavigatorFileActionButtons()
.then((buttonlist: any) => {
expect(buttonlist).to.be.an('array').lengthOf(2);
expect(buttonlist[0]).to.deep.equal({text: '+ Add a file...', enabled: true});
expect(buttonlist[1]).to.deep.equal({text: 'Deploy', enabled: true});
});
// deploy new item
Editor.clickDeployBND();
// -success message
OperationsHelper.processExpectedSuccess();
// -deploy disabled
Editor.retrieveNavigatorFileActionButtons()
.then((buttonlist: any) => {
expect(buttonlist).to.be.an('array').lengthOf(2);
expect(buttonlist[0]).to.deep.equal({text: '+ Add a file...', enabled: true});
expect(buttonlist[1]).to.deep.equal({text: 'Deploy', enabled: false});
});
});
}));

it('should enable the addition of a Query file via file input event', (() => {
Editor.retrieveNavigatorFileNames()
.then((names) => {
Expand Down Expand Up @@ -591,6 +689,26 @@ describe('Editor Define', (() => {
});
}));

it('should prevent the addition of a query file and/or acl file if one exists already', (() => {
AddFile.clickCancelAdd();
OperationsHelper.importBusinessNetworkArchive('./e2e/data/bna/importBNA.bna');

Editor.clickAddFile();
AddFile.waitToAppear();

AddFile.retrieveAddFileRadioButtons()
.then((radioList: any) => {
expect(radioList).to.be.an('array').lengthOf(4);
expect(radioList).to.contain({name: 'file-type-cto', enabled: true});
expect(radioList).to.contain({name: 'file-type-js', enabled: true});
expect(radioList).to.contain({name: 'file-type-qry', enabled: false});
expect(radioList).to.contain({name: 'file-type-acl', enabled: false});
});

AddFile.clickCancelAdd();

}));

it('should prevent the addition of a file with an invalid file extension', (() => {
AddFile.selectFromFile('./e2e/data/files/importBanned.wombat');
ErrorAlert.clickCloseError();
Expand Down
12 changes: 12 additions & 0 deletions packages/composer-playground/e2e/utils/operations-helper.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import { browser, element, by } from 'protractor';
import { ExpectedConditions, ElementFinder } from 'protractor';

import { Editor } from '../component/editor';
import { Import } from '../component/import';
import { Replace } from '../component/replace';

export class OperationsHelper {

// Perform a 'safe' click action on an element
Expand Down Expand Up @@ -47,4 +51,12 @@ export class OperationsHelper {
browser.wait(ExpectedConditions.visibilityOf(element(by.id('success_notify'))), 5000);
browser.wait(ExpectedConditions.invisibilityOf(element(by.id('success_notify'))), 5000);
};

static importBusinessNetworkArchive(fileName: string) {
Editor.clickImportBND();
Import.selectBusinessNetworkDefinitionFromFile(fileName);
Replace.confirmReplace();
Import.waitToDisappear();
this.processExpectedSuccess();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<svg class="ibm-icon" aria-hidden="true">
<use xlink:href="#icon-warn_32"></use>
</svg>
<h1>Current definition will be replaced</h1>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would appear that we are now using this replace modal in different places for different things - we should probably start making these inputs to modal to make it easier to use and more flexible

<h1>Current {{resource}} will be replaced</h1>
<button class="icon modal-exit" (click)="activeModal.close(false)">
<svg class="ibm-icon" aria-hidden="true">
<use xlink:href="#icon-close_new"></use>
Expand All @@ -18,6 +18,6 @@ <h1>Current definition will be replaced</h1>
</section>
<footer>
<button id="replace_cancel" type="button" class="secondary" (click)="activeModal.dismiss()">Cancel</button>
<button id="replace_confirm" type="button" class="primary" (click)="activeModal.close(true)">Replace & Import</button>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as above -maybe this should be an input to the modal?

<button id="replace_confirm" type="button" class="primary" (click)="activeModal.close(true)">Replace</button>
</footer>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export class ReplaceComponent {
@Input() headerMessage: string = null;
@Input() mainMessage: string = null;
@Input() supplementaryMessage: string = null;
@Input() resource: string = null;

constructor(public activeModal: NgbActiveModal) {
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ <h1>Add a file</h1>
</div>
<section class="modal-body">
<span>Upload a file from your computer...</span>
<file-importer *ngIf="!currentFile" (fileAccepted)="fileAccepted($event)" (fileRejected)="fileRejected($event)" [expandInput]="expandInput"
<file-importer (fileAccepted)="fileAccepted($event)" (fileRejected)="fileRejected($event)" [expandInput]="expandInput"
[maxFileSize]="maxFileSize" [supportedFileTypes]="supportedFileTypes" [ngClass]="{'expandFile': expandInput}" [svgName]="'#icon-CTO_JS_Upload'"></file-importer>
<div class="chosen-file" *ngIf="expandInput && currentFile">
<div class="file-info">
Expand Down Expand Up @@ -58,6 +58,22 @@ <h1>Add a file</h1>
Define the logic of transaction executions using JavaScript.
</div>
</div>
<div class="file-types-list-item" [ngClass]="{'selection-disabled': queryExists()}">
<input [disabled]="queryExists()" type="radio" id="file-type-qry" name="file-type-qry" [(ngModel)]="fileType" value="qry"
(change)="changeCurrentFileType()">
<label class="radio-label" for="file-type-qry">Query File (.qry)</label>
<div class="description">
Define the queries in here (Note: you can only have 1 of these per .bna).
</div>
</div>
<div class="file-types-list-item" [ngClass]="{'selection-disabled': aclExists()}">
<input [disabled]="aclExists()" type="radio" id="file-type-acl" name="file-type-acl" [(ngModel)]="fileType" value="acl"
(change)="changeCurrentFileType()">
<label class="radio-label" for="file-type-acl">Access Control File (permissions.acl)</label>
<div class="description">
Define your access controls here (Note: you can only have 1 of these per .bna).
</div>
</div>
</form>
</section>
<footer>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,20 @@
add-file-modal {
.import {
width: 700px;
height: 520px;
height: 100%;

display: flex;
flex-direction: column;

.file-types-list {
max-height: 250px;
max-height: 100%;
padding-right: 0px;
margin-top: 16px;

.selection-disabled {
opacity: 0.5;
}

.file-types-list-item {
background-color: $third-highlight;
padding: $space-medium;
Expand Down
Loading