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

Add upvote tests #30

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
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
6 changes: 3 additions & 3 deletions app/components/topic-card/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export default Ember.Component.extend({
else {
this.get('topic.upvoters').pushObject(this.get('session.currentUser'));
}
this.get('topic').save();
this.sendAction('topicUpdated', this.get('topic'));
},
chooseTalkDate(date) {
// we don't currently have a date and the meetup is today.
Expand All @@ -51,11 +51,11 @@ export default Ember.Component.extend({

this.set('showMeetupDates', false);

this.get('topic').save();
this.sendAction('topicUpdated', this.get('topic'));
},
cancelTalkBy() {
this.get('topic').setProperties({ talkBy: null, talkDate: null });
this.get('topic').save();
this.sendAction('topicUpdated', this.get('topic'));
}
}
});
3 changes: 3 additions & 0 deletions app/index/route.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ export default Ember.Route.extend({
submittedDate: new Date()
}).save();
this.set('controller.newTopic', '');
},
updateTopic(topic) {
topic.save();
}
}
});
2 changes: 1 addition & 1 deletion app/index/template.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
{{#each orderedTopics as |topic index|}}
<li>
<div class='number'>{{base-one-index index}}</div>
{{topic-card classNames='topic-card' topic=topic}}
{{topic-card classNames='topic-card' topic=topic topicUpdated='updateTopic'}}
</li>
{{/each}}
</ol>
20 changes: 19 additions & 1 deletion tests/integration/components/topic-card/component-test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { moduleForComponent, test } from 'ember-qunit';
import hbs from 'htmlbars-inline-precompile';

import Ember from 'ember';

moduleForComponent('topic-card', 'Integration | Component | topic card', {
integration: true
Expand All @@ -23,3 +23,21 @@ test('it renders', function(assert) {
assert.ok(descriptionText.indexOf('Now Test') !== -1);
assert.ok(descriptionText.indexOf('New!') !== -1);
});

test('upvoting adds a user to the upvoters list', function(assert) {
this.set('testTopic', { upvoters: Ember.A() });
this.render(hbs`{{topic-card topic=testTopic}}`);
this.$('.upvote.icon-btn').click();
assert.ok(this.$('.fa.fa-thumbs-up').length === 1);
assert.ok(this.$('.fa.fa-thumbs-o-up').length === 0);
assert.ok(this.get('testTopic.upvoters.length') === 1);
});

test('a user can remove their upvote', function(assert) {
this.set('testTopic', { upvoters: Ember.A([null]) });
this.render(hbs`{{topic-card topic=testTopic}}`);
this.$('.upvote.icon-btn').click();
assert.ok(this.$('.fa.fa-thumbs-up').length === 0);
assert.ok(this.$('.fa.fa-thumbs-o-up').length === 1);
assert.ok(this.get('testTopic.upvoters.length') === 0);
});