forked from hyperledger-archives/composer
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
playground tutorial protractor test (hyperledger-archives#2871)
Signed-off-by: awjh-ibm <[email protected]>
- Loading branch information
Showing
16 changed files
with
756 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,4 +35,4 @@ | |
], | ||
"author": "Hyperledger Composer", | ||
"license": "Apache-2.0" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,33 @@ | ||
import { browser, element, by } from 'protractor'; | ||
import { ExpectedConditions } from 'protractor'; | ||
import { OperationsHelper } from '../utils/operations-helper'; | ||
|
||
export class EditorFile { | ||
|
||
static retrieveEditorCodeMirrorText() { | ||
return OperationsHelper.retriveTextFromElement(element(by.id('editor-file_CodeMirror'))); | ||
return browser.executeScript(` | ||
var editor = document.getElementsByClassName('CodeMirror')[0].CodeMirror; | ||
editor.focus(); | ||
return editor.getValue(); | ||
`) | ||
} | ||
|
||
static setEditorCodeMirrorText(value: string) { | ||
return browser.executeScript(` | ||
var editor = document.getElementsByClassName('CodeMirror')[0].CodeMirror; | ||
editor.focus(); | ||
return editor.setValue(''); | ||
`) | ||
.then(() => { | ||
return element(by.css('.CodeMirror textarea')).sendKeys(value) | ||
.then(() => { | ||
return browser.sleep(1000); // DEBOUNCE | ||
}) | ||
}); | ||
} | ||
|
||
static retrieveEditorText() { | ||
return OperationsHelper.retriveTextFromElement(element(by.css('.readme'))); | ||
return OperationsHelper.retrieveTextFromElement(element(by.css('.readme'))); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,146 @@ | ||
import { browser, element, by } from 'protractor'; | ||
import { ExpectedConditions } from 'protractor'; | ||
import { OperationsHelper } from '../utils/operations-helper'; | ||
import { Constants } from '../utils/constants'; | ||
|
||
let scrollMe = (target) => { | ||
target.scrollIntoView(true); | ||
}; | ||
|
||
export class Test { | ||
// Wait to appear | ||
static waitToAppear() { | ||
return browser.wait(ExpectedConditions.visibilityOf(element(by.css('.main-view'))), Constants.shortWait); | ||
} | ||
|
||
static retrieveHeader() { | ||
return OperationsHelper.retrieveMatchingElementsByCSS('.resource-header', 'h1', 0) | ||
.map((elm) => { browser.executeScript(scrollMe, elm); | ||
return OperationsHelper.retrieveTextFromElement(elm); }); | ||
} | ||
|
||
// Retrieve Test Side Navigation Participants | ||
static retrieveAssetTypes() { | ||
// Due to scroll bar, need to scroll element into view in order to inspect text | ||
return OperationsHelper.retrieveMatchingElementsByCSS('.side-bar-nav:nth-of-type(2)', 'h3', 0) | ||
.map((elm) => { browser.executeScript(scrollMe, elm); | ||
return OperationsHelper.retrieveTextFromElement(elm); }); | ||
} | ||
|
||
// Retrieve Test Side Navigation Participants | ||
static retrieveParticipantTypes() { | ||
// Due to scroll bar, need to scroll element into view in order to inspect text | ||
return OperationsHelper.retrieveMatchingElementsByCSS('.side-bar-nav:first-of-type', 'h3', 0) | ||
.map((elm) => { browser.executeScript(scrollMe, elm); | ||
return OperationsHelper.retrieveTextFromElement(elm); }); | ||
} | ||
|
||
static selectRegistry(type: string, name: string) { | ||
let sideBar: string; | ||
switch(type) { | ||
case 'participants': sideBar = '.side-bar-nav:first-of-type'; break; | ||
case 'assets': sideBar = '.side-bar-nav:nth-of-type(2)'; break; | ||
default: throw new Error('Invalid type'); | ||
} | ||
|
||
return OperationsHelper.retrieveMatchingElementsByCSS(sideBar, 'h3', 0) | ||
.then((elements) => { | ||
for (var i = 0; i < elements.length; i++) { | ||
let elm = elements[i]; | ||
browser.executeScript(scrollMe, elm); | ||
OperationsHelper.retrieveTextFromElement(elm) | ||
.then((text) => { | ||
if(text.toString() === name) { | ||
return OperationsHelper.click(elm) | ||
} | ||
}); | ||
} | ||
}) | ||
} | ||
|
||
// create registry item on selected registry page | ||
static createRegistryItem(item: string) { | ||
return OperationsHelper.retrieveMatchingElementsByCSS('.resource-header', '.registry', 0) | ||
.then((elm) => { | ||
return OperationsHelper.click(elm[0]); | ||
}) | ||
.then(() => { | ||
return browser.wait(ExpectedConditions.visibilityOf(element(by.css('.resource-modal'))), Constants.shortWait); | ||
}) | ||
.then(() => { | ||
return browser.executeScript(` | ||
var editor = document.getElementsByClassName('CodeMirror')[0].CodeMirror; | ||
editor.focus(); | ||
return editor.setValue(''); | ||
`) | ||
}) | ||
.then(() => { | ||
return element(by.css('.CodeMirror textarea')).sendKeys(item) | ||
}) | ||
.then(() => { | ||
return OperationsHelper.click(element(by.id('createResourceButton'))); | ||
}) | ||
} | ||
|
||
// Get the current list of ids and data from opened registry section | ||
static retrieveRegistryItem() { | ||
let idsPromise = OperationsHelper.retrieveMatchingElementsByCSS('.resource-list', '.resource-container .id', 0) | ||
.map((elm) => { | ||
browser.executeScript(scrollMe, elm); | ||
return OperationsHelper.retrieveTextFromElement(elm) | ||
}); | ||
|
||
let dataPromise = OperationsHelper.retrieveMatchingElementsByCSS('.resource-list', '.resource-container .data', 0) | ||
.map((elm) => { | ||
browser.executeScript(scrollMe, elm); | ||
return OperationsHelper.retrieveTextFromElement(elm) | ||
}); | ||
|
||
let promises = [idsPromise, dataPromise]; | ||
|
||
return Promise.all(promises) | ||
.then((values) => { | ||
let ids = values[0]; | ||
let data = values[1]; | ||
var result = ids.map(function(val, index){ | ||
return { id: val, data: data[index] }; | ||
}); | ||
return result; | ||
}) | ||
} | ||
|
||
static submitTransaction(transaction: string, type: string) { | ||
return OperationsHelper.click(element(by.className('side-button')).all(by.className('button-item')).all(by.className('primary')).first()) | ||
.then(() => { | ||
OperationsHelper.click(element(by.className('transaction-modal')).all(by.id('dropdownMenu1')).first()); | ||
}) | ||
.then(() => { | ||
OperationsHelper.retrieveMatchingElementsByCSS('.transaction-modal', '.dropdown-item', 1) | ||
.then((elements) => { | ||
for (var i = 0; i < elements.length; i++) { | ||
let elm = elements[i]; | ||
browser.executeScript(scrollMe, elm); | ||
OperationsHelper.retrieveTextFromElement(elm) | ||
.then((text) => { | ||
if(text.toString() === type) { | ||
return OperationsHelper.click(elm) | ||
} | ||
}); | ||
} | ||
}); | ||
}) | ||
.then(() => { | ||
return browser.executeScript(` | ||
var editor = document.getElementsByClassName('CodeMirror')[0].CodeMirror; | ||
editor.focus(); | ||
return editor.setValue(''); | ||
`) | ||
}) | ||
.then(() => { | ||
return element(by.css('.CodeMirror textarea')).sendKeys(transaction) | ||
}) | ||
.then(() => { | ||
return OperationsHelper.click(element(by.id('submitTransactionButton'))); | ||
}) | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
packages/composer-playground/e2e/data/files/playground-tutorial/assets/ABC
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"$class": "org.acme.mynetwork.Commodity", | ||
"tradingSymbol": "ABC", | ||
"description": "Test commodity", | ||
"mainExchange": "Euronext", | ||
"quantity": 72.297, | ||
"owner": "resource:org.acme.mynetwork.Trader#TRADER1" | ||
} |
6 changes: 6 additions & 0 deletions
6
packages/composer-playground/e2e/data/files/playground-tutorial/participants/TRADER1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"$class": "org.acme.mynetwork.Trader", | ||
"tradeId": "TRADER1", | ||
"firstName": "Jenny", | ||
"lastName": "Jones" | ||
} |
6 changes: 6 additions & 0 deletions
6
packages/composer-playground/e2e/data/files/playground-tutorial/participants/TRADER2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"$class": "org.acme.mynetwork.Trader", | ||
"tradeId": "TRADER2", | ||
"firstName": "Amy", | ||
"lastName": "Williams" | ||
} |
5 changes: 5 additions & 0 deletions
5
packages/composer-playground/e2e/data/files/playground-tutorial/transactions/ABCtoTRADER2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"$class": "org.acme.mynetwork.Trade", | ||
"commodity": "resource:org.acme.mynetwork.Commodity#ABC", | ||
"newOwner": "resource:org.acme.mynetwork.Trader#TRADER2" | ||
} |
15 changes: 15 additions & 0 deletions
15
packages/composer-playground/e2e/data/files/playground-tutorial/tutorial-acl-file.acl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
rule NetworkAdminUser { | ||
description: "Grant business network administrators full access to user resources" | ||
participant: "org.hyperledger.composer.system.NetworkAdmin" | ||
operation: ALL | ||
resource: "**" | ||
action: ALLOW | ||
} | ||
|
||
rule NetworkAdminSystem { | ||
description: "Grant business network administrators full access to system resources" | ||
participant: "org.hyperledger.composer.system.NetworkAdmin" | ||
operation: ALL | ||
resource: "org.hyperledger.composer.system.**" | ||
action: ALLOW | ||
} |
20 changes: 20 additions & 0 deletions
20
packages/composer-playground/e2e/data/files/playground-tutorial/tutorial-model-file.cto
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/** | ||
* My commodity trading network | ||
*/ | ||
namespace org.acme.mynetwork | ||
asset Commodity identified by tradingSymbol { | ||
o String tradingSymbol | ||
o String description | ||
o String mainExchange | ||
o Double quantity | ||
--> Trader owner | ||
} | ||
participant Trader identified by tradeId { | ||
o String tradeId | ||
o String firstName | ||
o String lastName | ||
} | ||
transaction Trade { | ||
--> Commodity commodity | ||
--> Trader newOwner | ||
} |
12 changes: 12 additions & 0 deletions
12
packages/composer-playground/e2e/data/files/playground-tutorial/tutorial-script-file.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
/** | ||
* Track the trade of a commodity from one trader to another | ||
* @param {org.acme.mynetwork.Trade} trade - the trade to be processed | ||
* @transaction | ||
*/ | ||
function tradeCommodity(trade) { | ||
trade.commodity.owner = trade.newOwner; | ||
return getAssetRegistry('org.acme.mynetwork.Commodity') | ||
.then(function (assetRegistry) { | ||
return assetRegistry.update(trade.commodity); | ||
}); | ||
} |
Oops, something went wrong.