-
Notifications
You must be signed in to change notification settings - Fork 308
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[refactor] アップデート通知ダイアログ周りをEditorHome.vueから分離 (#1717)
* e2eテスト追加 * 色々実装しちゃったやつ * バグフィックス * assertNonNullable * UrlString
- Loading branch information
Showing
11 changed files
with
203 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
<!-- | ||
アップデート通知ダイアログのコンテナ。 | ||
スキップしたバージョンより新しいバージョンがあれば、ダイアログを表示する。 | ||
--> | ||
|
||
<template> | ||
<update-notification-dialog | ||
v-if="newUpdateResult.status == 'updateAvailable'" | ||
v-model="isDialogOpenComputed" | ||
:latest-version="newUpdateResult.latestVersion" | ||
:new-update-infos="newUpdateResult.newUpdateInfos" | ||
@skip-this-version-click="handleSkipThisVersionClick" | ||
/> | ||
</template> | ||
|
||
<script setup lang="ts"> | ||
import semver from "semver"; | ||
import { computed, watch } from "vue"; | ||
import UpdateNotificationDialog from "./Presentation.vue"; | ||
import { useFetchNewUpdateInfos } from "@/composables/useFetchNewUpdateInfos"; | ||
import { useStore } from "@/store"; | ||
import { UrlString } from "@/type/preload"; | ||
|
||
const props = | ||
defineProps<{ | ||
canOpenDialog: boolean; // ダイアログを開いても良いかどうか | ||
}>(); | ||
|
||
const store = useStore(); | ||
|
||
const isDialogOpenComputed = computed({ | ||
get: () => store.state.isUpdateNotificationDialogOpen, | ||
set: (val) => | ||
store.dispatch("SET_DIALOG_OPEN", { | ||
isUpdateNotificationDialogOpen: val, | ||
}), | ||
}); | ||
|
||
// エディタのアップデート確認 | ||
if (!import.meta.env.VITE_LATEST_UPDATE_INFOS_URL) { | ||
throw new Error( | ||
"環境変数VITE_LATEST_UPDATE_INFOS_URLが設定されていません。.envに記載してください。" | ||
); | ||
} | ||
|
||
// アプリのバージョンとスキップしたバージョンのうち、新しい方を返す | ||
const currentVersionGetter = async () => { | ||
const appVersion = await window.electron | ||
.getAppInfos() | ||
.then((obj) => obj.version); | ||
|
||
await store.dispatch("WAIT_VUEX_READY", { timeout: 15000 }); | ||
const skipUpdateVersion = store.state.skipUpdateVersion ?? "0.0.0"; | ||
if (semver.valid(skipUpdateVersion) == undefined) { | ||
throw new Error(`skipUpdateVersionが不正です: ${skipUpdateVersion}`); | ||
} | ||
|
||
return semver.gt(appVersion, skipUpdateVersion) | ||
? appVersion | ||
: skipUpdateVersion; | ||
}; | ||
|
||
// 新しいバージョンがあれば取得 | ||
const newUpdateResult = useFetchNewUpdateInfos( | ||
currentVersionGetter, | ||
UrlString(import.meta.env.VITE_LATEST_UPDATE_INFOS_URL) | ||
); | ||
|
||
// 新しいバージョンのアップデートがスキップされたときの処理 | ||
const handleSkipThisVersionClick = (version: string) => { | ||
store.dispatch("SET_ROOT_MISC_SETTING", { | ||
key: "skipUpdateVersion", | ||
value: version, | ||
}); | ||
}; | ||
|
||
// ダイアログを開くかどうか | ||
watch( | ||
() => [props.canOpenDialog, newUpdateResult], | ||
() => { | ||
if ( | ||
props.canOpenDialog && | ||
newUpdateResult.value.status == "updateAvailable" | ||
) { | ||
isDialogOpenComputed.value = true; | ||
} | ||
} | ||
); | ||
</script> |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import { | ||
mount, | ||
flushPromises, | ||
DOMWrapper, | ||
enableAutoUnmount, | ||
} from "@vue/test-utils"; | ||
import { describe, it } from "vitest"; | ||
import { Quasar } from "quasar"; | ||
|
||
import UpdateNotificationDialogPresentation from "@/components/UpdateNotificationDialog/Presentation.vue"; | ||
import { assertNonNullable } from "@/type/utility"; | ||
|
||
const mountUpdateNotificationDialogPresentation = async (context?: { | ||
latestVersion?: string; | ||
onSkipThisVersionClick?: (version: string) => void; | ||
}) => { | ||
const latestVersion = context?.latestVersion ?? "1.0.0"; | ||
const onSkipThisVersionClick = | ||
context?.onSkipThisVersionClick ?? (() => undefined); | ||
|
||
const wrapper = mount(UpdateNotificationDialogPresentation, { | ||
props: { | ||
modelValue: true, | ||
latestVersion, | ||
newUpdateInfos: [], | ||
onSkipThisVersionClick, | ||
}, | ||
global: { | ||
plugins: [Quasar], | ||
}, | ||
}); | ||
await flushPromises(); | ||
const domWrapper = new DOMWrapper(document.body); // QDialogを取得するワークアラウンド | ||
|
||
const buttons = domWrapper.findAll("button"); | ||
|
||
const skipButton = buttons.find((button) => button.text().match(/スキップ/)); | ||
assertNonNullable(skipButton); | ||
|
||
const exitButton = buttons.find((button) => button.text().match(/閉じる/)); | ||
assertNonNullable(exitButton); | ||
|
||
return { wrapper, skipButton, exitButton }; | ||
}; | ||
|
||
describe("Presentation", () => { | ||
enableAutoUnmount(afterEach); | ||
|
||
it("マウントできる", async () => { | ||
mountUpdateNotificationDialogPresentation(); | ||
}); | ||
|
||
it("閉じるボタンを押すと閉じられる", async () => { | ||
const { wrapper, exitButton } = | ||
await mountUpdateNotificationDialogPresentation(); | ||
await exitButton.trigger("click"); | ||
expect(wrapper.emitted("update:modelValue")).toEqual([[false]]); | ||
}); | ||
|
||
it("スキップボタンを押すとコールバックが実行される", async () => { | ||
const onSkipThisVersionClick = vi.fn(); | ||
const { skipButton } = await mountUpdateNotificationDialogPresentation({ | ||
onSkipThisVersionClick, | ||
}); | ||
await skipButton.trigger("click"); | ||
expect(onSkipThisVersionClick).toHaveBeenCalled(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters