mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-18 07:07:35 +01:00
* 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
101 lines
3.1 KiB
JavaScript
101 lines
3.1 KiB
JavaScript
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);
|
|
});
|
|
});
|
|
});
|