context('without options', function() { before(function() { const resourceLoader = new jsdom.ResourceLoader({userAgent: USER_AGENT_IPHONE_IOS9}); global.window = new JSDOM('<html></html>', { resource: resourceLoader }).window; global.document = window.document; global.getComputedStyle = global.document.defaultView.getComputedStyle; smartbanner = new SmartBanner(); }); it('expected to throw error', function() { expect(() => smartbanner.publish()).to.throw('No options detected. Please consult documentation.'); }); });
describe('apiEnabled', function() { const resourceLoader = new jsdom.ResourceLoader({ userAgent: USER_AGENT_IPHONE_IOS9 });
context('when on iPod', function() { before(function() { const resourceLoader = new jsdom.ResourceLoader({ userAgent: USER_AGENT_IPOD }); global.window = new JSDOM(HTML, { resources: resourceLoader }).window; platform = Detector.platform(); }); it('expected to return ios', function() { expect(platform).to.eql('ios'); }); it('expected exclude regex to not match', function() { expect(Detector.userAgentMatchesRegex(EXCLUDE_USER_AGENT_REGEX)).to.be.false; }); it('expected include regex to not match', function() { expect(Detector.userAgentMatchesRegex(INCLUDE_USER_AGENT_REGEX)).to.be.false; }); });
context('when has been closed within current session', function() { before(function() { const resourceLoader = new jsdom.ResourceLoader({ userAgent: USER_AGENT_ANDROID }); global.window = new JSDOM(HTML, { resources: resourceLoader }).window; global.document = window.document; global.getComputedStyle = window.getComputedStyle; global.Event = window.Event; smartbanner = new SmartBanner(); smartbanner.publish(); smartbanner.exit(); }); it('expected to not to add to body', function() { smartbanner.publish(); expect(document.querySelector('.js_smartbanner')).not.to.exist; }); });
describe('handleExitClick', function() { before(function() { const resourceLoader = new jsdom.ResourceLoader({ userAgent: USER_AGENT_IPHONE_IOS9 }); global.window = new JSDOM(HTML_API, { resources: resourceLoader }).window; global.document = window.document; global.getComputedStyle = window.getComputedStyle; smartbanner = new SmartBanner(); smartbanner.publish(); }); it('expected to handle exit', function(done) { document.addEventListener('smartbanner.exit', function () { done(); }); let clickEvent = document.createEvent("HTMLEvents"); clickEvent.initEvent("click", false, true); document.querySelector('.js_smartbanner__exit').dispatchEvent(clickEvent); }); });
context('when on iPad', function() { before(function() { const resourceLoader = new jsdom.ResourceLoader({ userAgent: USER_AGENT_IPAD }); global.window = new JSDOM(HTML_IOS, { resources: resourceLoader }).window; global.document = window.document; global.getComputedStyle = window.getComputedStyle; global.Event = window.Event; smartbanner = new SmartBanner(); }); it('expected to add iOS template to body', function() { smartbanner.publish(); let html = document.querySelector('.js_smartbanner').outerHTML; expect(html).to.eql(IOS_BODY); }); });
context('when on desktop', function() { before(function() { const resourceLoader = new jsdom.ResourceLoader({ userAgent: USER_AGENT_DESKTOP }); global.window = new JSDOM(HTML, { resources: resourceLoader }).window; global.document = window.document; global.getComputedStyle = window.getComputedStyle; global.Event = window.Event; smartbanner = new SmartBanner(); smartbanner.publish(); }); it('expected to not add anything to body', function() { expect(document.querySelector('.js_smartbanner')).to.be.null; }); });
context('when on iPhone with Custom Web App', function() { before(function() { const resourceLoader = new jsdom.ResourceLoader({ userAgent: USER_AGENT_IPHONE_CUSTOM_WEBAPP }); global.window = new JSDOM(HTML, { resources: resourceLoader }).window; platform = Detector.platform(); }); it('expected to return ios', function() { expect(platform).to.eql('ios'); }); it('expected exclude regex to match', function() { expect(Detector.userAgentMatchesRegex(EXCLUDE_USER_AGENT_REGEX)).to.be.true; }); it('expected include regex to not match', function() { expect(Detector.userAgentMatchesRegex(INCLUDE_USER_AGENT_REGEX)).to.be.true; }); });
context('when on Android with Custom Web App', function() { before(function() { const resourceLoader = new jsdom.ResourceLoader({ userAgent: USER_AGENT_ANDROID_CUSTOM_WEBAPP }); global.window = new JSDOM(HTML, { resources: resourceLoader }).window; platform = Detector.platform(); }); it('expected to return android', function() { expect(platform).to.eql('android'); }); it('expected exclude regex to match', function() { expect(Detector.userAgentMatchesRegex(EXCLUDE_USER_AGENT_REGEX)).to.be.true; }); it('expected include regex to not match', function() { expect(Detector.userAgentMatchesRegex(INCLUDE_USER_AGENT_REGEX)).to.be.false; }); });
context('when on iPhone with iOS9', function() { before(function() { const resourceLoader = new jsdom.ResourceLoader({ userAgent: USER_AGENT_IPHONE_IOS9 }); global.window = new JSDOM(HTML, { resources: resourceLoader }).window; platform = Detector.platform(); }); it('expected to return ios', function() { expect(platform).to.eql('ios'); }); it('expected exclude regex to not match', function() { expect(Detector.userAgentMatchesRegex(EXCLUDE_USER_AGENT_REGEX)).to.be.false; }); it('expected include regex to match', function() { expect(Detector.userAgentMatchesRegex(INCLUDE_USER_AGENT_REGEX)).to.be.true; }); });
context('when on iPod', function() { before(function() { const resourceLoader = new jsdom.ResourceLoader({ userAgent: USER_AGENT_IPOD }); global.window = new JSDOM(HTML_IOS, { resources: resourceLoader }).window; global.document = window.document; global.getComputedStyle = window.getComputedStyle; global.Event = window.Event; smartbanner = new SmartBanner(); }); it('expected to add iOS template to body', function() { smartbanner.publish(); let html = document.querySelector('.js_smartbanner').outerHTML; expect(html).to.eql(IOS_BODY); }); });
context('when on iPhone with iOS8', function() { before(function() { const resourceLoader = new jsdom.ResourceLoader({ userAgent: USER_AGENT_IPHONE_IOS8 }); global.window = new JSDOM(HTML, { resources: resourceLoader }).window; platform = Detector.platform(); }); it('expected to return ios', function() { expect(platform).to.eql('ios'); }); it('expected exclude regex to not match', function() { expect(Detector.userAgentMatchesRegex(EXCLUDE_USER_AGENT_REGEX)).to.be.false; }); it('expected include regex to not match', function() { expect(Detector.userAgentMatchesRegex(INCLUDE_USER_AGENT_REGEX)).to.be.false; }); });
context('when on Android', function() { before(function() { const resourceLoader = new jsdom.ResourceLoader({ userAgent: USER_AGENT_ANDROID }); global.window = new JSDOM(HTML, { resources: resourceLoader }).window; platform = Detector.platform(); }); it('expected to return android', function() { expect(platform).to.eql('android'); }); it('expected exclude regex to not match', function() { expect(Detector.userAgentMatchesRegex(EXCLUDE_USER_AGENT_REGEX)).to.be.false; }); it('expected include regex to not match', function() { expect(Detector.userAgentMatchesRegex(INCLUDE_USER_AGENT_REGEX)).to.be.false; }); });
context('when on iPad', function() { before(function() { const resourceLoader = new jsdom.ResourceLoader({ userAgent: USER_AGENT_IPAD }); global.window = new JSDOM(HTML, { resources: resourceLoader }).window; platform = Detector.platform(); }); it('expected to return ios', function() { expect(platform).to.eql('ios'); }); it('expected exclude regex to not match', function() { expect(Detector.userAgentMatchesRegex(EXCLUDE_USER_AGENT_REGEX)).to.be.false; }); it('expected include regex to not match', function() { expect(Detector.userAgentMatchesRegex(INCLUDE_USER_AGENT_REGEX)).to.be.false; }); });
describe('handleClickout', function() { before(function() { const resourceLoader = new jsdom.ResourceLoader({ userAgent: USER_AGENT_IPHONE_IOS9 }); global.window = new JSDOM(HTML_API, { resources: resourceLoader }).window; global.document = window.document; global.getComputedStyle = window.getComputedStyle; smartbanner = new SmartBanner(); smartbanner.publish(); }); it('expected to handle clickout', function(done) { document.addEventListener('smartbanner.clickout', function () { done(); }); let clickEvent = document.createEvent("HTMLEvents"); clickEvent.initEvent("click", false, true); document.querySelector('.js_smartbanner__button').dispatchEvent(clickEvent); }); });