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
11 changes: 11 additions & 0 deletions contrib-notes/release-process/playground-validation.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,9 @@ From the initial logon, the user should be presented with the “Hello World”

## Playground Test Areas

### General
Check that all page links are linking correctly (no 404s)

### Define Page (Side Navigation)
The define page is used to manage files and file content. Through the side navigation menu it is possible to perform working file selection/creation, and lifecycle actions such as import, export and deploy.

Expand Down Expand Up @@ -130,6 +133,14 @@ Following from reset to basic sample network by import of the basic sample netwo
- deploy button no longer active
- All files previously visible remain in navigation
- Repeat to add another script and model file
- Add a ReadMe file via the "AddFile" option and browsing to a ReadMe file on disc
- On selection the modal should indicate that a Readme file is to be imported
- On confirmation a warning modal should inform that the current readme will be overwritten
- On confirm, the existing readme should be replaced with that selected
- Add a ReadMe file via the "AddFile" option and drag/drop action of a ReadMe file on disc
- On selection the modal should indicate that a Readme file is to be imported
- On confirmation a warning modal should inform that the current readme will be overwritten
- On confirm, the existing readme should be replaced with that selected
- On export, exported BNA should contain the newly added files (2 script, 2 model)

### Define Page (File-Editor)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ <h1>Add a file</h1>
<svg class="ibm-icon" aria-hidden="true">
<use xlink:href="#icon-JS_File" *ngIf="fileType==='js'"></use>
<use xlink:href="#icon-CTO_File" *ngIf="fileType==='cto'"></use>
<use xlink:href="#icon-MD_File" *ngIf="fileType==='md'"></use>
</svg>
<div class="file-title">
<div class="title">{{currentFileName}}</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ describe('AddFileComponent', () => {
});

describe('#fileAccepted', () => {
it('should call this.createModel', fakeAsync(() => {
it('should call this.createModel if model file detected', fakeAsync(() => {
let b = new Blob(['/**CTO File*/'], {type: 'text/plain'});
let file = new File([b], 'newfile.cto');

Expand All @@ -130,7 +130,7 @@ describe('AddFileComponent', () => {
createMock.should.have.been.called;
}));

it('should call this.createScript', fakeAsync(() => {
it('should call this.createScript if script file detected', fakeAsync(() => {

let b = new Blob(['/**JS File*/'], {type: 'text/plain'});
let file = new File([b], 'newfile.js');
Expand All @@ -144,6 +144,20 @@ describe('AddFileComponent', () => {
createMock.should.have.been.called;
}));

it('should call this.createReadme if readme file detected', fakeAsync(() => {

let b = new Blob(['/**README File*/'], {type: 'text/plain'});
let file = new File([b], 'README.md');

let createMock = sandbox.stub(component, 'createReadme');
let dataBufferMock = sandbox.stub(component, 'getDataBuffer')
.returns(Promise.resolve('some data'));

component.fileAccepted(file);
tick();
createMock.should.have.been.called;
}));

it('should call this.fileRejected when there is an error reading the file', fakeAsync(() => {

let b = new Blob(['/**CTO File*/'], {type: 'text/plain'});
Expand Down Expand Up @@ -255,6 +269,20 @@ describe('AddFileComponent', () => {
}));
});

describe('#createModel', () => {
it('should establish a readme file', async(() => {
component.businessNetwork = mockBusinessNetwork;
let dataBuffer = new Buffer('/**README File**/ read all the things');

component.createReadme(dataBuffer);

component.fileType.should.equal('md');
component.currentFileName.should.equal('README.md');
component.currentFile.should.equal(dataBuffer.toString());
}));

});

describe('#changeCurrentFileType', () => {
it('should set current file to a script file, created by calling createScript with correct parameters', async(() => {
let mockScript = sinon.createStubInstance(Script);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export class AddFileComponent {
expandInput: boolean = false;

maxFileSize: number = 5242880;
supportedFileTypes: string[] = ['.js', '.cto'];
supportedFileTypes: string[] = ['.js', '.cto', '.md'];

addModelNamespace: string = 'org.acme.model';
addModelFileName: string = 'models/org.acme.model';
Expand Down Expand Up @@ -64,6 +64,10 @@ export class AddFileComponent {
this.expandInput = true;
this.createModel(file, data);
break;
case 'md':
this.expandInput = true;
this.createReadme(data);
break;
default:
throw new Error('Unexpected File Type');
}
Expand Down Expand Up @@ -92,7 +96,7 @@ export class AddFileComponent {
this.fileType = 'js';
let scriptManager = this.businessNetwork.getScriptManager();
let filename = file.name ? 'lib/' + file.name : this.addScriptFileName;
this.currentFile = scriptManager.createScript('lib/' + file.name || this.addScriptFileName, 'JS', dataBuffer.toString());
this.currentFile = scriptManager.createScript(filename, 'JS', dataBuffer.toString());
this.currentFileName = this.currentFile.getIdentifier();
}

Expand All @@ -104,6 +108,12 @@ export class AddFileComponent {
this.currentFileName = this.currentFile.getFileName();
}

createReadme(dataBuffer) {
this.fileType = 'md';
this.currentFile = dataBuffer.toString();
this.currentFileName = 'README.md';
}

fileRejected(reason: string) {
this.alertService.errorStatus$.next(reason);
}
Expand Down
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>{{headerMessage}}</h1>
<h1>Current definition 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 Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import * as chai from 'chai';

let should = chai.should();

describe('DeleteComponent', () => {
describe('ReplaceComponent', () => {
let component: ReplaceComponent;
let fixture: ComponentFixture<ReplaceComponent>;

Expand All @@ -32,16 +32,4 @@ describe('DeleteComponent', () => {
component.should.be.ok;
});

describe('onInit', () => {

it('should set default messages', () => {

component['ngOnInit']();

component['headerMessage'].should.be.equal('Current definition will be replaced');
component['mainMessage'].should.be.equal('Your Business Network Definition currently in the Playground will be removed & replaced.');
component['supplementaryMessage'].should.be.equal('Please ensure that you have exported any current model files in the Playground.');
});

});
});
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Component, Input, OnInit } from '@angular/core';
import { Component, Input } from '@angular/core';
import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap';

@Component({
Expand All @@ -7,18 +7,12 @@ import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap';
styleUrls: ['./replace-confirm.component.scss'.toString()]
})

export class ReplaceComponent implements OnInit {
export class ReplaceComponent {

public headerMessage: string = null;
public mainMessage: string = null;
public supplementaryMessage: string = null;
@Input() headerMessage: string = null;
@Input() mainMessage: string = null;
@Input() supplementaryMessage: string = null;

constructor(public activeModal: NgbActiveModal) {
}

ngOnInit() {
this.headerMessage = 'Current definition will be replaced';
this.mainMessage = 'Your Business Network Definition currently in the Playground will be removed & replaced.';
this.supplementaryMessage = 'Please ensure that you have exported any current model files in the Playground.';
}
}
141 changes: 140 additions & 1 deletion packages/composer-playground/src/app/editor/editor.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -643,6 +643,111 @@ describe('EditorComponent', () => {
});
});

describe('addReadme', () => {
it('should not open confirm modal if no readme present', fakeAsync(() => {
let mockUpdateFiles = sinon.stub(component, 'updateFiles');
let mockSetCurrentFile = sinon.stub(component, 'setCurrentFile');
component['files'] = [{id: 'random'}, {id: 'script'}];

let b = new Blob(['/**README File*/'], {type: 'text/plain'});
let mockReadmeFile = new File([b], 'redme.md');

component.addReadme(mockReadmeFile);
tick();

mockModal.open.should.not.have.been.called;
}));

it('should create readme if no existing readme present', fakeAsync(() => {
let mockUpdateFiles = sinon.stub(component, 'updateFiles');
let mockSetCurrentFile = sinon.stub(component, 'setCurrentFile');

component['files'] = [{id: 'zero-index'}, {id: 'script'}];

let b = new Blob(['/**README File*/'], {type: 'text/plain'});
let mockReadmeFile = new File([b], 'readme.md');

component.addReadme(mockReadmeFile);

tick();

mockClientService.setBusinessNetworkReadme.should.have.been.calledWith(mockReadmeFile);
mockUpdateFiles.should.have.been.called;
mockSetCurrentFile.should.have.been.calledWith({id: 'zero-index'});
component['dirty'].should.be.equal(true);
}));

it('should open confirm modal if readme present and handle error', fakeAsync(() => {
let mockUpdateFiles = sinon.stub(component, 'updateFiles');
let mockSetCurrentFile = sinon.stub(component, 'setCurrentFile');
component['files'] = [{readme: true}, {id: 'script'}];

let b = new Blob(['/**README File*/'], {type: 'text/plain'});
let mockReadmeFile = new File([b], 'redme.md');

mockModal.open = sinon.stub().returns({
componentInstance: {},
result: Promise.reject('some error')
});

component.addReadme(mockReadmeFile);
tick();

mockModal.open.should.have.been.called;
mockAlertService.errorStatus$.next.should.have.been.calledWith('some error');
mockClientService.setBusinessNetworkReadme.should.not.have.been.called;
mockUpdateFiles.should.not.have.been.called;
mockSetCurrentFile.should.not.have.been.called;
}));

it('should handle confirm modal cancel', fakeAsync(() => {
let mockUpdateFiles = sinon.stub(component, 'updateFiles');
let mockSetCurrentFile = sinon.stub(component, 'setCurrentFile');
component['files'] = [{readme: true}, {id: 'script'}];

let b = new Blob(['/**README File*/'], {type: 'text/plain'});
let mockReadmeFile = new File([b], 'redme.md');

mockModal.open = sinon.stub().returns({
componentInstance: {},
result: Promise.reject(1)
});

component.addReadme(mockReadmeFile);
tick();

mockModal.open.should.have.been.called;
mockAlertService.errorStatus$.next.should.not.have.been.called;
mockClientService.setBusinessNetworkReadme.should.not.have.been.called;
mockUpdateFiles.should.not.have.been.called;
mockSetCurrentFile.should.not.have.been.called;
}));

it('should create readme on modal confirm', fakeAsync(() => {
let mockUpdateFiles = sinon.stub(component, 'updateFiles');
let mockSetCurrentFile = sinon.stub(component, 'setCurrentFile');
component['files'] = [{readme: true}, {id: 'script'}];

let b = new Blob(['/**README File*/'], {type: 'text/plain'});
let mockReadmeFile = new File([b], 'redme.md');

mockModal.open = sinon.stub().returns({
componentInstance: {},
result: Promise.resolve()
});

component.addReadme(mockReadmeFile);
tick();

mockModal.open.should.have.been.called;
mockAlertService.errorStatus$.next.should.not.have.been.called;
mockClientService.setBusinessNetworkReadme.should.have.been.called;
mockUpdateFiles.should.have.been.called;
mockSetCurrentFile.should.have.been.calledWith({readme: true});
}));

});

describe('openImportModal', () => {
it('should open the import modal', fakeAsync(() => {
let mockUpdatePackage = sinon.stub(component, 'updatePackageInfo');
Expand Down Expand Up @@ -793,6 +898,7 @@ describe('EditorComponent', () => {
describe('openAddFileModal', () => {
let mockAddModel;
let mockAddScript;
let mockAddReadme;

beforeEach(() => {
mockModal.open = sinon.stub().returns({
Expand All @@ -808,6 +914,7 @@ describe('EditorComponent', () => {

mockAddModel = sinon.stub(component, 'addModelFile');
mockAddScript = sinon.stub(component, 'addScriptFile');
mockAddReadme = sinon.stub(component, 'addReadme');
});

it('should open add file modal', fakeAsync(() => {
Expand All @@ -819,7 +926,23 @@ describe('EditorComponent', () => {
mockAddModel.should.have.been.called;
}));

it('should open add file script', fakeAsync(() => {
it('should open AddFileComponent modal and call addModelFile if model returned', fakeAsync(() => {
mockModal.open = sinon.stub().returns({
componentInstance: {
businessNetwork: {}
},
result: Promise.resolve(mockModelFile)
});

component.openAddFileModal();

tick();

mockAddModel.should.have.been.called;
mockClientService.businessNetworkChanged$.next.should.have.been.calledWith(true);
}));

it('should open AddFileComponent modal and call addScriptFile if script returned', fakeAsync(() => {
mockModal.open = sinon.stub().returns({
componentInstance: {
businessNetwork: {}
Expand All @@ -835,6 +958,22 @@ describe('EditorComponent', () => {
mockClientService.businessNetworkChanged$.next.should.have.been.calledWith(true);
}));

it('should open AddFileComponent modal and call addreadme if README returned', fakeAsync(() => {
mockModal.open = sinon.stub().returns({
componentInstance: {
businessNetwork: {}
},
result: Promise.resolve({})
});

component.openAddFileModal();

tick();

mockAddReadme.should.have.been.called;
mockClientService.businessNetworkChanged$.next.should.have.been.calledWith(true);
}));

it('should do nothing if no result', fakeAsync(() => {
mockAddScript.reset;
mockAddModel.reset;
Expand Down
Loading