Skip to content
Open
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
3 changes: 1 addition & 2 deletions extensions/amp-insticator/0.1/amp-insticator.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@
/* ++++++++++ --------------- IMPORTS --------------- ++++++++++ */
import { Layout } from '../../../src/layout';
import { setStyles } from '../../../src/style';


import {removeElement} from '../../../src/dom';

/* ++++++++++ --------------- EXPORT AMP-INSTICATOR --------------- ++++++++++ */
export class AmpInsticator extends AMP.BaseElement {
Expand Down
65 changes: 57 additions & 8 deletions extensions/amp-insticator/0.1/test/test-amp-insticator.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

import '../amp-insticator';
import {AmpInsticator} from '../amp-insticator';

describes.realWin('amp-insticator', {
amp: {
Expand All @@ -23,16 +23,65 @@ describes.realWin('amp-insticator', {
}, env => {

let win;
let element;
let doc;
let ampInsticator;
let obj;
let layoutCallbackSpy;
let getRequestSpy;

beforeEach(() => {
function getAmpInsticatior() {
const ampInsticator = doc.createElement('amp-insticator');
ampInsticator.setAttribute('data-embed-id', '5bf0548f-a332-4934-9d35-c9ca9e93d4ff')
doc.body.appendChild(ampInsticator);

//Seting up spys and fakes
getRequestSpy = env.sandbox.spy(ampInsticator.implementation_, 'getRequest');

return ampInsticator.build()
.then( () => ampInsticator.layoutCallback() )
.then( () => ampInsticator );
}

beforeEach(async function() {
win = env.win;
element = win.document.createElement('amp-insticator');
win.document.body.appendChild(element);
doc = win.document;
ampInsticator = await getAmpInsticatior();
obj = ampInsticator.implementation_;
});

describe('renders', function renders(){
it('renders an iframe', function() {
expect(ampInsticator).to.not.be.undefined;
expect(ampInsticator).to.not.be.null;
const iframe = ampInsticator.querySelector('iframe');
expect(iframe).to.not.be.undefined;
expect(iframe).to.not.be.null;
});
it("appends Insticator's script to iframe", function(){
const iframe = ampInsticator.querySelector('iframe');
const scriptTagInIframe = iframe.contentWindow.document.querySelector('script');
expect(scriptTagInIframe).to.not.be.undefined;
expect(scriptTagInIframe).to.not.be.null;
expect(scriptTagInIframe.src).to.include(obj.url.embed);
});
it("appends div#app to iframe", function(){
const iframe = ampInsticator.querySelector('iframe');
const divApp = iframe.contentWindow.document.getElementById('app');
expect(divApp).to.not.be.undefined;
expect(divApp).to.not.be.null;
});
});

it('makes a request for ads data correctly', function() {
expect(getRequestSpy).to.be.calledOnce;
expect(getRequestSpy.calledWith(sinon.match(obj.url.ads), sinon.match.func)).to.be.true;
});

it('should have hello world when built', () => {
element.build();
expect(element.querySelector('div').textContent).to.equal('hello world');
it('removes iframe on unlayoutCallback()', function() {
const iframe = ampInsticator.querySelector('iframe');
expect(iframe).to.not.be.undefined;
expect(iframe).to.not.be.null;
obj.unlayoutCallback();
expect(ampInsticator.querySelector('iframe')).to.be.null;
});
});