From a9daa339534cc37175562ae348f05ae84bfb0af3 Mon Sep 17 00:00:00 2001 From: Robin Ward Date: Mon, 21 Mar 2016 14:16:05 -0400 Subject: [PATCH] Add tests to `home-logo` component --- .../templates/components/home-logo.hbs | 2 +- .../components/home-logo-test.js.es6 | 96 +++++++++++++++++++ .../javascripts/helpers/component-test.js.es6 | 4 +- 3 files changed, 100 insertions(+), 2 deletions(-) create mode 100644 test/javascripts/components/home-logo-test.js.es6 diff --git a/app/assets/javascripts/discourse/templates/components/home-logo.hbs b/app/assets/javascripts/discourse/templates/components/home-logo.hbs index b2b8f9e6db7..8cb81d9c4b9 100644 --- a/app/assets/javascripts/discourse/templates/components/home-logo.hbs +++ b/app/assets/javascripts/discourse/templates/components/home-logo.hbs @@ -1,7 +1,7 @@ {{#if showSmallLogo}} {{#if smallLogoUrl}} - + {{unbound title}} {{else}} {{/if}} diff --git a/test/javascripts/components/home-logo-test.js.es6 b/test/javascripts/components/home-logo-test.js.es6 new file mode 100644 index 00000000000..770343d4994 --- /dev/null +++ b/test/javascripts/components/home-logo-test.js.es6 @@ -0,0 +1,96 @@ +import componentTest from 'helpers/component-test'; + +moduleForComponent('home-logo', {integration: true}); + +const bigLogo = '/images/d-logo-sketch.png?test'; +const smallLogo = '/images/d-logo-sketch-small.png?test'; +const mobileLogo = '/images/d-logo-sketch.png?mobile'; +const title = "Cool Forum"; + +componentTest('basics', { + template: '{{home-logo minimized=minimized}}', + setup() { + this.siteSettings.logo_url = bigLogo; + this.siteSettings.logo_small_url= smallLogo; + this.siteSettings.title = title; + this.set('minimized', false); + }, + + test(assert) { + assert.ok(this.$('a[data-auto-route]').length === 1); + + assert.ok(this.$('img#site-logo.logo-big').length === 1); + assert.equal(this.$('#site-logo').attr('src'), bigLogo); + assert.equal(this.$('#site-logo').attr('alt'), title); + + this.set('minimized', true); + andThen(() => { + assert.ok(this.$('img.logo-small').length === 1); + assert.equal(this.$('img.logo-small').attr('src'), smallLogo); + assert.equal(this.$('img.logo-small').attr('alt'), title); + }); + } +}); + +componentTest('no logo', { + template: '{{home-logo minimized=minimized}}', + setup() { + this.siteSettings.logo_url = ''; + this.siteSettings.logo_small_url = ''; + this.siteSettings.title = title; + this.set('minimized', false); + }, + + test(assert) { + assert.ok(this.$('a[data-auto-route]').length === 1); + + assert.ok(this.$('h2#site-text-logo.text-logo').length === 1); + assert.equal(this.$('#site-text-logo').text(), title); + + this.set('minimized', true); + andThen(() => { + assert.ok(this.$('i.fa-home').length === 1); + }); + } +}); + +componentTest('mobile logo', { + template: "{{home-logo minimized=minimized}}", + setup() { + this.siteSettings.mobile_logo_url = mobileLogo; + this.siteSettings.logo_small_url= smallLogo; + this.set('minimized', true); + this.site.mobileView = true; + }, + + test(assert) { + assert.ok(this.$('img#site-logo.logo-big').length === 1); + assert.equal(this.$('#site-logo').attr('src'), mobileLogo); + + this.set('minimized', true); + andThen(() => { + assert.equal(this.$('#site-logo').attr('src'), mobileLogo); + }); + } +}); + +componentTest('mobile without logo', { + template: "{{home-logo minimized=minimized}}", + setup() { + this.set('minimized', true); + this.siteSettings.logo_url = bigLogo; + this.site.mobileView = true; + }, + + test(assert) { + assert.ok(this.$('img#site-logo.logo-big').length === 1); + assert.equal(this.$('#site-logo').attr('src'), bigLogo); + } +}); + +componentTest("changing url", { + template: '{{home-logo targetUrl="https://www.discourse.org"}}', + test(assert) { + assert.equal(this.$('a').attr('href'), 'https://www.discourse.org'); + } +}); diff --git a/test/javascripts/helpers/component-test.js.es6 b/test/javascripts/helpers/component-test.js.es6 index 652424a95f3..995fb476218 100644 --- a/test/javascripts/helpers/component-test.js.es6 +++ b/test/javascripts/helpers/component-test.js.es6 @@ -7,10 +7,12 @@ export default function(name, opts) { test(name, function(assert) { const appEvents = AppEvents.create(); + this.site = Discourse.Site.current(); + this.container.register('site-settings:main', Discourse.SiteSettings, { instantiate: false }); this.container.register('app-events:main', appEvents, { instantiate: false }); this.container.register('capabilities:main', Ember.Object); - this.container.register('site:main', Discourse.Site.current(), { instantiate: false }); + this.container.register('site:main', this.site, { instantiate: false }); this.container.injection('component', 'siteSettings', 'site-settings:main'); this.container.injection('component', 'appEvents', 'app-events:main'); this.container.injection('component', 'capabilities', 'capabilities:main');