diff --git a/electron/service/viewer.spec.ts b/electron/service/viewer.spec.ts index 1dd96a0..f8fefff 100644 --- a/electron/service/viewer.spec.ts +++ b/electron/service/viewer.spec.ts @@ -79,10 +79,10 @@ describe('viewer_api', () => { .parseJoinInfoFileName(infoFileNameWithoutExt) ._unsafeUnwrap().worldId; // api で world 情報を取得する - const reqUrl = `https://api.vrchat.cloud/api/1/worlds/wrld_${worldId}`; - console.log(reqUrl); + const reqUrl = `https://api.vrchat.cloud/api/1/worlds/${worldId}`; const res = await fetch(reqUrl); const worldInfo = await res.json(); - console.log(worldInfo); + expect(worldInfo.id).toBe(worldId); + expect(typeof worldInfo.name).toBe('string'); }); }); diff --git a/src/page/photoList/composable.spec.ts b/src/page/photoList/composable.spec.ts index b565af1..1b89c9c 100644 --- a/src/page/photoList/composable.spec.ts +++ b/src/page/photoList/composable.spec.ts @@ -1,54 +1,5 @@ -import { sortPhotoList, usePhotoItems } from './composable'; - describe('composable', () => { - describe('sortPhotoList', () => { - it('returns undefined for null or undefined photoList', () => { - expect(sortPhotoList(undefined)).toBeUndefined(); - expect(sortPhotoList(null)).toBeUndefined(); - }); - - it('returns original list if no JOIN items are present', () => { - const photoList = [{ type: 'PHOTO', date: '2023-12-15' }]; - expect(sortPhotoList(photoList)).toEqual(photoList); - }); - - const createPhotoList = ({ - type, - datetime, - }: { type: 'PHOTO' | 'JOIN'; datetime: string }): ReturnType< - typeof usePhotoItems - >['photoItemList'] => { - return { - type, - datetime: { - date: { - year: datetime.slice(0, 4), - month: datetime.slice(5, 7), - day: datetime.slice(8, 10), - }, - time: { - hour: datetime.slice(11, 13), - minute: datetime.slice(14, 16), - second: 0, - millisecond: 0, - }, - }, - }; - }; - - it('correctly rearranges list with JOIN items', () => { - const photoList = [ - createPhotoList({ type: 'PHOTO', datetime: '2023-12-17T00:00' }), - createPhotoList({ type: 'JOIN', datetime: '2023-12-16T00:00' }), - createPhotoList({ type: 'JOIN', datetime: '2023-12-15T00:00' }), - ]; - console.log(photoList); - const expectedResult = [ - createPhotoList({ type: 'JOIN', datetime: '2023-12-16T00:00' }), - createPhotoList({ type: 'PHOTO', datetime: '2023-12-17T00:00' }), - createPhotoList({ type: 'JOIN', datetime: '2023-12-15T00:00' }), - ]; - expect(sortPhotoList(photoList)).toEqual(expectedResult); - }); + it('should be defined', () => { + expect(true).toBeTruthy(); }); }); diff --git a/src/page/photoList/composable.ts b/src/page/photoList/composable.ts index 577af39..6e12d17 100644 --- a/src/page/photoList/composable.ts +++ b/src/page/photoList/composable.ts @@ -68,114 +68,3 @@ export const usePhotoItems = (selectedFolderYearMonth: YearMonth) => { refetchPhotoItemList, }; }; - -// export const usePhotoItems = (selectedFolderYearMonth: YearMonth) => { -// console.log('selectedFolderYearMonth', selectedFolderYearMonth); -// const [photoItemList, setPhotoItemList] = -// useState< -// inferProcedureOutput< -// AppRouter['getVRChatPhotoWithWorldIdAndDate'] -// >['data'] -// >(); -// const [photoItemFetchError, setPhotoItemFetchError] = -// useState< -// inferProcedureOutput< -// AppRouter['getVRChatPhotoWithWorldIdAndDate'] -// >['error'] -// >(null); - -// const photoItemListQuery = -// trpcReact.getVRChatPhotoWithWorldIdAndDate.useQuery( -// selectedFolderYearMonth, -// { -// enabled: !!( -// selectedFolderYearMonth.year && selectedFolderYearMonth.month -// ), -// }, -// ); - -// const sortedPhotoItems = useMemo(() => { -// if (!photoItemListQuery.data?.data) { -// return []; -// } - -// const list = photoItemListQuery.data.data; -// return [...list].sort((a, b) => { -// const datetimeA = -// a.datetime.date.year + -// a.datetime.date.month + -// a.datetime.date.day + -// a.datetime.time.hour + -// a.datetime.time.minute + -// a.datetime.time.second + -// a.datetime.time.millisecond; -// const datetimeB = -// b.datetime.date.year + -// b.datetime.date.month + -// b.datetime.date.day + -// b.datetime.time.hour + -// b.datetime.time.minute + -// b.datetime.time.second + -// b.datetime.time.millisecond; -// return datetimeB.localeCompare(datetimeA); -// }); -// }, [photoItemListQuery.data?.data]); - -// useEffect(() => { -// setPhotoItemList(sortedPhotoItems); -// setPhotoItemFetchError(photoItemListQuery.data?.error ?? null); -// }, [sortedPhotoItems, photoItemListQuery.data?.error]); - -// const refetchPhotoItemList = () => photoItemListQuery.refetch(); - -// return { -// photoItemList, -// setPhotoItemList, -// photoItemFetchError, -// refetchPhotoItemList, -// }; -// }; - -// /** -// * 通常の順番で表示すると、WorldInfo が写真の下に表示されてしまうため、 -// * WorldInfo が写真の上に表示されるように並び替える -// */ -// export const sortPhotoList = ( -// photoList: ReturnType['photoItemList'], -// ): undefined | ReturnType['photoItemList'] => { -// if (!photoList) { -// return; -// } -// const resultPhotoList = [...photoList]; -// // JOINが存在するインデックスを保存 -// const joinIndexes = resultPhotoList.reduce( -// (indexes: number[], item, index) => { -// if (item.type === 'JOIN') { -// indexes.push(index); -// } -// return indexes; -// }, -// [], -// ); - -// // JOIN要素を逆順で移動 -// for (let i = joinIndexes.length - 2; i >= 0; i -= 1) { -// const currentIndex = joinIndexes[i]; -// const nextIndex = joinIndexes[i + 1]; - -// // 現在のJOIN要素を取得し、配列から削除 -// const joinElement = resultPhotoList.splice(currentIndex, 1)[0]; - -// // 次のJOINの位置の後ろに挿入 -// resultPhotoList.splice(nextIndex, 0, joinElement); - -// // 配列が変更されたので、インデックスを更新 -// for (let j = i; j >= 0; j -= 1) { -// if (joinIndexes[j] < nextIndex) { -// joinIndexes[j] += 1; -// } -// } -// } - -// return resultPhotoList; -// };