Onboarding guide and initial achievements refactoring (#11536)

* add achievements to user

* add placeholder strings

* add to achievements to common script

* add onboarding achievements category

* add notifications

* more notifications

* award achievements

* wip notification panel

* add achievements icons and copy

* do not count onboarding tasks for the created task achievement

* add notes

* sprites, fixes and completion status and reward

* add onboarding panel

* add toggle

* fix toggle size

* fix tests

* fix typo

* add notification

* start adding modal

* fix remove button positionin, timeout, progress bar

* modal + fixes

* disable broken social links from level up modal

* change toggle icon color on hover

* add border bottom to onboarding guide panel

* add collapse animation

* expanded onboarding on first open

* onboarding: flip toggle colors

* onboarding: show progress bar all the time

* onboarding: fix panel closing on click

* onboarding modal: add close icon and fix padding

* wip: add migration for existing users

* fix titles in guide

* fix achievements copy

* do not award completed task achievement when direction is down

* start implementing new achievements

* start migrating client

* remove social links from achievements modals

* prevent skipping tutorial + fix achievement notification

* sync fixes

* start redesign achievement modal

* misc fixes to achievements, polish generic achievement modal and hatched pet modal

* add special badge for onboarding

* fix badge condition

* modals fixes

* hatched pet modal: add close icon

* fix badge typo

* fix justin button

* new scrolling behavior for dropdowns

* fix strings capitalization

* add common tests

* add api unit tests

* add date check

* achievements modal polishing

* typos

* add toggle for achievements categories

* typo

* fix test

* fix edit avatar modal cannot be closed

* finish migration and correct launch date

* fix migration

* migration fixes

* fix tests
This commit is contained in:
Matteo Pagliazzi
2019-12-16 17:20:47 +01:00
committed by GitHub
parent a00a8cced8
commit 8f5a0cfe79
108 changed files with 18515 additions and 17229 deletions

View File

@@ -239,6 +239,47 @@ describe('achievements', () => {
});
});
describe('unearned onboarding achievements', () => {
const user = generateUser();
const onboardingAchievs = shared
.achievements.getAchievementsForProfile(user).onboarding.achievements;
it('created task achievement exists with no count', () => {
const { createdTask } = onboardingAchievs;
expect(createdTask).to.exist;
expect(createdTask.optionalCount).to.be.undefined;
});
it('completed task achievement exists with no count', () => {
const { completedTask } = onboardingAchievs;
expect(completedTask).to.exist;
expect(completedTask.optionalCount).to.be.undefined;
});
it('hatched pet achievement exists with no count', () => {
const { hatchedPet } = onboardingAchievs;
expect(hatchedPet).to.exist;
expect(hatchedPet.optionalCount).to.be.undefined;
});
it('fed pet achievement exists with no count', () => {
const { fedPet } = onboardingAchievs;
expect(fedPet).to.exist;
expect(fedPet.optionalCount).to.be.undefined;
});
it('purchased equipment achievement exists with no count', () => {
const { purchasedEquipment } = onboardingAchievs;
expect(purchasedEquipment).to.exist;
expect(purchasedEquipment.optionalCount).to.be.undefined;
});
});
describe('earned seasonal achievements', () => {
const user = generateUser();
const quests = ['dilatory', 'stressbeast', 'burnout', 'bewilder'];

View File

@@ -0,0 +1,100 @@
import moment from 'moment';
import {
hasActiveOnboarding,
hasCompletedOnboarding,
onOnboardingComplete,
checkOnboardingStatus,
} from '../../../website/common/script/libs/onboarding';
import { generateUser } from '../../helpers/common.helper';
describe('onboarding', () => {
let user;
beforeEach(() => {
user = generateUser();
user.addNotification = sinon.spy();
// Make sure the onboarding is active
user.auth.timestamps.created = moment('2019-12-20').toDate();
});
describe('hasActiveOnboarding', () => {
// The value of BEGIN DATE is available in common/script/libs/onboarding
it('returns true if the account is created after BEGIN_DATE', () => {
expect(hasActiveOnboarding(user)).to.eql(true);
});
it('returns false if the account is created before BEGIN_DATE', () => {
user.auth.timestamps.created = moment('2019-12-01').toDate();
expect(hasActiveOnboarding(user)).to.eql(false);
});
});
describe('hasCompletedOnboarding', () => {
it('returns false if no achievement has been awarded', () => {
const result = hasCompletedOnboarding(user);
expect(result).to.eql(false);
});
it('returns false if not all achievements have been awarded', () => {
user.achievements.completedTask = true;
const result = hasCompletedOnboarding(user);
expect(result).to.eql(false);
});
it('returns true if all achievements have been awarded', () => {
user.achievements.createdTask = true;
user.achievements.completedTask = true;
user.achievements.hatchedPet = true;
user.achievements.fedPet = true;
user.achievements.purchasedEquipment = true;
const result = hasCompletedOnboarding(user);
expect(result).to.eql(true);
});
});
describe('onOnboardingComplete', () => {
it('awards prizes', () => {
const { gp } = user.stats;
onOnboardingComplete(user);
expect(user.stats.gp).to.eql(gp + 100);
});
});
describe('checkOnboardingStatus', () => {
it('does nothing if onboarding is not active', () => {
const { gp } = user.stats;
user.auth.timestamps.created = moment('2019-12-01').toDate();
checkOnboardingStatus(user);
expect(user.addNotification).to.not.be.called;
expect(user.stats.gp).to.eql(gp);
});
it('does nothing if onboarding is not complete', () => {
const { gp } = user.stats;
checkOnboardingStatus(user);
expect(user.addNotification).to.not.be.called;
expect(user.stats.gp).to.eql(gp);
});
it('awards prize and add notification when onboarding is complete', () => {
user.achievements.createdTask = true;
user.achievements.completedTask = true;
user.achievements.hatchedPet = true;
user.achievements.fedPet = true;
user.achievements.purchasedEquipment = true;
const { gp } = user.stats;
checkOnboardingStatus(user);
expect(user.addNotification).to.be.calledOnce;
expect(user.addNotification).to.be.calledWith('ONBOARDING_COMPLETE');
expect(user.stats.gp).to.eql(gp + 100);
});
});
});

View File

@@ -41,7 +41,10 @@ describe('shared.ops.buyMarketGear', () => {
},
});
user.addAchievement = sinon.spy();
sinon.stub(shared, 'randomVal');
sinon.stub(shared.onboarding, 'checkOnboardingStatus');
sinon.stub(shared.fns, 'predictableRandom');
sinon.stub(analytics, 'track');
});
@@ -49,6 +52,7 @@ describe('shared.ops.buyMarketGear', () => {
afterEach(() => {
shared.randomVal.restore();
shared.fns.predictableRandom.restore();
shared.onboarding.checkOnboardingStatus.restore();
analytics.track.restore();
});
@@ -86,6 +90,27 @@ describe('shared.ops.buyMarketGear', () => {
expect(analytics.track).to.be.calledOnce;
});
it('adds the onboarding achievement to the user and checks the onboarding status', () => {
user.stats.gp = 31;
buyGear(user, { params: { key: 'armor_warrior_1' } }, analytics);
expect(user.addAchievement).to.be.calledOnce;
expect(user.addAchievement).to.be.calledWith('purchasedEquipment');
expect(shared.onboarding.checkOnboardingStatus).to.be.calledOnce;
expect(shared.onboarding.checkOnboardingStatus).to.be.calledWith(user);
});
it('does not add the onboarding achievement to the user if it\'s already been awarded', () => {
user.stats.gp = 31;
user.achievements.purchasedEquipment = true;
buyGear(user, { params: { key: 'armor_warrior_1' } }, analytics);
expect(user.addAchievement).to.not.be.called;
});
it('deducts gold from user', () => {
user.stats.gp = 31;

View File

@@ -10,12 +10,19 @@ import {
generateUser,
} from '../../helpers/common.helper';
import errorMessage from '../../../website/common/script/libs/errorMessage';
import shared from '../../../website/common/script';
describe('shared.ops.feed', () => {
let user;
beforeEach(() => {
user = generateUser();
user.addAchievement = sinon.spy();
sinon.stub(shared.onboarding, 'checkOnboardingStatus');
});
afterEach(() => {
shared.onboarding.checkOnboardingStatus.restore();
});
context('failure conditions', () => {
@@ -223,5 +230,28 @@ describe('shared.ops.feed', () => {
expect(user.items.mounts['Wolf-Base']).to.equal(true);
expect(user.items.currentPet).to.equal('');
});
it('adds the onboarding achievement to the user and checks the onboarding status', () => {
user.items.pets['Wolf-Base'] = 5;
user.items.food.Meat = 2;
feed(user, { params: { pet: 'Wolf-Base', food: 'Meat' } });
expect(user.addAchievement).to.be.calledOnce;
expect(user.addAchievement).to.be.calledWith('fedPet');
expect(shared.onboarding.checkOnboardingStatus).to.be.calledOnce;
expect(shared.onboarding.checkOnboardingStatus).to.be.calledWith(user);
});
it('does not add the onboarding achievement to the user if it\'s already been awarded', () => {
user.items.pets['Wolf-Base'] = 5;
user.items.food.Meat = 2;
user.achievements.fedPet = true;
feed(user, { params: { pet: 'Wolf-Base', food: 'Meat' } });
expect(user.addAchievement).to.not.be.called;
});
});
});

View File

@@ -9,12 +9,19 @@ import {
generateUser,
} from '../../helpers/common.helper';
import errorMessage from '../../../website/common/script/libs/errorMessage';
import shared from '../../../website/common/script';
describe('shared.ops.hatch', () => {
let user;
beforeEach(() => {
user = generateUser();
user.addAchievement = sinon.spy();
sinon.stub(shared.onboarding, 'checkOnboardingStatus');
});
afterEach(() => {
shared.onboarding.checkOnboardingStatus.restore();
});
context('Pet Hatching', () => {
@@ -195,6 +202,30 @@ describe('shared.ops.hatch', () => {
hatch(user, { params: { egg: 'Wolf', hatchingPotion: 'Spooky' } });
expect(user.achievements.dustDevil).to.eql(true);
});
it('adds the onboarding achievement to the user and checks the onboarding status', () => {
user.items.eggs = { Wolf: 1 };
user.items.hatchingPotions = { Base: 1 };
user.items.pets = {};
hatch(user, { params: { egg: 'Wolf', hatchingPotion: 'Base' } });
expect(user.addAchievement).to.be.calledOnce;
expect(user.addAchievement).to.be.calledWith('hatchedPet');
expect(shared.onboarding.checkOnboardingStatus).to.be.calledOnce;
expect(shared.onboarding.checkOnboardingStatus).to.be.calledWith(user);
});
it('does not add the onboarding achievement to the user if it\'s already been awarded', () => {
user.items.eggs = { Wolf: 1 };
user.items.hatchingPotions = { Base: 1 };
user.items.pets = {};
user.achievements.hatchedPet = true;
hatch(user, { params: { egg: 'Wolf', hatchingPotion: 'Base' } });
expect(user.addAchievement).to.not.be.called;
});
});
});
});

View File

@@ -12,6 +12,7 @@ import {
NotAuthorized,
} from '../../../website/common/script/libs/errors';
import crit from '../../../website/common/script/fns/crit';
import shared from '../../../website/common/script';
const EPSILON = 0.0001; // negligible distance between datapoints
@@ -340,5 +341,49 @@ describe('shared.ops.scoreTask', () => {
expectClosePoints(ref.beforeUser, ref.afterUser, freshTodo, todo);
});
});
context('onboarding', () => {
beforeEach(() => {
ref.afterUser.addAchievement = sinon.spy();
sinon.stub(shared.onboarding, 'checkOnboardingStatus');
});
afterEach(() => {
shared.onboarding.checkOnboardingStatus.restore();
});
it('adds the achievement to the user and checks the onboarding status', () => {
scoreTask({ user: ref.afterUser, task: todo, direction: 'up' });
expect(ref.afterUser.addAchievement).to.be.calledOnce;
expect(ref.afterUser.addAchievement).to.be.calledWith('completedTask');
expect(shared.onboarding.checkOnboardingStatus).to.be.calledOnce;
expect(shared.onboarding.checkOnboardingStatus).to.be.calledWith(ref.afterUser);
});
it('does not add the onboarding achievement to the user if it\'s already been awarded', () => {
ref.afterUser.achievements.completedTask = true;
scoreTask({ user: ref.afterUser, task: todo, direction: 'up' });
expect(ref.afterUser.addAchievement).to.not.be.called;
});
it('does not add the onboarding achievement to the user if it\'s scored down', () => {
scoreTask({ user: ref.afterUser, task: todo, direction: 'down' });
expect(ref.afterUser.addAchievement).to.not.be.called;
});
it('does not add the onboarding achievement to the user if cron is running', () => {
scoreTask({
user: ref.afterUser,
task: todo,
direction: 'up',
cron: true,
});
expect(ref.afterUser.addAchievement).to.not.be.called;
});
});
});
});