guidence fix
This commit is contained in:
77
src/features/store-admin/setupProgress.test.ts
Normal file
77
src/features/store-admin/setupProgress.test.ts
Normal file
@@ -0,0 +1,77 @@
|
||||
/**
|
||||
* Which step a merchant is walked through, and what skipping does.
|
||||
*
|
||||
* The rule that matters: skipping moves the guidance on, it never marks work
|
||||
* done. A shop whose catalogue is unpriced does not start selling because
|
||||
* somebody pressed "Skip for now", and a card that implied otherwise would be
|
||||
* worse than no card.
|
||||
*/
|
||||
import assert from 'node:assert/strict';
|
||||
import { test, beforeEach } from 'node:test';
|
||||
import { focusStep, isPaused } from './setupProgress';
|
||||
import type { SetupStep, SetupStepId } from './setupSteps';
|
||||
|
||||
const step = (id: SetupStepId, done: boolean): SetupStep => ({
|
||||
id,
|
||||
title: id,
|
||||
todo: '',
|
||||
cta: '',
|
||||
done,
|
||||
href: '/',
|
||||
});
|
||||
|
||||
const steps = [
|
||||
step('profile', false),
|
||||
step('people', false),
|
||||
step('branch', true),
|
||||
step('products', false),
|
||||
];
|
||||
|
||||
beforeEach(() => {
|
||||
// `localStorage` does not exist under the test runner, and the module must
|
||||
// survive that — a private window and a browser refusing site data reach the
|
||||
// same code path.
|
||||
delete (globalThis as { localStorage?: unknown }).localStorage;
|
||||
});
|
||||
|
||||
test('the focus is the first step that is neither done nor skipped', () => {
|
||||
assert.equal(focusStep(steps, [])?.id, 'profile');
|
||||
assert.equal(focusStep(steps, ['profile'])?.id, 'people');
|
||||
assert.equal(focusStep(steps, ['profile', 'people'])?.id, 'products');
|
||||
});
|
||||
|
||||
// Done steps are stepped over whether or not they were skipped — 'branch' is
|
||||
// already complete and never becomes the focus.
|
||||
test('a completed step is never focused', () => {
|
||||
assert.notEqual(focusStep(steps, ['profile', 'people'])?.id, 'branch');
|
||||
});
|
||||
|
||||
test('skipping everything outstanding leaves nothing to focus', () => {
|
||||
assert.equal(focusStep(steps, ['profile', 'people', 'products']), null);
|
||||
assert.equal(isPaused(steps, ['profile', 'people', 'products']), true);
|
||||
});
|
||||
|
||||
/*
|
||||
Paused is not finished. Every outstanding step being skipped means the merchant
|
||||
waved the guidance past — the work is still undone, which is why the card shows
|
||||
a resume line rather than disappearing.
|
||||
*/
|
||||
test('paused is false while any outstanding step is unskipped', () => {
|
||||
assert.equal(isPaused(steps, ['profile']), false);
|
||||
assert.equal(isPaused(steps, []), false);
|
||||
});
|
||||
|
||||
// A shop with nothing left to do is not "paused" either — there is simply
|
||||
// nothing outstanding to have skipped.
|
||||
test('a finished shop is not reported as paused', () => {
|
||||
const finished = [step('profile', true), step('people', true)];
|
||||
assert.equal(isPaused(finished, []), false);
|
||||
assert.equal(isPaused(finished, ['profile']), false);
|
||||
});
|
||||
|
||||
// Storage the browser refuses must not take the page down, and must fail
|
||||
// towards showing the guidance rather than silently hiding it.
|
||||
test('unavailable storage reads as nothing skipped', async () => {
|
||||
const { skippedSteps } = await import('./setupProgress');
|
||||
assert.deepEqual(skippedSteps(1141), []);
|
||||
});
|
||||
Reference in New Issue
Block a user