Moved onboarding display check into new onboarding service (#19938)

refs
https://linear.app/tryghost/issue/IPC-92/add-logic-for-completing-steps

- added `onboarding` service to manage logic and state for the onboarding display and it's various steps
- added basic "display onboarding checklist" state to replicate the basic feature flag toggle along with making sure it's only shown to owners
- added acceptance test file and missing mirage endpoints needed for the dashboard to load without error
This commit is contained in:
Kevin Ansfield 2024-03-27 17:37:37 +00:00 committed by GitHub
parent 75b08a716b
commit 919ec733e7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 104 additions and 16 deletions

View File

@ -1,4 +1,4 @@
<div class="gh-onboarding-wrapper">
<div class="gh-onboarding-wrapper" data-test-dashboard="onboarding-checklist">
<div class="gh-onboarding-header">
<video width="80" height="80" loop autoplay muted playsinline preload="metadata" style="width: 80px; height: 80px; margin-bottom: 24px;">
<source src="assets/videos/logo-loader.mp4" type="video/mp4" />

View File

@ -18,10 +18,11 @@ const DAYS_OPTIONS = [{
export default class DashboardController extends Controller {
@service dashboardStats;
@service membersUtils;
@service store;
@service mentionUtils;
@service feature;
@service membersUtils;
@service mentionUtils;
@service onboarding;
@service store;
@tracked mentions = [];
@tracked hasNewMentions = false;

View File

@ -1,7 +1,7 @@
import Helper from '@ember/component/helper';
import {inject as service} from '@ember/service';
export default class EnableDeveloperExperimentsHelper extends Helper {
export default class FeatureHelper extends Helper {
@service feature;
compute([featureFlag]) {

View File

@ -0,0 +1,11 @@
import Service, {inject as service} from '@ember/service';
export default class OnboardingService extends Service {
@service feature;
@service session;
get isChecklistShown() {
return this.feature.onboardingChecklist
&& this.session.user.isOwnerOnly;
}
}

View File

@ -1,7 +1,7 @@
<section class="gh-canvas" {{scroll-top}}>
<div class="gh-dashboard">
{{#unless (feature 'onboardingChecklist')}}
<GhCanvasHeader class="gh-canvas-header sticky">
{{#unless this.onboarding.isChecklistShown}}
<GhCanvasHeader class="gh-canvas-header sticky" data-test-dashboard="header">
<h2 class="gh-canvas-title" data-test-screen-title>
Dashboard
</h2>
@ -80,13 +80,14 @@
{{/unless}}
</GhCanvasHeader>
{{/unless}}
<section class="gh-dashboard-layout">
{{#if this.isLoading }}
<GhLoadingSpinner />
{{else}}
{{#if this.areMembersEnabled}}
{{#if (feature 'onboardingChecklist')}}
{{#if this.onboarding.isChecklistShown}}
<Dashboard::OnboardingChecklist />
{{/if}}
@ -94,8 +95,8 @@
<Dashboard::Charts::Overview />
{{/if}}
{{#unless (feature 'onboardingChecklist')}}
<div class="gh-dashboard-group {{if this.isTotalMembersZero 'is-zero'}}">
{{#unless this.onboarding.isChecklistShown}}
<div class="gh-dashboard-group {{if this.isTotalMembersZero 'is-zero'}}" data-test-dashboard="attribution">
<Dashboard::Charts::AnchorAttribution />
{{#if this.hasPaidTiers}}
<section class="gh-dashboard-section">

View File

@ -63,4 +63,11 @@ export default function mockStats(server) {
}
};
});
server.get('/stats/referrers/', function () {
return {
stats: [],
meta: {}
};
});
}

View File

@ -5,6 +5,12 @@ let themeCount = 1;
export default function mockThemes(server) {
server.get('/themes');
server.get('/themes/active/', function ({themes}) {
const theme = themes.findBy({active: true});
return {themes: [theme]};
});
server.post('/themes/upload/', function ({themes}) {
// pretender/mirage doesn't currently process FormData so we can't use
// any info passed in through the request

View File

@ -0,0 +1,62 @@
import {authenticateSession} from 'ember-simple-auth/test-support';
import {currentURL, find, visit} from '@ember/test-helpers';
import {describe, it} from 'mocha';
import {enableLabsFlag} from '../helpers/labs-flag';
import {enableMembers} from '../helpers/members';
import {expect} from 'chai';
import {setupApplicationTest} from 'ember-mocha';
import {setupMirage} from 'ember-cli-mirage/test-support';
describe('Acceptance: Onboarding', function () {
const hooks = setupApplicationTest();
setupMirage(hooks);
beforeEach(async function () {
this.server.loadFixtures('configs');
this.server.loadFixtures('settings');
this.server.loadFixtures('themes');
enableLabsFlag(this.server, 'onboardingChecklist');
enableMembers(this.server);
});
describe('checklist (owner)', function () {
beforeEach(async function () {
let role = this.server.create('role', {name: 'Owner'});
this.server.create('user', {roles: [role], slug: 'owner'});
return await authenticateSession();
});
it('dashboard shows the checklist', async function () {
await visit('/dashboard');
expect(currentURL()).to.equal('/dashboard');
// main onboarding list is visible
expect(find('[data-test-dashboard="onboarding-checklist"]'), 'checklist').to.exist;
// other default dashboard elements get hidden
expect(find('[data-test-dashboard="header"]'), 'header').to.not.exist;
expect(find('[data-test-dashboard="attribution"]'), 'attribution section').to.not.exist;
});
});
describe('checklist (non-owner)', function () {
beforeEach(async function () {
let role = this.server.create('role', {name: 'Administrator'});
this.server.create('user', {roles: [role], slug: 'admin'});
return await authenticateSession();
});
it('dashboard doesn\'t show the checklist', async function () {
await visit('/dashboard');
expect(currentURL()).to.equal('/dashboard');
// onboarding isn't shown
expect(find('[data-test-dashboard="onboarding-checklist"]'), 'checklist').to.not.exist;
// other default dashboard elements are visible
expect(find('[data-test-dashboard="header"]'), 'header').to.exist;
expect(find('[data-test-dashboard="attribution"]'), 'attribution section').to.exist;
});
});
});