Skip to content

Commit

Permalink
Fixing extension banner behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
jarrodek committed Jan 12, 2019
1 parent ff5f7ba commit 09cfb85
Show file tree
Hide file tree
Showing 9 changed files with 379 additions and 223 deletions.
478 changes: 262 additions & 216 deletions analysis.json

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions api-console.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ declare namespace MulesoftApps {
* When set the extension banner is rendered.
*/
readonly extensionBannerActive: boolean|null|undefined;
_hasApicCorsExtension: boolean|null|undefined;

/**
* Forces the console to send headers defined in this string overriding
Expand Down Expand Up @@ -473,6 +474,7 @@ declare namespace MulesoftApps {
* @param value Current value of `noExtensionBanner` property
*/
_noExtBannerChanged(value: Boolean|null): void;
_hasCorsExtensionChanged(value: any): void;

/**
* Computes value of `isMethod` proiperty.
Expand Down
10 changes: 8 additions & 2 deletions api-console.html
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ <h1 class="method-title">[[methodName]]</h1>
<raml-aware raml="{{amfModel}}" scope="[[aware]]"></raml-aware>
</template>
<paper-toast class="error-toast" id="apiLoadErrorToast"></paper-toast>
<api-console-ext-comm has-extension="{{noExtensionBanner}}"></api-console-ext-comm>
<api-console-ext-comm has-extension="{{_hasApicCorsExtension}}"></api-console-ext-comm>
<!--
The components below are optional dependencies. They will not be used until
sources of the components are included into AC bundle.
Expand Down Expand Up @@ -454,6 +454,7 @@ <h1 class="method-title">[[methodName]]</h1>
type: Boolean,
readOnly: true
},
_hasApicCorsExtension: {type: Boolean, observer: '_hasCorsExtensionChanged'},
/**
* Forces the console to send headers defined in this string overriding
* any used defined header.
Expand Down Expand Up @@ -816,7 +817,7 @@ <h1 class="method-title">[[methodName]]</h1>
return;
}
setTimeout(() => {
if (!this.noExtensionBanner) {
if (!this.noExtensionBanner && !this._hasApicCorsExtension) {
this._setExtensionBannerActive(true);
}
});
Expand Down Expand Up @@ -890,6 +891,11 @@ <h1 class="method-title">[[methodName]]</h1>
this._setExtensionBannerActive(false);
}
}
_hasCorsExtensionChanged(value) {
if (value && this.extensionBannerActive) {
this._setExtensionBannerActive(false);
}
}
/**
* Computes value of `isMethod` proiperty.
* @param {String} selectedShapeType Current value of `selectedShapeType`
Expand Down
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"Pawel Psztyc",
"The Advanced REST client authors <arc@mulesoft.com>"
],
"version": "5.0.0-rc.1",
"version": "5.0.0-rc.2",
"keywords": [
"web-components",
"polymer",
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "api-console",
"version": "5.0.0-rc.1",
"version": "5.0.0-rc.2",
"license": "CPAL-1.0",
"description": "The API console used in RAML platform.",
"devDependencies": {
Expand Down
4 changes: 2 additions & 2 deletions test/basic-test.html
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@
assert.isTrue(element.isDocs);
});

test('noExtensionBanner is false by default', function() {
assert.isFalse(element.noExtensionBanner);
test('noExtensionBanner is not set by default', function() {
assert.isUndefined(element.noExtensionBanner);
});

test('extensionBannerActive is not initally set', function() {
Expand Down
101 changes: 101 additions & 0 deletions test/cors-extension-banner-test.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, minimum-scale=1.0, initial-scale=1.0, user-scalable=yes">
<script src="../../webcomponentsjs/webcomponents-loader.js"></script>
<script src="../../web-component-tester/browser.js"></script>
<link rel="import" href="../../raml-aware/raml-aware.html">
<link rel="import" href="../../arc-polyfills/arc-polyfills.html">
<link rel="import" href="../api-console.html">
<script src="amf-loader.js"></script>
</head>
<body>

<test-fixture id="Basic">
<template>
<api-console></api-console>
</template>
</test-fixture>

<test-fixture id="NoExtension">
<template>
<api-console no-extension-banner></api-console>
</template>
</test-fixture>

<script>
suite('Declarative use', () => {
test('extensionBannerActive is eventually set', (done) => {
const element = fixture('NoExtension');
element.page = 'request';
flush(() => {
assert.isUndefined(element.extensionBannerActive);
done();
});
});

test('The extension banner is not visible', (done) => {
const element = fixture('NoExtension');
element.page = 'request';
flush(() => {
const node = element.shadowRoot.querySelector('.extension-banner');
const result = getComputedStyle(node).display.trim();
assert.equal(result, 'none');
done();
});
});
});

suite('Banner flow', () => {
let element;
setup(() => {
element = fixture('Basic');
element.page = 'request';
});

test('extensionBannerActive is set', (done) => {
if (!element.isChrome) {
done();
return;
}
flush(() => {
assert.isTrue(element.extensionBannerActive);
done();
});
});

test('Renders extension banner', (done) => {
if (!element.isChrome) {
done();
return;
}
flush(() => {
const node = element.shadowRoot.querySelector('.extension-banner');
const result = getComputedStyle(node).display.trim();
assert.notEqual(result, 'none');
done();
});
});

test('The banner is hidden when extension is detected', (done) => {
if (!element.isChrome) {
done();
return;
}
window.postMessage({
'api-console-payload': 'init',
'api-console-extension': true
}, location.origin);
flush(() => {
assert.isUndefined(element.extensionBannerActive);
const node = element.shadowRoot.querySelector('.extension-banner');
const result = getComputedStyle(node).display.trim();
assert.equal(result, 'none');
done();
});
});
});
</script>
</body>
</html>
1 change: 1 addition & 0 deletions test/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
'raml-aware-test.html',
'amf-computations-test.html',
'attribution-test.html',
'cors-extension-banner-test.html',
'integration-test.html'
]);
</script>
Expand Down

0 comments on commit 09cfb85

Please sign in to comment.