mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-18 07:07:35 +01:00
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:
@@ -11,6 +11,7 @@ import { model as User } from '../../../../../../website/server/models/user';
|
||||
import { model as Group } from '../../../../../../website/server/models/group';
|
||||
import {
|
||||
generateGroup,
|
||||
sleep,
|
||||
} from '../../../../../helpers/api-unit.helper';
|
||||
|
||||
describe('Purchasing a group plan for group', () => {
|
||||
@@ -307,6 +308,7 @@ describe('Purchasing a group plan for group', () => {
|
||||
data.groupId = group._id;
|
||||
|
||||
await api.createSubscription(data);
|
||||
await sleep(0.5);
|
||||
|
||||
expect(sender.sendTxn).to.have.callCount(4);
|
||||
expect(sender.sendTxn.args[0][0]._id).to.equal(TECH_ASSISTANCE_EMAIL);
|
||||
@@ -340,6 +342,7 @@ describe('Purchasing a group plan for group', () => {
|
||||
data.groupId = group._id;
|
||||
|
||||
await api.createSubscription(data);
|
||||
await sleep(0.5);
|
||||
|
||||
expect(sender.sendTxn).to.have.callCount(4);
|
||||
expect(sender.sendTxn.args[0][0]._id).to.equal(TECH_ASSISTANCE_EMAIL);
|
||||
|
||||
@@ -5,6 +5,7 @@ import {
|
||||
moveTask,
|
||||
} from '../../../../website/server/libs/taskManager';
|
||||
import i18n from '../../../../website/common/script/i18n';
|
||||
import shared from '../../../../website/common/script';
|
||||
import {
|
||||
generateUser,
|
||||
generateGroup,
|
||||
@@ -58,6 +59,51 @@ describe('taskManager', () => {
|
||||
expect(newTask.createdAt).to.exist;
|
||||
});
|
||||
|
||||
describe('onboarding', () => {
|
||||
beforeEach(() => {
|
||||
user.addAchievement = sinon.spy();
|
||||
sinon.stub(shared.onboarding, 'checkOnboardingStatus');
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
shared.onboarding.checkOnboardingStatus.restore();
|
||||
});
|
||||
|
||||
it('adds the onboarding achievement to the user and checks the onboarding status', async () => {
|
||||
req.body = testHabit;
|
||||
res.t = i18n.t;
|
||||
user.flags.welcomed = true;
|
||||
|
||||
await createTasks(req, res, { user });
|
||||
|
||||
expect(user.addAchievement).to.be.calledOnce;
|
||||
expect(user.addAchievement).to.be.calledWith('createdTask');
|
||||
|
||||
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 flags.welcomed is false', async () => {
|
||||
req.body = testHabit;
|
||||
res.t = i18n.t;
|
||||
user.flags.welcomed = false;
|
||||
|
||||
await createTasks(req, res, { user });
|
||||
|
||||
expect(user.addAchievement).to.not.be.called;
|
||||
});
|
||||
|
||||
it('does not add the onboarding achievement to the user if it\'s already been awarded', async () => {
|
||||
req.body = testHabit;
|
||||
res.t = i18n.t;
|
||||
user.achievements.createdTask = true;
|
||||
|
||||
await createTasks(req, res, { user });
|
||||
|
||||
expect(user.addAchievement).to.not.be.called;
|
||||
});
|
||||
});
|
||||
|
||||
it('gets user tasks', async () => {
|
||||
req.body = testHabit;
|
||||
res.t = i18n.t;
|
||||
|
||||
@@ -1879,6 +1879,8 @@ describe('Group Model', () => {
|
||||
await questLeader.save();
|
||||
await party.finishQuest(quest);
|
||||
|
||||
await sleep(0.5);
|
||||
|
||||
const [
|
||||
updatedLeader,
|
||||
updatedParticipatingMember,
|
||||
|
||||
@@ -84,6 +84,103 @@ describe('User Model', () => {
|
||||
expect(userToJSON.stats.toNextLevel).to.equal(common.tnl(user.stats.lvl));
|
||||
});
|
||||
|
||||
context('achievements', () => {
|
||||
it('can add an achievement', () => {
|
||||
const user = new User();
|
||||
const originalUserToJSON = user.toJSON({ minimize: false });
|
||||
expect(originalUserToJSON.achievements.createdTask).to.not.eql(true);
|
||||
const notificationsN = originalUserToJSON.notifications.length;
|
||||
|
||||
user.addAchievement('createdTask');
|
||||
|
||||
const userToJSON = user.toJSON();
|
||||
expect(user.notifications.length).to.equal(notificationsN + 1);
|
||||
expect(userToJSON.notifications[0]).to.have.all.keys(['data', 'id', 'type', 'seen']);
|
||||
expect(userToJSON.notifications[0].type).to.equal('ACHIEVEMENT');
|
||||
expect(userToJSON.notifications[0].data).to.eql({
|
||||
achievement: 'createdTask',
|
||||
});
|
||||
expect(userToJSON.notifications[0].seen).to.eql(false);
|
||||
|
||||
expect(userToJSON.achievements.createdTask).to.eql(true);
|
||||
});
|
||||
|
||||
it('throws an error if the achievement is not valid', () => {
|
||||
const user = new User();
|
||||
expect(() => user.addAchievement('notAnAchievement')).to.throw;
|
||||
});
|
||||
|
||||
context('static push method', () => {
|
||||
it('throws an error if the achievement is not valid', async () => {
|
||||
const user = new User();
|
||||
await user.save();
|
||||
|
||||
await expect(User.addAchievementUpdate({ _id: user._id }, 'notAnAchievement'))
|
||||
.to.eventually.be.rejected;
|
||||
|
||||
expect(() => user.addAchievement('notAnAchievement')).to.throw;
|
||||
});
|
||||
|
||||
it('adds an achievement for a single member via static method', async () => {
|
||||
let user = new User();
|
||||
await user.save();
|
||||
|
||||
const originalUserToJSON = user.toJSON({ minimize: false });
|
||||
expect(originalUserToJSON.achievements.createdTask).to.not.eql(true);
|
||||
const notificationsN = originalUserToJSON.notifications.length;
|
||||
|
||||
await User.addAchievementUpdate({ _id: user._id }, 'createdTask');
|
||||
|
||||
user = await User.findOne({ _id: user._id }).exec();
|
||||
|
||||
const userToJSON = user.toJSON();
|
||||
expect(user.notifications.length).to.equal(notificationsN + 1);
|
||||
expect(userToJSON.notifications[0]).to.have.all.keys(['data', 'id', 'type', 'seen']);
|
||||
expect(userToJSON.notifications[0].type).to.equal('ACHIEVEMENT');
|
||||
expect(userToJSON.notifications[0].data).to.eql({
|
||||
achievement: 'createdTask',
|
||||
});
|
||||
expect(userToJSON.notifications[0].seen).to.eql(false);
|
||||
|
||||
expect(userToJSON.achievements.createdTask).to.eql(true);
|
||||
});
|
||||
|
||||
it('adds an achievement for all given users via static method', async () => {
|
||||
let user = new User();
|
||||
const otherUser = new User();
|
||||
await Promise.all([user.save(), otherUser.save()]);
|
||||
|
||||
await User.addAchievementUpdate({ _id: { $in: [user._id, otherUser._id] } }, 'createdTask');
|
||||
|
||||
user = await User.findOne({ _id: user._id }).exec();
|
||||
|
||||
let userToJSON = user.toJSON();
|
||||
expect(user.notifications.length).to.equal(1);
|
||||
expect(userToJSON.notifications[0]).to.have.all.keys(['data', 'id', 'type', 'seen']);
|
||||
expect(userToJSON.notifications[0].type).to.equal('ACHIEVEMENT');
|
||||
expect(userToJSON.notifications[0].data).to.eql({
|
||||
achievement: 'createdTask',
|
||||
});
|
||||
expect(userToJSON.notifications[0].seen).to.eql(false);
|
||||
|
||||
expect(userToJSON.achievements.createdTask).to.eql(true);
|
||||
|
||||
user = await User.findOne({ _id: otherUser._id }).exec();
|
||||
|
||||
userToJSON = user.toJSON();
|
||||
expect(user.notifications.length).to.equal(1);
|
||||
expect(userToJSON.notifications[0]).to.have.all.keys(['data', 'id', 'type', 'seen']);
|
||||
expect(userToJSON.notifications[0].type).to.equal('ACHIEVEMENT');
|
||||
expect(userToJSON.notifications[0].data).to.eql({
|
||||
achievement: 'createdTask',
|
||||
});
|
||||
expect(userToJSON.notifications[0].seen).to.eql(false);
|
||||
|
||||
expect(userToJSON.achievements.createdTask).to.eql(true);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
context('notifications', () => {
|
||||
it('can add notifications without data', () => {
|
||||
const user = new User();
|
||||
|
||||
Reference in New Issue
Block a user