Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Listen Live Chunk on wqxr series #86

Merged
merged 9 commits into from
Apr 20, 2017
Merged
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
6 changes: 5 additions & 1 deletion app/channel/route.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,15 @@ export default Route.extend(PlayParamMixin, {
const listingSlug = `${inflector.pluralize(channelType)}/${params.slug}`;
set(this, 'listingSlug', listingSlug);

let listenLive = this.store.findRecord('chunk', `shows-${params.slug}-listenlive`)
.catch(() => '');

return this.store.find('django-page', listingSlug.replace(/\/*$/, '/')).then(page => {
return waitFor({
page,
channel: page.get('wnycChannel'),
user: this.get('session.data.authenticated')
user: this.get('session.data.authenticated'),
listenLive
});
})
.catch(e => retryFromServer(e, listingSlug.replace(/\/*$/, '/')));
Expand Down
4 changes: 2 additions & 2 deletions app/channel/template.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@
{{/alt-channel-layout}}
{{else}}
{{#if model.channel.hasMarquee}}
{{x-marquee model=model.channel isStaff=session.data.isStaff adminURL=adminURL}}
{{x-marquee listenLive=model.listenLive.pagecontent model=model.channel isStaff=session.data.isStaff adminURL=adminURL}}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't actually know the answer to this question, so I'm just throwing it out: would bad things happen if listenLive was '' (because the show chunk didn't exist), and you subsequently try to access an attr? Console error or...? Should there be a default chunk like shows-default-listenlive that gets used if the show chunk doesn't exist?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

excellent question; answered by the tests. I create a listen live chunk on one test only; the others do not retrieve one and seem to render fine.

This can be tested on demo as well by loading up any show that isn't Q2. Ember is fairly forgiving when it comes to accessing keys on undefined values on templates, but not so much in JS files.

{{else}}
{{channel-header model=model.channel isStaff=session.data.isStaff adminURL=adminURL}}
{{channel-header listenLive=model.listenLive.pagecontent model=model.channel isStaff=session.data.isStaff adminURL=adminURL}}
{{/if}}

<div class="l-constrained">
Expand Down
8 changes: 8 additions & 0 deletions app/chunk/adapter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import ApplicationAdapter from 'wqxr-web-client/adapters/application';

export default ApplicationAdapter.extend({
buildURL() {
let url = this._super(...arguments);
return url + '/';
}
});
3 changes: 3 additions & 0 deletions app/components/channel-header/template.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
Produced by {{producing-orgs model.producingOrganizations}}.
{{/if}}
{{airings}}
{{#if listenLive}}
{{django-page page=listenLive}}
{{/if}}
</div>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion app/components/x-marquee/template.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
<div class="marquee-gradient" style={{marqueeGradientCSS}}></div>
</div>
<div class="marquee-footer">
{{channel-header model=model isStaff=isStaff adminURL=adminURL}}
{{channel-header listenLive=listenLive model=model isStaff=isStaff adminURL=adminURL}}
</div>
4 changes: 2 additions & 2 deletions app/lib/alien-dom.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,10 @@ export function removeAlienListeners() {
// destination. This runs in the django-page model's separateScripts method as well
// as in the django-page component's didReceiveAttrs hook if an Alien DOM is present.
export function embeddedComponentSetup(root = document) {
Array.from(root.querySelectorAll('[data-ember-component]')).forEach(function (el, i) {
Array.from(root.querySelectorAll('[data-ember-component]')).forEach(function (el) {
// embedded ember components require an ID that is in sync with the
// django-page document
el.id = el.id || `ember-component-${i}`;
el.id = el.id || Ember.guidFor(el);
el.setAttribute('data-text-content', el.textContent.trim());
el.textContent = '';
});
Expand Down
1 change: 1 addition & 0 deletions mirage/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ export default function() {
this.get(`${baseUrl}/api/v3/buckets/:slug/`, 'bucket');
this.get(`${baseUrl}/api/v3/story/detail/:id`, 'story');
this.get(`${baseUrl}/api/v3/channel/\*id`, 'api-response');
this.get(`${baseUrl}/api/v3/chunks/:id/`, 'chunk');

/*------------------------------------------------------------
identity management (account) endpoints
Expand Down
6 changes: 6 additions & 0 deletions mirage/factories/chunk.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { Factory, faker } from 'ember-cli-mirage';

export default Factory.extend({
slug: () => faker.lorem.words(2).join('-'),
content: faker.lorem.sentence
});
4 changes: 4 additions & 0 deletions mirage/models/chunk.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { Model } from 'ember-cli-mirage';

export default Model.extend({
});
20 changes: 20 additions & 0 deletions tests/acceptance/viewing-show-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,26 @@ test('show pages with a play param', function(assert) {

});

test('show pages with a listen live chunk', function(assert) {
let show = server.create('show', {
id: 'shows/foo/'
});
server.create('api-response', { id: 'shows/foo/recent_stories/1' });

server.create('chunk', {
id: 'shows-foo-listenlive',
content: 'foo bar text'
});
server.create('django-page', {id: show.id});
djangoPage
.bootstrap(show)
.visit(show);

andThen(() => {
assert.equal(find('.channel-header .django-content').text().trim(), 'foo bar text');
});
});

moduleForAcceptance('Acceptance | Django Page | Show Page Analytics');

test('metrics properly reports channel attrs', function(assert) {
Expand Down
12 changes: 12 additions & 0 deletions tests/unit/chunk/adapter-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { moduleFor, test } from 'ember-qunit';

moduleFor('adapter:chunk', 'Unit | Adapter | chunk', {
// Specify the other units that are required for this test.
// needs: ['serializer:foo']
});

// Replace this with your real tests.
test('it exists', function(assert) {
let adapter = this.subject();
assert.ok(adapter);
});
12 changes: 12 additions & 0 deletions tests/unit/chunk/model-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { moduleForModel, test } from 'ember-qunit';

moduleForModel('chunk', 'Unit | Model | chunk', {
// Specify the other units that are required for this test.
needs: []
});

test('it exists', function(assert) {
let model = this.subject();
// let store = this.store();
assert.ok(!!model);
});
15 changes: 15 additions & 0 deletions tests/unit/chunk/serializer-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { moduleForModel, test } from 'ember-qunit';

moduleForModel('chunk', 'Unit | Serializer | chunk', {
// Specify the other units that are required for this test.
needs: ['serializer:chunk']
});

// Replace this with your real tests.
test('it serializes records', function(assert) {
let record = this.subject();

let serializedRecord = record.serialize();

assert.ok(serializedRecord);
});