Skip to content

Commit

Permalink
Merge pull request #1553 from code-corps/add-popular-skills
Browse files Browse the repository at this point in the history
Add popular skills
  • Loading branch information
joshsmith committed Nov 26, 2017
2 parents f3b4ce1 + 4fbda2d commit 64a656c
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 8 deletions.
15 changes: 11 additions & 4 deletions app/controllers/start/skills.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { alias } from '@ember/object/computed';
import { alias, mapBy } from '@ember/object/computed';
import Controller from '@ember/controller';
import { get } from '@ember/object';
import { computed, get, getProperties } from '@ember/object';
import { inject as service } from '@ember/service';
import OnboardingControllerMixin from '../../mixins/onboarding-controller';

Expand All @@ -9,7 +9,7 @@ export default Controller.extend(OnboardingControllerMixin, {
store: service(),
userSkillsList: service(),

user: alias('model'),
skills: mapBy('userSkills', 'skill'),
userSkills: alias('user.userSkills'),

removeUserSkill(userSkill) {
Expand All @@ -18,5 +18,12 @@ export default Controller.extend(OnboardingControllerMixin, {

selectSkill(skill) {
return get(this, 'userSkillsList').toggle(skill);
}
},

selectablePopularSkills: computed('popularSkills.@each', 'skills.@each', function() {
let { popularSkills, skills } = getProperties(this, 'popularSkills', 'skills');
return popularSkills.filter((skill) => {
return !skills || !skills.isAny('id', get(skill, 'id'));
});
})
});
9 changes: 8 additions & 1 deletion app/routes/start/skills.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@ export default Route.extend({
userSkillsList: service(),

model() {
return get(this, 'currentUser.user');
let user = get(this, 'currentUser.user');
let popularSkills = this.store.query('skill', { limit: 20, popular: true });
return { popularSkills, user };
},

setupController(controller, { popularSkills, user }) {
controller.set('popularSkills', popularSkills);
controller.set('user', user);
}
});
7 changes: 7 additions & 0 deletions app/styles/templates/start/skills.scss
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@
.skills__list {
text-align: center;

&--main {
align-items: center;
display: flex;
justify-content: center;
min-height: 56px;
}

button {
margin: 0 5px 5px 0;
}
Expand Down
13 changes: 12 additions & 1 deletion app/templates/start/skills.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
</div>

<div class="start__skills">
<div class="skills__list">
<div data-test-user-skills-list class="skills__list skills__list--main">
{{#each userSkills as |userSkill|}}
{{skill-button
hasCheck=true
Expand All @@ -25,6 +25,17 @@
skillsList=userSkillsList
}}
</div>

{{#if selectablePopularSkills}}
<div data-test-popular-skills-list class="skills__list">
<p>Or choose from some popular skills:</p>
{{#each selectablePopularSkills as |skill|}}
<button class="clear" {{action selectSkill skill}}>
{{skill.title}}
</button>
{{/each}}
</div>
{{/if}}
</div>

<div class="start__footer">
Expand Down
8 changes: 7 additions & 1 deletion tests/acceptance/onboarding-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ test('A user can onboard as expected', function(assert) {
server.create('skill', {
title: 'Ruby'
});
server.create('skill', {
title: 'CSS'
});

authenticateSession(this.application, { user_id: user.id });

Expand Down Expand Up @@ -113,7 +116,8 @@ test('A user can onboard as expected', function(assert) {
});

andThen(() => {
assert.equal(onboardingPage.userSkillsList().count, 0);
assert.equal(onboardingPage.userSkillsList().count, 0, 'No skills have been added yet');
assert.equal(onboardingPage.popularSkillsList().count, 2, 'Popular skills are listed');
onboardingPage.skillsTypeahead.searchFor('r');
});

Expand All @@ -123,6 +127,8 @@ test('A user can onboard as expected', function(assert) {
});

andThen(() => {
assert.equal(onboardingPage.userSkillsList().count, 1, 'A user skill was added');
assert.equal(onboardingPage.popularSkillsList().count, 1, 'The popular skills were updated');
onboardingPage.startFooterButton.click();
});

Expand Down
11 changes: 10 additions & 1 deletion tests/pages/onboarding.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,15 @@ export default create({
}
},

popularSkillsList: collection({
scope: '[data-test-popular-skills-list]',
itemScope: 'button',
item: {
text: text(),
click: clickable()
}
}),

roleColumns: collection({
itemScope: '.expertise__column',

Expand All @@ -81,7 +90,7 @@ export default create({
}),

userSkillsList: collection({
scope: '.skills__list',
scope: '[data-test-user-skills-list]',
itemScope: 'button',
item: {
text: text(),
Expand Down

0 comments on commit 64a656c

Please sign in to comment.