mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-10-18 21:16:47 +00:00
8f6ed02cff
After an update the service worker keeps serving the previous bundle until the new one is installed. That shell announces the release layout too, so the layout alone let it draw the notice with its own older texts and use it up for the version now running with one click on X. The bundle now sends the version it was built as (client/package.json, baked in by define), and the server compares it with its own before it hands a notice with a release block over. A shell of another version is told nothing and gets the notice after the reload, from the bundle that can draw it. This holds for every update, not only the one that introduced the parameter.
76 lines
3.4 KiB
TypeScript
76 lines
3.4 KiB
TypeScript
import { describe, it, expect, beforeEach } from 'vitest';
|
|
import { http, HttpResponse } from 'msw';
|
|
import { server } from '../../helpers/msw/server';
|
|
import { useSystemNoticeStore } from '../../../src/store/systemNoticeStore';
|
|
|
|
const initial = useSystemNoticeStore.getState();
|
|
|
|
beforeEach(() => {
|
|
useSystemNoticeStore.setState(initial, true);
|
|
});
|
|
|
|
describe('systemNoticeStore', () => {
|
|
// After an update the service worker serves the previous bundle until the new one is
|
|
// installed. The server only hands the release notice to a bundle that announces it
|
|
// can draw the release layout, so an older bundle never shows it as bare keys and
|
|
// never dismisses it for good. This bundle has to announce it on every fetch.
|
|
describe('FE-SYSNOTICE-001: fetch() announces the layouts this bundle can draw', () => {
|
|
it('sends supports=release and the version this bundle was built as', async () => {
|
|
const urls: URL[] = [];
|
|
server.use(
|
|
http.get('/api/system-notices/active', ({ request }) => {
|
|
urls.push(new URL(request.url));
|
|
return HttpResponse.json([]);
|
|
}),
|
|
);
|
|
|
|
await useSystemNoticeStore.getState().fetch();
|
|
|
|
expect(urls).toHaveLength(1);
|
|
expect(urls[0].searchParams.get('supports')).toBe('release');
|
|
// The value `define` bakes in from client/package.json: the server compares it
|
|
// with its own version before it hands the release notice over.
|
|
expect(urls[0].searchParams.get('ui')).toBe(__TREK_UI_VERSION__);
|
|
expect(urls[0].searchParams.get('ui')).toMatch(/^\d+\.\d+\.\d+/);
|
|
expect(useSystemNoticeStore.getState().loaded).toBe(true);
|
|
});
|
|
|
|
it('keeps the notices the server returns, release layout included', async () => {
|
|
const release = {
|
|
id: 'release-notes', display: 'modal', severity: 'info', dismissible: true,
|
|
titleKey: 'system_notice.release_notes.headline', bodyKey: 'system_notice.release_notes.intro',
|
|
release: {
|
|
version: '4.3.0',
|
|
eyebrowKey: 'system_notice.release_notes.eyebrow',
|
|
headlineKey: 'system_notice.release_notes.headline',
|
|
introKey: 'system_notice.release_notes.intro',
|
|
featuresLabelKey: 'system_notice.release_notes.features_label',
|
|
features: [],
|
|
note: {
|
|
eyebrowKey: 'system_notice.release_notes.note_eyebrow',
|
|
titleKey: 'system_notice.release_notes.note_title',
|
|
bodyKey: 'system_notice.release_notes.note_body',
|
|
promiseLabelKey: 'system_notice.release_notes.promise_label',
|
|
promiseLeadKey: 'system_notice.release_notes.promise_lead',
|
|
promiseTextKey: 'system_notice.release_notes.promise_text',
|
|
bodyAfterKey: 'system_notice.release_notes.note_body_after',
|
|
closingKey: 'system_notice.release_notes.note_closing',
|
|
},
|
|
supportLeadKey: 'system_notice.release_notes.support_lead',
|
|
supportTextKey: 'system_notice.release_notes.support_text',
|
|
},
|
|
};
|
|
server.use(
|
|
http.get('/api/system-notices/active', () => HttpResponse.json([release])),
|
|
);
|
|
|
|
await useSystemNoticeStore.getState().fetch();
|
|
|
|
const state = useSystemNoticeStore.getState();
|
|
expect(state.loaded).toBe(true);
|
|
expect(state.notices.map(n => n.id)).toEqual(['release-notes']);
|
|
expect(state.notices[0].release?.version).toBe('4.3.0');
|
|
});
|
|
});
|
|
});
|