Skip to content

Commit 7f07305

Browse files
committed
Update mock.js
1 parent af3d5f6 commit 7f07305

1 file changed

Lines changed: 17 additions & 3 deletions

File tree

code/miniapp/test/mock.js

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ const SCENES = {
8383
'japan-jp': { t: 'japan', l: 'jp' },
8484
'jma-429': { t: 'japan', l: 'en' },
8585
'jma-wait': { t: 'japan', l: 'en' },
86+
'jma-switch': { t: 'finance', l: 'en' },
8687
'weather-down-jp': { t: 'japan', l: 'jp' },
8788
'japan-us': { t: 'japan', l: 'en' },
8889
'japan-es': { t: 'japan', l: 'es' },
@@ -100,6 +101,7 @@ const SCENES = {
100101
'live-tg': { t: 'japan', l: 'en' },
101102
'live-tg-cams': { t: 'japan', l: 'en' },
102103
'live-tg-open': { t: 'japan', l: 'en' },
104+
'live-tg-early': { t: 'japan', l: 'en' },
103105
'live-tg-slow': { t: 'japan', l: 'en' },
104106
'live-tg-back': { t: 'japan', l: 'en' },
105107
'live-tg-next': { t: 'japan', l: 'en' },
@@ -751,7 +753,11 @@ if (scenario === 'diag-telegram' || scenario === 'weather-tg' || scenario === 'h
751753
};
752754
}
753755

756+
const heldReady = [];
754757
globalThis.YT = {
758+
flushReady() {
759+
heldReady.splice(0).forEach(fn => fn());
760+
},
755761
Player: class {
756762
constructor(id, opts) {
757763
this.el = document.getElementById(id);
@@ -760,8 +766,15 @@ globalThis.YT = {
760766
this.muted = !!opts.playerVars?.mute;
761767
this.playing = false;
762768
this.loads = 0;
769+
this.ready = false;
763770
this._paint();
764-
queueMicrotask(() => opts.events?.onReady?.({ target: this }));
771+
const fire = () => {
772+
this.ready = true;
773+
opts.events?.onReady?.({ target: this });
774+
this._paint();
775+
};
776+
if (scenario === 'live-tg-early') heldReady.push(fire);
777+
else queueMicrotask(fire);
765778
}
766779
_paint() {
767780
if (!this.el) return;
@@ -770,6 +783,7 @@ globalThis.YT = {
770783
this.el.dataset.muted = this.muted ? '1' : '0';
771784
this.el.dataset.playing = this.playing ? '1' : '0';
772785
this.el.dataset.loads = String(this.loads);
786+
this.el.dataset.ready = this.ready ? '1' : '0';
773787
}
774788
getVideoData() { return { video_id: this.videoId }; }
775789
loadVideoById(id) { this.videoId = id; this.loads += 1; this.playing = true; this._paint(); }
@@ -970,13 +984,13 @@ globalThis.fetch = input => {
970984
if (url.includes('quake/data/list.json')) {
971985
if (scenario === 'quake-down') return text('', 500);
972986
const body = json(withQuakes ? quakes() : []);
973-
return scenario === 'jma-wait' ? later(350, body) : body;
987+
return scenario === 'jma-wait' || scenario === 'jma-switch' ? later(350, body) : body;
974988
}
975989
if (url.includes('common/const/area.json')) {
976990
if (scenario.startsWith('diag') || scenario === 'weather-down' || scenario === 'weather-down-jp') return Promise.reject(new Error('down'));
977991
if (scenario === 'weather-no-c20') return json({ offices: AREA.offices, class10s: AREA.class10s });
978992
const area = json(AREA);
979-
return scenario === 'jma-wait' ? later(350, area) : area;
993+
return scenario === 'jma-wait' || scenario === 'jma-switch' ? later(350, area) : area;
980994
}
981995
if (url.includes('panel/const/setting.json')) {
982996
if (scenario === 'weather-l2') {

0 commit comments

Comments
 (0)