Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
147 changes: 130 additions & 17 deletions scripts/test-whats-new.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@ import fs from 'node:fs';
import vm from 'node:vm';

// ---- The What's new dialog ------------------------------------------------------
// js/whats-new.js tells a returning user about the newest feature, once. It
// shows at startup to a signed-in account with at least one project, never over
// a build or another dialog. Show me closes it and points at the feature
// (fast mode's bolt button), Later just closes it, and closing it in any way
// saves the announcement's start date in puter.kv, under one key per user that
// a later announcement overwrites. Runs the real whats-new.js with a small
// fake jQuery, kv and FastMode, then checks the startup wiring in app.js and
// the bundle list.
// js/whats-new.js tells a returning user about recent features, one per load,
// each once. It shows at startup to a signed-in account with at least one
// project, never over a build or another dialog. Show me closes it and points
// at the feature (fast mode's bolt button), auto top-up's button opens Puter's
// billing page in a new tab, Later just closes it, and closing it in any way
// saves the announcement's start date in puter.kv, under one key per user. A
// load shows the oldest announcement newer than that, running today and for
// the account (auto top-up only for an account that buys its own credit).
// Runs the real whats-new.js with a small fake jQuery, kv, FastMode and clock,
// then checks the startup wiring in app.js and the bundle list.

let failures = 0;
function check(name, cond, detail) {
Expand All @@ -21,10 +23,22 @@ const source = read('../src/js/whats-new.js');
const tick = () => new Promise((r) => setTimeout(r, 0));

const KV_KEY = 'whats_new_seen';
const START = (source.match(/start: '(\d{4}-\d{2}-\d{2})'/) || [])[1];
check('the announcement has a YYYY-MM-DD start', !!START);
const STARTS = [...source.matchAll(/^\s*start: '(\d{4}-\d{2}-\d{2})',$/gm)].map((m) => m[1]);
const ENDS = [...source.matchAll(/^\s*end: '(\d{4}-\d{2}-\d{2})',$/gm)].map((m) => m[1]);
const IDS = [...source.matchAll(/^\s*id: '([a-z-]+)',$/gm)].map((m) => m[1]);
check('the announcements are fast mode then auto top-up', IDS.join() === 'fast-mode,auto-top-up', IDS.join());
check('each has a YYYY-MM-DD start and end, the end on or after the start',
STARTS.length === IDS.length && ENDS.length === IDS.length && STARTS.every((d, i) => ENDS[i] >= d));
check('… and each starts later than the one before (kv keeps only the start)',
STARTS.every((d, i) => i === 0 || d > STARTS[i - 1]), STARTS.join());
const START = STARTS[0];
const TOPUP = STARTS[1];
// The next day, as YYYY-MM-DD.
const dayAfter = (d) => { const t = new Date(d + 'T12:00:00'); t.setDate(t.getDate() + 1); return t.toISOString().slice(0, 10); };
// Noon on the day auto top-up went out, when both are running.
const NOW = TOPUP + 'T12:00:00';

function setup({ user = { uuid: 'u1', username: 'ann' }, paid = false, fast = true, kv = {}, kvFails = false, kvSetFails = false, otherDialog = false } = {}) {
function setup({ user = { uuid: 'u1', username: 'ann' }, paid = false, topUp = paid, fast = true, now = NOW, kv = {}, kvFails = false, kvSetFails = false, otherDialog = false } = {}) {
const calls = { kvGet: [], kvSet: [], kvDel: [], track: [], released: 0, warn: [], showMe: [] };
const kvStore = new Map(Object.entries(kv));
const overlays = [];
Expand Down Expand Up @@ -67,7 +81,9 @@ function setup({ user = { uuid: 'u1', username: 'ann' }, paid = false, fast = tr
};
const env = {
console: { ...console, warn: (...a) => calls.warn.push(a.join(' ')) },
Date, Promise, $, document,
// The clock reads now, so the tests don't depend on the day they run.
Date: class extends Date { constructor(...a) { super(...(a.length ? a : [now])); } static now() { return new Date(now).getTime(); } },
Promise, $, document,
setTimeout: (fn) => fn(),
requestAnimationFrame: (fn) => fn(),
puter: {
Expand All @@ -82,7 +98,8 @@ function setup({ user = { uuid: 'u1', username: 'ann' }, paid = false, fast = tr
};
env.window = env;
env.user = user ? { ...user } : null;
env.Branding = { isSubscribed: () => paid };
// A team seat is paid but can't buy credit (topUp false).
env.Branding = { isSubscribed: () => paid, canTopUp: () => topUp };
// Show me records whether the dialog was still up when it ran.
env.FastMode = {
SPEED: '2.5x', COST: '2x',
Expand Down Expand Up @@ -300,15 +317,111 @@ for (const junk of [1730000000000, true, { at: 1 }, '']) {
!t.kvStore.has(KV_KEY) && (await t.W.maybeShow({ hasProjects: true })) === true);
}

// --- Copy ----------------------------------------------------------------------------
// --- Auto top-up -----------------------------------------------------------------------
{
const t = setup();
const t = setup({ paid: true });
check('a paid account that missed fast mode sees fast mode first',
(await t.W.maybeShow({ hasProjects: true })) === true && /Build faster with fast mode/.test(t.shown()[0].html));
t.fire('.whats-new-later click');
await tick();
check('… and the next load, auto top-up', (await t.W.maybeShow({ hasProjects: true })) === true
&& /Keep building with auto top-up/.test(t.shown()[0].html)
&& t.calls.track.some((c) => c.name === 'Whats New Shown' && c.id === 'auto-top-up'));

const html = t.shown()[0].html;
check('its main button is a link to Puter’s billing page, opened in a new tab',
/<a class="confirm-modal-btn upgrade-primary whats-new-show" href="https:\/\/puter\.com\/#billing" target="_blank" rel="noopener noreferrer">Turn on auto top-up<\/a>/.test(html));
check('… after Later, with ✕, and no Show me',
(html.match(/<button/g) || []).length === 2 && html.indexOf('>Later<') < html.indexOf('>Turn on auto top-up<')
&& /aria-label="Close"/.test(html) && !/Show me/.test(html));
check('it says what it does and where to turn it on',
/adds credits for you when you run low/.test(html) && /Turn it on in your Puter billing settings\./.test(html));
check('the drawing is the credits card and switch, on the green panel, hidden from screen readers',
/class="whats-new-art is-credits" aria-hidden="true"/.test(html) && /class="wn-topup"/.test(html)
&& /wn-credits-bar/.test(html) && /wn-switch/.test(html) && /Topped up<\/span>/.test(html)
&& /<span>Credits used<\/span>/.test(html));

t.fire('.whats-new-show click');
await tick();
check('its button closes the dialog and points at nothing (the link opens the page)',
t.shown().length === 0 && t.calls.released === 2 && t.calls.showMe.length === 0);
check('… saves its start as seen', t.kvStore.get(KV_KEY) === TOPUP, String(t.kvStore.get(KV_KEY)));
check('… and is counted as show', t.calls.track.some((c) => c.name === 'Whats New Closed' && c.id === 'auto-top-up' && c.how === 'show'));
check('then nothing more', (await t.W.maybeShow({ hasProjects: true })) === false && t.shown().length === 0);
}
{
const t = setup({ paid: true, kv: { [KV_KEY]: START } });
check('a paid account that closed fast mode sees auto top-up', (await t.W.maybeShow({ hasProjects: true })) === true
&& /auto top-up/.test(t.shown()[0].html));
}
{
const t = setup({ kv: { [KV_KEY]: START } });
check('a free account that closed fast mode sees nothing', (await t.W.maybeShow({ hasProjects: true })) === false && t.shown().length === 0);
t.env.Branding.canTopUp = () => true;
check('… until it pays for a plan', (await t.W.maybeShow({ hasProjects: true })) === true && /auto top-up/.test(t.shown()[0].html));
}
{
const t = setup({ paid: true, topUp: false });
await t.W.maybeShow({ hasProjects: true });
check('a team seat sees fast mode', /Build faster with fast mode/.test(t.shown()[0].html));
t.fire('.whats-new-later click');
await tick();
check('… but never auto top-up, since its team buys the credit', (await t.W.maybeShow({ hasProjects: true })) === false);
}
{
const t = setup({ paid: true, fast: false });
check('fast mode off: a paid account goes straight to auto top-up',
(await t.W.maybeShow({ hasProjects: true })) === true && /auto top-up/.test(t.shown()[0].html));
}

// --- Running from start to end -------------------------------------------------------
{
const t = setup({ paid: true, kv: { [KV_KEY]: START }, now: START + 'T12:00:00' });
check('auto top-up waits for its start day', (await t.W.maybeShow({ hasProjects: true })) === false);
}
{
const fastEnd = ENDS[0];
const free = setup({ now: dayAfter(fastEnd) + 'T12:00:00' });
check('after fast mode’s end: a free account sees nothing, and kv is not asked',
(await free.W.maybeShow({ hasProjects: true })) === false && free.calls.kvGet.length === 0);
const paid = setup({ paid: true, now: dayAfter(fastEnd) + 'T12:00:00' });
check('… while a paid account that never saw fast mode gets auto top-up instead',
(await paid.W.maybeShow({ hasProjects: true })) === true && /auto top-up/.test(paid.shown()[0].html));
const last = setup({ paid: true, now: fastEnd + 'T23:00:00' });
check('fast mode still shows on its end day', (await last.W.maybeShow({ hasProjects: true })) === true
&& /fast mode/.test(last.shown()[0].html));
}
{
const t = setup({ paid: true, now: dayAfter(ENDS[1]) + 'T12:00:00' });
check('after the last end: nothing shows, and kv is not asked',
(await t.W.maybeShow({ hasProjects: true })) === false && t.calls.kvGet.length === 0);
check('… though the console still opens the newest', t.W.open() === true && /auto top-up/.test(t.shown()[0].html));
}

// --- Console ----------------------------------------------------------------------------
{
const free = setup();
check('open() on a free account shows fast mode, the newest it gets', free.W.open() === true && /fast mode/.test(free.shown()[0].html));
const free2 = setup();
check('open(\'auto-top-up\') on a free account shows nothing', free2.W.open('auto-top-up') === false && free2.shown().length === 0);
const paid = setup({ paid: true, kv: { [KV_KEY]: TOPUP } });
check('open() on a paid account shows auto top-up even after it was seen', paid.W.open() === true && /auto top-up/.test(paid.shown()[0].html));
const byId = setup({ paid: true });
check('open(\'fast-mode\') shows fast mode', byId.W.open('fast-mode') === true && /fast mode/.test(byId.shown()[0].html));
const none = setup();
check('open with an unknown id shows nothing', none.W.open('nope') === false && none.shown().length === 0);
}

// --- Copy ----------------------------------------------------------------------------
for (const [label, opts] of [['fast mode', {}], ['auto top-up', { paid: true, kv: { [KV_KEY]: START } }]]) {
const t = setup(opts);
await t.W.maybeShow({ hasProjects: true });
const html = t.shown()[0].html;
const text = html.slice(html.indexOf('whats-new-text'), html.indexOf('whats-new-art'))
.replace(/<[^>]+>/g, ' ').replace(/\s+/g, ' ');
check('the words use no em or en dashes', !/[–—]/.test(text), text);
check('… and no colon or semicolon joining sentences', !/[;:]/.test(text), text);
check(`${label}: the words use no em or en dashes`, !/[–—]/.test(text), text);
check(`… and no colon or semicolon joining sentences`, !/[;:]/.test(text), text);
check(`… nor the AI or model names`, !/the AI|Opus|Claude/.test(text), text);
}

// --- Wiring --------------------------------------------------------------------------
Expand Down
120 changes: 119 additions & 1 deletion src/css/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -6814,6 +6814,16 @@ a.upgrade-more-link:hover { background: none; color: #111; }
.whats-new-body .whats-new-note { margin: 0; font-size: 13px; color: #76767f; }
.whats-new-actions { grid-area: actions; display: flex; gap: 10px; padding: 20px 32px 32px; }
.whats-new-actions .confirm-modal-btn { flex: 1 1 0; padding: 11px 18px; }
/* The main button as a link (an announcement with an href). Its words keep
to one line, and Later gets what's left. */
.whats-new-actions a.whats-new-show {
flex-basis: auto;
display: inline-flex;
align-items: center;
justify-content: center;
white-space: nowrap;
text-decoration: none;
}
.whats-new-x {
position: absolute;
top: 14px;
Expand Down Expand Up @@ -6865,7 +6875,8 @@ a.upgrade-more-link:hover { background: none; color: #111; }
.whats-new-title { margin-top: 12px; font-size: 20px; }
.whats-new-body p { margin-bottom: 14px; }
.whats-new-art { height: 200px; margin: 18px 20px 0; border-radius: 12px; }
.whats-new-art .wn-fast { transform: scale(0.8); }
.whats-new-art .wn-fast,
.whats-new-art .wn-topup { transform: scale(0.8); }
.whats-new-actions { padding: 16px 20px 20px; }
.whats-new-x { background: #f0f0f3; color: #555; }
.whats-new-x:hover { background: #e5e5e8; }
Expand Down Expand Up @@ -6980,6 +6991,103 @@ a.upgrade-more-link:hover { background: none; color: #111; }
}
.wn-cursor > span { display: block; transform-origin: 3px 4px; animation: wn-press 0.25s ease 0.95s both; }
.wn-cursor svg { display: block; width: 20px; height: 20px; fill: #1a1a1a; stroke: #fff; filter: drop-shadow(0 2px 3px rgba(0, 0, 0, 0.25)); }

/* The auto top-up drawing, on a green panel: a credits card above and a
settings card below whose switch a cursor turns on. Then the credits used
fill the bar during a build, go red at the limit, and clear as a Topped up
chip pops. Each element's resting style is
the end state, so reduced motion shows just that. */
.whats-new-art.is-credits { background: linear-gradient(155deg, #9be3b4 0%, #1f9254 100%); }
.wn-topup { position: relative; flex: 0 0 auto; width: 304px; height: 160px; }
.wn-credits {
position: absolute;
top: 0;
right: 0;
width: 272px;
padding: 12px 14px;
box-sizing: border-box;
border-radius: 12px;
background: #fff;
box-shadow: 0 10px 30px rgba(0, 70, 30, 0.25);
}
.wn-credits-head {
display: flex;
align-items: center;
justify-content: space-between;
height: 20px;
margin-bottom: 10px;
font-size: 11px;
font-weight: 600;
color: #333;
}
.wn-credits-chip {
display: inline-flex;
align-items: center;
gap: 3px;
padding: 3px 8px 3px 6px;
border-radius: 999px;
background: #dcfce7;
color: #15803d;
font-size: 10px;
font-weight: 700;
animation: wn-pop 0.3s cubic-bezier(0.3, 1.6, 0.6, 1) 2.8s both;
}
.wn-credits-chip svg { width: 10px; height: 10px; flex: 0 0 auto; }
.wn-credits-bar { display: block; height: 10px; border-radius: 5px; background: #eef0f4; overflow: hidden; }
/* 1.3s to 2.4s it fills to red, holds, then clears by 3.3s. */
.wn-credits-bar i { display: block; width: 10%; height: 100%; border-radius: 5px; background: #22a35a; animation: wn-credits 2s ease-in-out 1.3s both; }
.wn-credits-foot { display: block; margin-top: 8px; font-size: 10.5px; color: #76767f; }
.wn-setting {
position: absolute;
left: 0;
bottom: 0;
width: 232px;
display: flex;
align-items: center;
justify-content: space-between;
gap: 10px;
padding: 12px 14px;
box-sizing: border-box;
border-radius: 14px;
background: #fff;
box-shadow: 0 14px 34px rgba(0, 70, 30, 0.3);
}
.wn-setting-text { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.wn-setting-text b { font-size: 11.5px; font-weight: 600; color: #1a1a1a; }
.wn-setting-text span { font-size: 10px; color: #76767f; }
.wn-switch {
position: relative;
flex: 0 0 auto;
width: 32px;
height: 18px;
border-radius: 9px;
background: #22a35a;
--wn-switch-off: #d4d5db;
animation: wn-switch-track 0.2s ease 1.05s both;
}
.wn-switch > i {
position: absolute;
top: 2px;
left: 2px;
width: 14px;
height: 14px;
border-radius: 50%;
background: #fff;
box-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
transform: translateX(14px);
animation: wn-switch-knob 0.2s ease 1.05s both;
}
@keyframes wn-credits {
0% { width: 40%; background: #22a35a; }
30% { background: #f5a524; }
55% { width: 100%; background: #e5484d; }
70% { width: 100%; background: #e5484d; }
/* Green as it starts to clear, not a fade from red through brown. */
72% { background: #22a35a; }
100% { width: 10%; background: #22a35a; }
}
@keyframes wn-switch-track { from { background: var(--wn-switch-off); } }
@keyframes wn-switch-knob { from { transform: none; } }
@keyframes wn-grow { from { width: 0; } }
@keyframes wn-light { from { fill: transparent; stroke: var(--wn-off); } }
@keyframes wn-ring { from { opacity: 0.9; transform: scale(0.9); } to { opacity: 0; transform: scale(1.45); } }
Expand Down Expand Up @@ -7013,6 +7121,16 @@ html[data-theme="dark"] .wn-lane.is-fast .wn-lane-bar i { background: #ff8a00; }
html[data-theme="dark"] .wn-composer-row > span { color: var(--text-muted); --wn-off: var(--text-muted); }
html[data-theme="dark"] .wn-race-chip { background: rgba(251, 191, 36, 0.14); color: #fbbf24; }
html[data-theme="dark"] .wn-composer-row > .wn-composer-send { background: #eef2f7; color: #0b1118; }
html[data-theme="dark"] .whats-new-art.is-credits { background: linear-gradient(155deg, #1c7a44 0%, #0a3a1f 100%); }
html[data-theme="dark"] .wn-credits,
html[data-theme="dark"] .wn-setting { background: var(--surface); box-shadow: 0 14px 34px rgba(0, 0, 0, 0.45); }
html[data-theme="dark"] .wn-credits-head,
html[data-theme="dark"] .wn-setting-text b { color: var(--text); }
html[data-theme="dark"] .wn-credits-foot,
html[data-theme="dark"] .wn-setting-text span { color: var(--text-muted); }
html[data-theme="dark"] .wn-credits-bar { background: var(--surface-active); }
html[data-theme="dark"] .wn-credits-chip { background: rgba(74, 222, 128, 0.14); color: #86efac; }
html[data-theme="dark"] .wn-switch { --wn-switch-off: var(--surface-active); }

/* Project Properties dialog — reuses .confirm-modal-overlay for the backdrop. */
.properties-modal {
Expand Down
4 changes: 2 additions & 2 deletions src/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -3301,8 +3301,8 @@ $(document).ready(async function(){
// seconds and reports its own outcome, and nothing below depends on it.
window.consumeTemplateDeepLink?.();

// The newest feature, once per account, for a user who has built
// something (js/whats-new.js). Not while an upgrade is pending, since its
// A recent feature, one per load and each once per account, for a user
// who has built something (js/whats-new.js). Not while an upgrade is pending, since its
// success dialog comes first. Not awaited: it waits on puter.kv, then
// checks again that no build has started, the user hasn't typed, and
// focus is still on the page or the chat box.
Expand Down
Loading
Loading