Skip to content

Commit

Permalink
test: テストの修正
Browse files Browse the repository at this point in the history
  • Loading branch information
tktcorporation committed Feb 4, 2024
1 parent fa2e504 commit 1c6859f
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 165 deletions.
6 changes: 3 additions & 3 deletions electron/service/viewer.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
});
});
53 changes: 2 additions & 51 deletions src/page/photoList/composable.spec.ts
Original file line number Diff line number Diff line change
@@ -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();
});
});
111 changes: 0 additions & 111 deletions src/page/photoList/composable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<typeof usePhotoItems>['photoItemList'],
// ): undefined | ReturnType<typeof usePhotoItems>['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;
// };

0 comments on commit 1c6859f

Please sign in to comment.