Skip to content
This repository has been archived by the owner on Feb 7, 2019. It is now read-only.

Commit

Permalink
Breaking: Changes for mulesoft/api-console#535
Browse files Browse the repository at this point in the history
  • Loading branch information
jarrodek committed Oct 25, 2017
1 parent a42bea0 commit 6c038f9
Show file tree
Hide file tree
Showing 6 changed files with 147 additions and 70 deletions.
4 changes: 2 additions & 2 deletions bower.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "raml-request-panel",
"description": "The request panel view for the request defined as a RAML method",
"version": "0.2.3",
"version": "0.3.0",
"authors": [
"The Advanced REST client authors <arc@mulesoft.com>"
],
Expand Down Expand Up @@ -74,4 +74,4 @@
"test",
"tasks"
]
}
}
21 changes: 20 additions & 1 deletion demo/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,16 @@
<h1>The raml-request-panel element</h1>
<div main>
<template is="dom-if" if="[[isMethod]]" restamp="true">
<div class="env-selector">
<label>Manually change base URI</label>
<select value="{{envUri::input}}">
<option value="">RAML base uri</option>
<option value="http://api.domain.com/{contextPath}/{contextSubPath}">http://api.domain.com/{contextPath}/{contextSubPath}</option>
<option value="api.domain.com/path/">api.domain.com/path/</option>
</select>
</div>
<div class="demo-area">
<raml-request-panel method="[[selected]]" narrow="[[narrow]]" response="{{response}}" response-error="{{responseError}}" redirect-url="[[redirectUrl]]" loading-time="{{loadingTime}}" no-url-editor="[[noUrl]]"></raml-request-panel>
<raml-request-panel method="[[selected]]" narrow="[[narrow]]" response="{{response}}" response-error="{{responseError}}" redirect-url="[[redirectUrl]]" loading-time="{{loadingTime}}" no-url-editor="[[noUrl]]" base-uri="[[baseUri]]"></raml-request-panel>
</div>
<template is="dom-if" if="[[response.ok]]">
<p>Request succeeded</p>
Expand All @@ -101,6 +109,17 @@ <h1>The raml-request-panel element</h1>
</template>
<script>
(function(app) {
app.observers = [
'_envUriChanged(envUri)'
];
app._envUriChanged = function(envUri) {
if (envUri) {
app.baseUri = envUri;
} else {
app.baseUri = undefined;
}
};

var path = location.pathname;
if (~path.indexOf('.html')) {
path = path.substr(0, path.lastIndexOf('/') + 1);
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "raml-request-panel",
"version": "0.2.3",
"version": "0.3.0",
"license": "Apache-2.0 OR CC-BY-4.0",
"description": "The request panel view for the request defined as a RAML method",
"devDependencies": {
Expand Down
51 changes: 46 additions & 5 deletions raml-request-panel.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
<link rel="import" href="../paper-dialog-scrollable/paper-dialog-scrollable.html">
<link rel="import" href="../paper-dialog/paper-dialog.html">
<link rel="import" href="../paper-toast/paper-toast.html">
<link rel="import" href="../raml-request-parameters-editor/raml-request-parameters-model.html">
<link rel="import" href="raml-request-panel-simple-xhr.html">
<!--
The request panel view for the request defined as a RAML method.
Expand Down Expand Up @@ -310,7 +311,7 @@
paper-spinner {
margin-right: 8px;
}

paper-dialog {
@apply(--raml-request-panel-popup);
}
Expand All @@ -327,9 +328,11 @@
}
</style>
<iron-media-query query="(max-width: [[narrowWidth]])" query-matches="{{narrow}}"></iron-media-query>
<raml-request-parameters-model query-parameters="[[method.queryParameters]]" uri-parameters="[[method.allUriParameters]]" query-model="{{queryModel}}" uri-model="{{uriModel}}" has-query-parameters="{{hasQueryParameters}}" has-uri-parameters="{{hasUriParameters}}" has-parameters="{{hasParameters}}"></raml-request-parameters-model>

<div class="content">
<div class="url-editor" hidden$="[[noUrlEditor]]">
<raml-request-url-editor auto-validate required uri-parameters="[[method.allUriParameters]]" url="[[method.absoluteUri]]" value="{{url}}" invalid="{{urlInvalid}}" base-uri="[[baseUri]]"></raml-request-url-editor>
<raml-request-url-editor auto-validate required value="{{url}}" invalid="{{urlInvalid}}" base-uri="[[_baseUri]]" endpoint-uri="[[method.relativeUri]]" query-model="[[queryModel]]" uri-model="[[uriModel]]"></raml-request-url-editor>
</div>
<paper-tabs selected="{{selectedTab}}">
<paper-tab hidden$="[[!authRequired]]">
Expand All @@ -342,7 +345,7 @@
</paper-tabs>
<iron-pages selected="{{selectedTab}}">
<authorization-panel hidden$="[[!authRequired]]" secured-by="[[method.securedBy]]" redirect-url="[[redirectUrl]]" is-required="{{authRequired}}"></authorization-panel>
<raml-request-parameters-editor query-parameters="[[method.queryParameters]]" uri-parameters="[[method.allUriParameters]]" url="[[method.absoluteUri]]" value="{{url}}"></raml-request-parameters-editor>
<raml-request-parameters-editor query-model="[[queryModel]]" uri-model="[[uriModel]]" has-query-parameters="[[hasQueryParameters]]" has-uri-parameters="[[hasUriParameters]]" has-parameters="[[hasParameters]]"></raml-request-parameters-editor>
<raml-request-headers-editor narrow="[[narrow]]" raml-headers="[[method.headers]]" content-type="{{contentType}}" is-payload="[[isPayloadRequest]]" value="{{headers}}"></raml-request-headers-editor>
<raml-body-editor-panel narrow="[[narrow]]" body="[[method.body]]" hidden$="[[!isPayloadRequest]]" content-type="{{contentType}}" value="{{payload}}"></raml-body-editor-panel>
</iron-pages>
Expand Down Expand Up @@ -575,13 +578,29 @@ <h2>Authorization</h2>
* is passed to the URL editor that prefixes the URL with `baseUri` value
* if passed URL is a relative URL.
*/
baseUri: String
baseUri: {
type: String,
observer: '_baseUriChanged'
},
// Computed baseUri value passed to the URL editor.
_baseUri: String,
// Computed model for query parameters
queryModel: Object,
// Computed model for URI parameters
uriModel: Object,
// Computed value from the parameters model
hasUriParameters: Boolean,
// Computed value from the parameters model
hasQueryParameters: Boolean,
// Computed value from the parameters model
hasParameters: Boolean
},

observers: [
'_isPayloadRequestChanged(isPayloadRequest)',
'_authRequiredChanged(authRequired)',
'_selectedTabChanged(selectedTab)'
'_selectedTabChanged(selectedTab)',
'_methodBaseUriChanged(method.baseUri)'
],

listeners: {
Expand Down Expand Up @@ -799,6 +818,28 @@ <h2>Authorization</h2>
if (selectedTab === 3) {
this.$$('raml-body-editor-panel').notifyResize();
}
},
/**
* Sets the `_baseUri` property to the RAML method `baseUri` only if
* `baseUri` property is not set.
*
* @param {String} methodBaseUri RAML method base URI.
*/
_methodBaseUriChanged: function(methodBaseUri) {
if (this.baseUri) {
return;
}
this._baseUri = methodBaseUri;
},

_baseUriChanged: function(value) {
if (!value) {
if (this.method) {
this._baseUri = this.method.baseUri;
}
} else {
this._baseUri = value;
}
}
});
</script>
Expand Down
120 changes: 59 additions & 61 deletions test/basic-test.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
<script src="../../web-component-tester/browser.js"></script>
<script src="../../iron-test-helpers/test-helpers.js"></script>
<script src="../../iron-test-helpers/mock-interactions.js"></script>
<script src="helper.js"></script>
<link rel="import" href="../../fetch-polyfill/fetch-polyfill.html">
<link rel="import" href="../../raml-js-parser/raml-js-parser.html">
<link rel="import" href="../../raml-json-enhance/raml-json-enhance.html">
Expand All @@ -40,34 +41,64 @@
</template>
</test-fixture>
<script>
/* global fixture, assert, TestHelpers, sinon */
suite('get-method', function() {
/* global fixture, assert, TestHelpers, sinon, RamlRequestTestHelper */

suite('basic', function() {
var element;
var method1;
var method2;

suiteSetup(function() {
this.timeout(120000);
return RamlRequestTestHelper.getTestRaml('test.raml')
.then(function(raml) {
method1 = raml.resources[0].methods[0];
method2 = raml.resources[1].methods[0];
});
});

setup(function() {
element = fixture('basic');
element.method = method1;
TestHelpers.forceXIfStamp(element);
});

test('_baseUri is computed from selected method', function() {
assert.equal(element._baseUri, method1.baseUri);
});

test('Setting "baseUri" overrides method "baseUri"', function() {
var uri = 'http://test.com/path';
element.baseUri = uri;
assert.equal(element._baseUri, uri);
});

test('Reseting method will not change _baseUri', function() {
var uri = 'http://test.com/path';
element.baseUri = uri;
element.method = method2;
assert.equal(element._baseUri, uri);
});

test('Clearing "baseUri resets original base uri"', function() {
var uri = 'http://test.com/path';
element.baseUri = uri;
element.method = method2;
element.baseUri = undefined;
assert.equal(element._baseUri, method2.baseUri);
});
});

suite('get-method', function() {
var element;
var raml;
var method;

suiteSetup(function(done) {
this.timeout(30000);
var baseUrl = location.href.substr(0, location.href.lastIndexOf('/') + 1);
var parser = fixture('parser');
var enhancer = fixture('enhancer');
enhancer.addEventListener('raml-json-enhance-ready', function(e) {
raml = e.detail.json;
suiteSetup(function() {
this.timeout(120000);
return RamlRequestTestHelper.getTestRaml('test.raml')
.then(function(raml) {
method = raml.resources[0].methods[0];
done();
});
enhancer.addEventListener('error', function(e) {
e = new Error(e.message || 'Unknown error');
done(e);
});
parser.loadApi(baseUrl + 'test.raml')
.then(function(data) {
enhancer.json = data.json.specification;
})
.catch(function(e) {
done(new Error('Parser error: ' + (e.message || 'Some error happened...')));
});
});

setup(function() {
Expand Down Expand Up @@ -130,32 +161,15 @@
});

suite('post-method', function() {

var element;
var raml;
var method;

suiteSetup(function(done) {
suiteSetup(function() {
this.timeout(30000);
var baseUrl = location.href.substr(0, location.href.lastIndexOf('/') + 1);
var parser = fixture('parser');
var enhancer = fixture('enhancer');
enhancer.addEventListener('raml-json-enhance-ready', function(e) {
raml = e.detail.json;
return RamlRequestTestHelper.getTestRaml('test.raml')
.then(function(raml) {
method = raml.resources[0].methods[1];
done();
});
enhancer.addEventListener('error', function(e) {
e = new Error(e.message || 'Unknown error');
done(e);
});
parser.loadApi(baseUrl + 'test.raml')
.then(function(data) {
enhancer.json = data.json.specification;
})
.catch(function(e) {
done(new Error('Parser error: ' + (e.message || 'Some error happened...')));
});
});

setup(function() {
Expand Down Expand Up @@ -188,30 +202,14 @@
suite('with authorization', function() {

var element;
var raml;
var method;

suiteSetup(function(done) {
suiteSetup(function() {
this.timeout(30000);
var baseUrl = location.href.substr(0, location.href.lastIndexOf('/') + 1);
var parser = fixture('parser');
var enhancer = fixture('enhancer');
enhancer.addEventListener('raml-json-enhance-ready', function(e) {
raml = e.detail.json;
return RamlRequestTestHelper.getTestRaml('test.raml')
.then(function(raml) {
method = raml.resources[1].methods[0];
done();
});
enhancer.addEventListener('error', function(e) {
e = new Error(e.message || 'Unknown error');
done(e);
});
parser.loadApi(baseUrl + 'test.raml')
.then(function(data) {
enhancer.json = data.json.specification;
})
.catch(function(e) {
done(new Error('Parser error: ' + (e.message || 'Some error happened...')));
});
});

setup(function() {
Expand Down
19 changes: 19 additions & 0 deletions test/helper.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/* global Promise, fixture */
var RamlRequestTestHelper = {};
RamlRequestTestHelper.getTestRaml = function(file) {
return new Promise(function(resolve, reject) {
var baseUrl = location.href.substr(0, location.href.lastIndexOf('/') + 1);
var parser = fixture('parser');
var enhancer = fixture('enhancer');
enhancer.addEventListener('raml-json-enhance-ready', function(e) {
resolve(e.detail.json);
});
parser.loadApi(baseUrl + file)
.then(function(data) {
enhancer.json = data.json.specification;
})
.catch(function(e) {
reject(new Error('Parser error: ' + (e.message || 'Some error happened...')));
});
});
};

0 comments on commit 6c038f9

Please sign in to comment.