Synchronisation im Hintegrund

This commit is contained in:
silas 2018-10-02 18:32:36 +02:00
parent b5da034687
commit da2252fc11
4 changed files with 83 additions and 39 deletions

View File

@ -6159,7 +6159,7 @@ class LevelSite extends WordRotatorBaseSite {
this.wonText.style.fontSize = "0"; this.wonText.style.fontSize = "0";
const db = WordRotatorDb.getInstance(); const db = WordRotatorDb.getInstance();
const nextLevelJson = await db.loadNextLevel([20, 40, 60, 100, 120, 140, 160]); const nextLevelJson = await db.loadNextLevel(LevelSite.RENDERER_TYPES);
if (nextLevelJson === null) { if (nextLevelJson === null) {
this.startSite(EndSite); this.startSite(EndSite);
@ -6449,7 +6449,7 @@ class LevelSite extends WordRotatorBaseSite {
} }
} }
} }
LevelSite.RENDERER_TYPES = [20, 40, 60, 100, 120, 140, 160];
LevelSite.TUTORIAL = { LevelSite.TUTORIAL = {
FIRST_LEVEL: 67, FIRST_LEVEL: 67,
SECOND_LEVEL: 15, SECOND_LEVEL: 15,
@ -6486,7 +6486,7 @@ class MenuSite extends WordRotatorBaseSite {
level.getWonPromise().then(() => { level.getWonPromise().then(() => {
Matomo.push(["trackEvent", "MainMenu", "levelSolved"]); Matomo.push(["trackEvent", "MainMenu", "levelSolved"]);
this.startSite(LevelSite); this.startLevelSite();
}); });
let segment = level.getRootSegment(); let segment = level.getRootSegment();
@ -6549,13 +6549,23 @@ class MenuSite extends WordRotatorBaseSite {
return res; return res;
} }
async startLevelSite() {
this.startSite(LevelSite, Promise.race([this.loadLevelPromise, new Promise(async resolve => {
const db = WordRotatorDb.getInstance();
let level = await db.loadNextLevel(LevelSite.RENDERER_TYPES);
if (level !== null) {
resolve();
}
})]));
}
async onFirstStart() { async onFirstStart() {
super.onFirstStart(); super.onFirstStart();
let playButton = this.findBy("#play-button"); let playButton = this.findBy("#play-button");
playButton.addEventListener("click", () => { playButton.addEventListener("click", () => {
Matomo.push(["trackEvent", "MainMenu", "startButton"]); Matomo.push(["trackEvent", "MainMenu", "startButton"]);
this.startSite(LevelSite, this.loadLevelPromise); this.startLevelSite();
}); });
let leafSegmentTemplate = this.findBy("#segment-leaf-template"); let leafSegmentTemplate = this.findBy("#segment-leaf-template");
@ -6591,10 +6601,10 @@ class MenuSite extends WordRotatorBaseSite {
playMusicButton.addEventListener("change", () => { playMusicButton.addEventListener("change", () => {
settingsManager.setSetting("play-music", playMusicButton.checked); settingsManager.setSetting("play-music", playMusicButton.checked);
soundManager.set({muted: !playMusicButton.checked}, SoundManager.CHANNELS.MUSIC); soundManager.set({muted: !playMusicButton.checked}, SoundManager.CHANNELS.MUSIC);
if (playMusicButton.checked){ if (playMusicButton.checked) {
soundManager.play(SoundManager.CHANNELS.MUSIC); soundManager.play(SoundManager.CHANNELS.MUSIC);
} }
Matomo.push(["trackEvent", "MainMenu", "PlayMusic", "Play Music", (playMusicButton.checked)?1:0]); Matomo.push(["trackEvent", "MainMenu", "PlayMusic", "Play Music", (playMusicButton.checked) ? 1 : 0]);
}); });
let playSoundButton = this.findBy("#play-sound"); let playSoundButton = this.findBy("#play-sound");
@ -6602,7 +6612,7 @@ class MenuSite extends WordRotatorBaseSite {
playSoundButton.addEventListener("change", () => { playSoundButton.addEventListener("change", () => {
settingsManager.setSetting("play-sound", playSoundButton.checked); settingsManager.setSetting("play-sound", playSoundButton.checked);
soundManager.set({muted: !playSoundButton.checked}, SoundManager.CHANNELS.SOUND); soundManager.set({muted: !playSoundButton.checked}, SoundManager.CHANNELS.SOUND);
Matomo.push(["trackEvent", "MainMenu", "PlaySound", "Play Sound", (playSoundButton.checked)?1:0]); Matomo.push(["trackEvent", "MainMenu", "PlaySound", "Play Sound", (playSoundButton.checked) ? 1 : 0]);
}); });
} }
@ -6625,7 +6635,9 @@ class MenuSite extends WordRotatorBaseSite {
"dateLastSync": dateLastSync "dateLastSync": dateLastSync
})); }));
if (!res["success"]) { if (!res["success"]) {
FlashMessenger.addMessage("sync-error", null, 6000); if (await db.loadNextLevel(LevelSite.RENDERER_TYPES) === null) {
FlashMessenger.addMessage("sync-error", null, 6000);
}
newLastSync = null; newLastSync = null;
break; break;
} }
@ -6645,8 +6657,7 @@ class MenuSite extends WordRotatorBaseSite {
let levels = await Promise.all(levelPromises); let levels = await Promise.all(levelPromises);
await db.saveManyLevels(levels); await db.saveManyLevels(levels);
if (newLastSync != null && newLastSync !== "null") if (newLastSync != null && newLastSync !== "null") {
{
localStorage.setItem("date-last-sync", newLastSync); localStorage.setItem("date-last-sync", newLastSync);
} }
} }

View File

@ -150,7 +150,7 @@ export class LevelSite extends WordRotatorBaseSite {
this.wonText.style.fontSize = "0"; this.wonText.style.fontSize = "0";
const db = WordRotatorDb.getInstance(); const db = WordRotatorDb.getInstance();
const nextLevelJson = await db.loadNextLevel([20, 40, 60, 100, 120, 140, 160]); const nextLevelJson = await db.loadNextLevel(LevelSite.RENDERER_TYPES);
if (nextLevelJson === null) { if (nextLevelJson === null) {
this.startSite(EndSite); this.startSite(EndSite);
@ -440,7 +440,7 @@ export class LevelSite extends WordRotatorBaseSite {
} }
} }
} }
LevelSite.RENDERER_TYPES = [20, 40, 60, 100, 120, 140, 160];
LevelSite.TUTORIAL = { LevelSite.TUTORIAL = {
FIRST_LEVEL: 67, FIRST_LEVEL: 67,
SECOND_LEVEL: 15, SECOND_LEVEL: 15,

View File

@ -24,7 +24,7 @@ export class MenuSite extends WordRotatorBaseSite {
level.getWonPromise().then(() => { level.getWonPromise().then(() => {
Matomo.push(["trackEvent", "MainMenu", "levelSolved"]); Matomo.push(["trackEvent", "MainMenu", "levelSolved"]);
this.startSite(LevelSite); this.startLevelSite();
}); });
let segment = level.getRootSegment(); let segment = level.getRootSegment();
@ -87,13 +87,23 @@ export class MenuSite extends WordRotatorBaseSite {
return res; return res;
} }
async startLevelSite() {
this.startSite(LevelSite, Promise.race([this.loadLevelPromise, new Promise(async resolve => {
const db = WordRotatorDb.getInstance();
let level = await db.loadNextLevel(LevelSite.RENDERER_TYPES);
if (level !== null) {
resolve();
}
})]));
}
async onFirstStart() { async onFirstStart() {
super.onFirstStart(); super.onFirstStart();
let playButton = this.findBy("#play-button"); let playButton = this.findBy("#play-button");
playButton.addEventListener("click", () => { playButton.addEventListener("click", () => {
Matomo.push(["trackEvent", "MainMenu", "startButton"]); Matomo.push(["trackEvent", "MainMenu", "startButton"]);
this.startSite(LevelSite, this.loadLevelPromise); this.startLevelSite();
}); });
let leafSegmentTemplate = this.findBy("#segment-leaf-template"); let leafSegmentTemplate = this.findBy("#segment-leaf-template");
@ -129,10 +139,10 @@ export class MenuSite extends WordRotatorBaseSite {
playMusicButton.addEventListener("change", () => { playMusicButton.addEventListener("change", () => {
settingsManager.setSetting("play-music", playMusicButton.checked); settingsManager.setSetting("play-music", playMusicButton.checked);
soundManager.set({muted: !playMusicButton.checked}, SoundManager.CHANNELS.MUSIC); soundManager.set({muted: !playMusicButton.checked}, SoundManager.CHANNELS.MUSIC);
if (playMusicButton.checked){ if (playMusicButton.checked) {
soundManager.play(SoundManager.CHANNELS.MUSIC); soundManager.play(SoundManager.CHANNELS.MUSIC);
} }
Matomo.push(["trackEvent", "MainMenu", "PlayMusic", "Play Music", (playMusicButton.checked)?1:0]); Matomo.push(["trackEvent", "MainMenu", "PlayMusic", "Play Music", (playMusicButton.checked) ? 1 : 0]);
}); });
let playSoundButton = this.findBy("#play-sound"); let playSoundButton = this.findBy("#play-sound");
@ -140,7 +150,7 @@ export class MenuSite extends WordRotatorBaseSite {
playSoundButton.addEventListener("change", () => { playSoundButton.addEventListener("change", () => {
settingsManager.setSetting("play-sound", playSoundButton.checked); settingsManager.setSetting("play-sound", playSoundButton.checked);
soundManager.set({muted: !playSoundButton.checked}, SoundManager.CHANNELS.SOUND); soundManager.set({muted: !playSoundButton.checked}, SoundManager.CHANNELS.SOUND);
Matomo.push(["trackEvent", "MainMenu", "PlaySound", "Play Sound", (playSoundButton.checked)?1:0]); Matomo.push(["trackEvent", "MainMenu", "PlaySound", "Play Sound", (playSoundButton.checked) ? 1 : 0]);
}); });
} }
@ -163,7 +173,9 @@ export class MenuSite extends WordRotatorBaseSite {
"dateLastSync": dateLastSync "dateLastSync": dateLastSync
})); }));
if (!res["success"]) { if (!res["success"]) {
FlashMessenger.addMessage("sync-error", null, 6000); if (await db.loadNextLevel(LevelSite.RENDERER_TYPES) === null) {
FlashMessenger.addMessage("sync-error", null, 6000);
}
newLastSync = null; newLastSync = null;
break; break;
} }
@ -183,8 +195,7 @@ export class MenuSite extends WordRotatorBaseSite {
let levels = await Promise.all(levelPromises); let levels = await Promise.all(levelPromises);
await db.saveManyLevels(levels); await db.saveManyLevels(levels);
if (newLastSync != null && newLastSync !== "null") if (newLastSync != null && newLastSync !== "null") {
{
localStorage.setItem("date-last-sync", newLastSync); localStorage.setItem("date-last-sync", newLastSync);
} }
} }

View File

@ -17,13 +17,23 @@ const replaceRandom = ClientFunction((sequence) => {
async function beforeEachTest(t) { async function beforeEachTest(t) {
// await replaceRandom(); // await replaceRandom();
await waitForMainMenu(t);
} }
async function afterEachTest(t) { async function afterEachTest(t) {
return await t.eval(() => indexedDB.deleteDatabase('wordRotator')); return await t.eval(() => indexedDB.deleteDatabase('wordRotator'));
} }
let isLocal = false; async function waitForMainMenu(t) {
while (!(await Selector("#play-button").exists)) {
// console.log("nextIterate");
await t.wait(100);
}
await t.wait(2000);
}
let isLocal = true;
if (isLocal) { if (isLocal) {
fixture`Play` fixture`Play`
.page`https://127.0.0.1/pwa/wordRotator/publicTest/`.beforeEach(async t => { .page`https://127.0.0.1/pwa/wordRotator/publicTest/`.beforeEach(async t => {
@ -40,7 +50,7 @@ else {
password: '20luxl200' password: '20luxl200'
}).beforeEach(async t => { }).beforeEach(async t => {
await beforeEachTest(t); await beforeEachTest(t);
await t.wait(25000); // await t.wait(25000);
}).afterEach(async t => { }).afterEach(async t => {
await afterEachTest(t); await afterEachTest(t);
}); });
@ -78,6 +88,7 @@ const SEGMENT = {
test('Play', async t => { test('Play', async t => {
let levelNumber = 1; let levelNumber = 1;
await waitForMainMenu(t);
await t await t
//Main Menu //Main Menu
.click(Selector('#play-button')) .click(Selector('#play-button'))
@ -369,6 +380,7 @@ test('Play', async t => {
.expect(Selector('#site-content').childElementCount).eql(1); .expect(Selector('#site-content').childElementCount).eql(1);
}); });
test('LoadLastLevel', async t => { test('LoadLastLevel', async t => {
await waitForMainMenu(t);
await t.click(Selector('#play-button')) await t.click(Selector('#play-button'))
.expect(Selector('.segment-parent').nth(SEGMENT.ONE).hasClass('locked')).ok() .expect(Selector('.segment-parent').nth(SEGMENT.ONE).hasClass('locked')).ok()
.expect(Selector('.segment-parent').nth(SEGMENT.ONE).getStyleProperty('transform')).eql("matrix(1, 0, 0, 1, 0, 0)") .expect(Selector('.segment-parent').nth(SEGMENT.ONE).getStyleProperty('transform')).eql("matrix(1, 0, 0, 1, 0, 0)")
@ -378,11 +390,12 @@ test('LoadLastLevel', async t => {
await testLocalStorageSet("currentLevel", "{\"id\":15,\"rotations\":[0,0,270],\"locks\":[false,true,true]}"); await testLocalStorageSet("currentLevel", "{\"id\":15,\"rotations\":[0,0,270],\"locks\":[false,true,true]}");
}); });
test('LevelRotation', async t => { test('LevelRotation', async t => {
await t await waitForMainMenu(t);
await t.click(Selector('.segment-parent').nth(SEGMENT.THREE))
.click(Selector('.segment-parent').nth(SEGMENT.THREE)) .click(Selector('.segment-parent').nth(SEGMENT.THREE))
.click(Selector('.segment-parent').nth(SEGMENT.THREE)) .click(Selector('.segment-parent').nth(SEGMENT.THREE))
.click(Selector('.segment-parent').nth(SEGMENT.THREE)) .expect(Selector('.segment-parent').nth(SEGMENT.THREE).getStyleProperty('transform')).eql("matrix(0, -1, 1, 0, 0, 0)")
.wait(3000) .wait(3500)
.expect(Selector('.segment-parent').nth(SEGMENT.THREE).getStyleProperty('transform')).eql("matrix(0, -1, 1, 0, 0, 0)") .expect(Selector('.segment-parent').nth(SEGMENT.THREE).getStyleProperty('transform')).eql("matrix(0, -1, 1, 0, 0, 0)")
.expect(Selector('.segment-parent').nth(SEGMENT.FOUR).getStyleProperty('transform')).eql("matrix(0, 1, -1, 0, 0, 0)") .expect(Selector('.segment-parent').nth(SEGMENT.FOUR).getStyleProperty('transform')).eql("matrix(0, 1, -1, 0, 0, 0)")
.click(Selector('.segment-parent').nth(SEGMENT.THREE)) .click(Selector('.segment-parent').nth(SEGMENT.THREE))
@ -397,7 +410,8 @@ test('LevelRotation', async t => {
.click(Selector('.segment-parent').nth(SEGMENT.THREE)) .click(Selector('.segment-parent').nth(SEGMENT.THREE))
.click(Selector('.segment-parent').nth(SEGMENT.THREE)) .click(Selector('.segment-parent').nth(SEGMENT.THREE))
.click(Selector('.segment-parent').nth(SEGMENT.THREE)) .click(Selector('.segment-parent').nth(SEGMENT.THREE))
.wait(4000) .expect(Selector('.segment-parent').nth(SEGMENT.THREE).getStyleProperty('transform')).eql("matrix(0, -1, 1, 0, 0, 0)")
.wait(3500)
.expect(Selector('.segment-parent').nth(SEGMENT.THREE).getStyleProperty('transform')).eql("matrix(0, -1, 1, 0, 0, 0)") .expect(Selector('.segment-parent').nth(SEGMENT.THREE).getStyleProperty('transform')).eql("matrix(0, -1, 1, 0, 0, 0)")
.expect(Selector('.segment-parent').nth(SEGMENT.FOUR).getStyleProperty('transform')).eql("matrix(0, 1, -1, 0, 0, 0)") .expect(Selector('.segment-parent').nth(SEGMENT.FOUR).getStyleProperty('transform')).eql("matrix(0, 1, -1, 0, 0, 0)")
.click(Selector('.segment-parent').nth(SEGMENT.THREE)) .click(Selector('.segment-parent').nth(SEGMENT.THREE))
@ -412,26 +426,34 @@ test('LevelRotation', async t => {
await replaceRandom([0.9, 0.5]); await replaceRandom([0.9, 0.5]);
}); });
test('SendUserstats', async t => { test('SendUserstats', async t => {
await waitForMainMenu(t);
let matomoCheck = ClientFunction(() => { let matomoCheck = ClientFunction(() => {
return fetch("//matomo.silas.link/index.php?module=API&method=AjaxOptOut.isTracked", { return new Promise((resolve) => {
"mode": "cors", function check() {
"credentials": "include", window["_paq"].push([function () {
}).then(res => res.text()).then(text => (new window.DOMParser()).parseFromString(text, "text/xml")).then((xml => { resolve(!this["isUserOptedOut"]());
let textContent = xml.firstChild.textContent; }]);
console.log(textContent); }
return (textContent === "1")
})); window.addEventListener("load", () => {
check();
});
if (document.readyState === 'complete') {
check();
}
});
}); });
await t await t
.click(Selector(".action [data-translation-title='settings']")) .click(Selector(".action [data-translation-title='settings']"))
.expect(Selector("#play-sound").checked).ok() .expect(Selector("#play-sound").checked).ok()
.expect(Selector("#play-music").checked).ok() .expect(Selector("#play-music").checked).ok()
.expect(Selector("#track-switch").checked).ok() .expect(Selector("#track-switch").checked).ok();
.expect(await matomoCheck()).ok() let res = await matomoCheck();
await t.expect(res).ok()
.click(Selector(".switch [data-translation='track']")) .click(Selector(".switch [data-translation='track']"))
.expect(Selector("#track-switch").checked).eql(false); .expect(Selector("#track-switch").checked).eql(false);
let res = await matomoCheck(); res = await matomoCheck();
await t.expect(res).eql(false) await t.expect(res).eql(false)
.click(Selector(".switch [data-translation='track']")) .click(Selector(".switch [data-translation='track']"))
.expect(Selector("#track-switch").checked).ok(); .expect(Selector("#track-switch").checked).ok();
@ -442,7 +464,7 @@ test('SendUserstats', async t => {
}); });
test('Themes', async t => { test('Themes', async t => {
await testLocalStorageSet("currentTheme", "dark"); await waitForMainMenu(t);
await t await t
.expect(Selector("body.dark").visible).ok() .expect(Selector("body.dark").visible).ok()
.click(Selector(".action [data-translation-title='settings']")) .click(Selector(".action [data-translation-title='settings']"))
@ -453,5 +475,5 @@ test('Themes', async t => {
.expect(Selector("#theme-name").innerText).eql("Grün") .expect(Selector("#theme-name").innerText).eql("Grün")
.expect(Selector("body.green").visible).ok() .expect(Selector("body.green").visible).ok()
}).before(async t => { }).before(async t => {
testLocalStorageSet("currentTheme", "dark"); await testLocalStorageSet("currentTheme", "dark");
}); });