refactor store

This commit is contained in:
pa
2026-03-10 17:19:03 +09:00
parent 95c4a1d3e6
commit 1cbad7fb60
39 changed files with 1290 additions and 2366 deletions
+2 -1
View File
@@ -149,6 +149,7 @@
import { useDataTableScrollHeight } from '../../composables/useDataTableScrollHeight';
import { useVrcxVueTable } from '../../lib/table/useVrcxVueTable';
import { showUserDialog } from '../../coordinators/userCoordinator';
import { confirmDeleteFriend, handleFriendDelete } from '../../coordinators/friendRelationshipCoordinator';
const { t } = useI18n();
@@ -156,7 +157,7 @@ import { showUserDialog } from '../../coordinators/userCoordinator';
const { friends, allFavoriteFriendIds } = storeToRefs(useFriendStore());
const modalStore = useModalStore();
const { getAllUserStats, getAllUserMutualCount, confirmDeleteFriend, handleFriendDelete } = useFriendStore();
const { getAllUserStats, getAllUserMutualCount } = useFriendStore();
const appearanceSettingsStore = useAppearanceSettingsStore();
const { randomUserColours } = storeToRefs(appearanceSettingsStore);
@@ -40,9 +40,13 @@ mocks.pagination = mocks.makeRef({
});
mocks.sorting = mocks.makeRef([]);
vi.mock('pinia', () => ({
storeToRefs: (store) => store
}));
vi.mock('pinia', async (importOriginal) => {
const actual = await importOriginal();
return {
...actual,
storeToRefs: (store) => store
};
});
vi.mock('vue-i18n', () => ({
useI18n: () => ({
@@ -66,9 +70,7 @@ vi.mock('../../../stores', () => ({
friends: mocks.friends,
allFavoriteFriendIds: mocks.allFavoriteFriendIds,
getAllUserStats: mocks.getAllUserStats,
getAllUserMutualCount: mocks.getAllUserMutualCount,
confirmDeleteFriend: mocks.confirmDeleteFriend,
handleFriendDelete: mocks.handleFriendDelete
getAllUserMutualCount: mocks.getAllUserMutualCount
}),
useModalStore: () => ({
confirm: (...args) => mocks.modalConfirm(...args),
@@ -78,9 +80,7 @@ vi.mock('../../../stores', () => ({
stringComparer: mocks.stringComparer,
friendsListSearch: mocks.friendsListSearch
}),
useUserStore: () => ({
showUserDialog: (...args) => mocks.showUserDialog(...args)
}),
useUserStore: () => ({}),
useAppearanceSettingsStore: () => ({
tablePageSizes: [10, 25, 50],
tablePageSize: 25,
@@ -91,6 +91,15 @@ vi.mock('../../../stores', () => ({
})
}));
vi.mock('../../../coordinators/userCoordinator', () => ({
showUserDialog: (...args) => mocks.showUserDialog(...args)
}));
vi.mock('../../../coordinators/friendRelationshipCoordinator', () => ({
confirmDeleteFriend: (...args) => mocks.confirmDeleteFriend(...args),
handleFriendDelete: (...args) => mocks.handleFriendDelete(...args)
}));
vi.mock('../../../plugin/router', () => ({
router: {
push: (...args) => mocks.routerPush(...args)
+12 -5
View File
@@ -8,9 +8,13 @@ const mocks = vi.hoisted(() => ({
te: vi.fn((key) => key === 'view.moderation.filters.block')
}));
vi.mock('pinia', () => ({
storeToRefs: (store) => store
}));
vi.mock('pinia', async (importOriginal) => {
const actual = await importOriginal();
return {
...actual,
storeToRefs: (store) => store
};
});
vi.mock('../../../plugin', () => ({
i18n: {
@@ -26,11 +30,14 @@ vi.mock('../../../stores', () => ({
shiftHeld: mocks.shiftHeld
}),
useUserStore: () => ({
currentUser: mocks.currentUser,
showUserDialog: (...args) => mocks.showUserDialog(...args)
currentUser: mocks.currentUser
})
}));
vi.mock('../../../coordinators/userCoordinator', () => ({
showUserDialog: (...args) => mocks.showUserDialog(...args)
}));
vi.mock('../../../shared/utils', () => ({
formatDateFilter: (value, format) => `${format}:${value}`
}));
@@ -21,9 +21,13 @@ const mocks = vi.hoisted(() => ({
photonColumnToggleVisibility: vi.fn()
}));
vi.mock('pinia', () => ({
storeToRefs: (store) => store
}));
vi.mock('pinia', async (importOriginal) => {
const actual = await importOriginal();
return {
...actual,
storeToRefs: (store) => store
};
});
vi.mock('vue-i18n', () => ({
useI18n: () => ({
@@ -43,9 +47,7 @@ vi.mock('../../../stores', () => ({
saveChatboxUserBlacklist: (...args) => mocks.saveChatboxUserBlacklist(...args)
}),
useUserStore: () => ({
currentUser: mocks.currentUser,
showUserDialog: (...args) => mocks.showUserDialog(...args),
lookupUser: (...args) => mocks.lookupUser(...args)
currentUser: mocks.currentUser
}),
useWorldStore: () => ({
showWorldDialog: (...args) => mocks.showWorldDialog(...args)
@@ -64,6 +66,11 @@ vi.mock('../../../stores', () => ({
})
}));
vi.mock('../../../coordinators/userCoordinator', () => ({
showUserDialog: (...args) => mocks.showUserDialog(...args),
lookupUser: (...args) => mocks.lookupUser(...args)
}));
vi.mock('../../../lib/table/useVrcxVueTable', () => ({
useVrcxVueTable: () => ({
table: {
@@ -390,7 +390,6 @@
useAuthStore,
useAvatarProviderStore,
useAvatarStore,
useGameLogStore,
useGeneralSettingsStore,
useGroupStore,
useInstanceStore,
@@ -400,10 +399,11 @@
useUserStore,
useVRCXUpdaterStore,
useVrStore,
useVrcxStore,
useWorldStore
} from '../../../../stores';
import { authRequest, queryRequest } from '../../../../api';
import { disableGameLogDialog } from '../../../../coordinators/gameLogCoordinator';
import { clearVRCXCache } from '../../../../coordinators/vrcxCoordinator';
import { openExternalLink } from '../../../../shared/utils';
import AvatarProviderDialog from '../../dialogs/AvatarProviderDialog.vue';
@@ -420,9 +420,7 @@
const { updateVRLastLocation, updateOpenVR } = useVrStore();
const { enablePrimaryPasswordChange } = useAuthStore();
const { cachedConfig } = storeToRefs(useAuthStore());
const { clearVRCXCache } = useVrcxStore();
const { showConsole } = useUiStore();
const { disableGameLogDialog } = useGameLogStore();
const generalSettingsStore = useGeneralSettingsStore();
const { udonExceptionLogging, logResourceLoad, logEmptyAvatars, autoLoginDelayEnabled } =
+2 -1
View File
@@ -81,6 +81,7 @@
import '@/styles/status-icon.css';
import { showUserDialog } from '../../../coordinators/userCoordinator';
import { confirmDeleteFriend } from '../../../coordinators/friendRelationshipCoordinator';
const props = defineProps({
friend: { type: Object, required: true },
@@ -89,7 +90,7 @@ import { showUserDialog } from '../../../coordinators/userCoordinator';
const { hideNicknames } = storeToRefs(useAppearanceSettingsStore());
const { isRefreshFriendsLoading, allFavoriteFriendIds } = storeToRefs(useFriendStore());
const { confirmDeleteFriend } = useFriendStore();
const { t } = useI18n();
@@ -7,17 +7,20 @@ const mocks = vi.hoisted(() => ({
},
friendStore: {
isRefreshFriendsLoading: false,
allFavoriteFriendIds: new Set(),
confirmDeleteFriend: vi.fn()
allFavoriteFriendIds: new Set()
},
userStore: {
showUserDialog: vi.fn()
}
userStore: {},
showUserDialog: vi.fn(),
confirmDeleteFriend: vi.fn()
}));
vi.mock('pinia', () => ({
storeToRefs: (store) => store
}));
vi.mock('pinia', async (importOriginal) => {
const actual = await importOriginal();
return {
...actual,
storeToRefs: (store) => store
};
});
vi.mock('../../../../stores', () => ({
useAppearanceSettingsStore: () => mocks.appearanceStore,
@@ -25,6 +28,14 @@ vi.mock('../../../../stores', () => ({
useUserStore: () => mocks.userStore
}));
vi.mock('../../../../coordinators/userCoordinator', () => ({
showUserDialog: (...args) => mocks.showUserDialog(...args)
}));
vi.mock('../../../../coordinators/friendRelationshipCoordinator', () => ({
confirmDeleteFriend: (...args) => mocks.confirmDeleteFriend(...args)
}));
vi.mock('../../../../shared/utils', () => ({
userImage: vi.fn(() => 'https://example.com/avatar.png'),
userStatusClass: vi.fn(() => 'status-online')
@@ -125,8 +136,8 @@ describe('FriendItem.vue', () => {
mocks.appearanceStore.hideNicknames = false;
mocks.friendStore.isRefreshFriendsLoading = false;
mocks.friendStore.allFavoriteFriendIds = new Set();
mocks.friendStore.confirmDeleteFriend.mockReset();
mocks.userStore.showUserDialog.mockReset();
mocks.confirmDeleteFriend.mockReset();
mocks.showUserDialog.mockReset();
});
test('renders nickname when hideNicknames is false', () => {
@@ -149,7 +160,7 @@ describe('FriendItem.vue', () => {
test('clicking row opens user dialog', async () => {
const wrapper = mountItem();
await wrapper.get('div').trigger('click');
expect(mocks.userStore.showUserDialog).toHaveBeenCalledWith('usr_1');
expect(mocks.showUserDialog).toHaveBeenCalledWith('usr_1');
});
test('renders delete action for orphan friend and triggers confirmDeleteFriend', async () => {
@@ -164,9 +175,9 @@ describe('FriendItem.vue', () => {
expect(wrapper.text()).toContain('Ghost');
const button = wrapper.get('[data-testid="delete-button"]');
await button.trigger('click');
expect(mocks.friendStore.confirmDeleteFriend).toHaveBeenCalledWith(
expect(mocks.confirmDeleteFriend).toHaveBeenCalledWith(
'usr_orphan'
);
expect(mocks.userStore.showUserDialog).not.toHaveBeenCalled();
expect(mocks.showUserDialog).not.toHaveBeenCalled();
});
});
@@ -23,7 +23,6 @@ const mocks = vi.hoisted(() => ({
gameLogDisabled: { value: false }
},
userStore: {
showUserDialog: vi.fn(),
showSendBoopDialog: vi.fn(),
currentUser: {
value: {
@@ -78,9 +77,13 @@ const mocks = vi.hoisted(() => ({
}
}));
vi.mock('pinia', () => ({
storeToRefs: (store) => store
}));
vi.mock('pinia', async (importOriginal) => {
const actual = await importOriginal();
return {
...actual,
storeToRefs: (store) => store
};
});
vi.mock('@tanstack/vue-virtual', () => ({
useVirtualizer: (optionsRef) => ({
@@ -111,6 +114,10 @@ vi.mock('../../../../stores', () => ({
useUserStore: () => mocks.userStore
}));
vi.mock('../../../../coordinators/userCoordinator', () => ({
showUserDialog: vi.fn()
}));
vi.mock('../../../../shared/utils', () => ({
getFriendsSortFunction: () => (a, b) => a.id.localeCompare(b.id),
isRealInstance: (location) =>
@@ -18,23 +18,26 @@ const mocks = vi.hoisted(() => ({
},
userStore: {
cachedUsers: new Map(),
showUserDialog: vi.fn(),
showSendBoopDialog: vi.fn()
},
groupStore: {
showGroupDialog: vi.fn()
},
groupStore: {},
locationStore: {
lastLocation: { value: { location: 'wrld_home:123' } }
},
gameStore: {
isGameRunning: { value: true }
}
},
showUserDialog: vi.fn(),
showGroupDialog: vi.fn()
}));
vi.mock('pinia', () => ({
storeToRefs: (store) => store
}));
vi.mock('pinia', async (importOriginal) => {
const actual = await importOriginal();
return {
...actual,
storeToRefs: (store) => store
};
});
vi.mock('../../../../stores', () => ({
useNotificationStore: () => mocks.notificationStore,
@@ -44,6 +47,14 @@ vi.mock('../../../../stores', () => ({
useGameStore: () => mocks.gameStore
}));
vi.mock('../../../../coordinators/userCoordinator', () => ({
showUserDialog: (...args) => mocks.showUserDialog(...args)
}));
vi.mock('../../../../coordinators/groupCoordinator', () => ({
showGroupDialog: (...args) => mocks.showGroupDialog(...args)
}));
vi.mock('../../../../shared/utils', () => ({
checkCanInvite: vi.fn(() => true),
userImage: vi.fn(() => 'https://example.com/avatar.png')
@@ -155,9 +166,9 @@ describe('NotificationItem.vue', () => {
mocks.notificationStore.queueMarkAsSeen.mockReset();
mocks.notificationStore.openNotificationLink.mockReset();
mocks.notificationStore.isNotificationExpired.mockReturnValue(false);
mocks.userStore.showUserDialog.mockReset();
mocks.showUserDialog.mockReset();
mocks.userStore.showSendBoopDialog.mockReset();
mocks.groupStore.showGroupDialog.mockReset();
mocks.showGroupDialog.mockReset();
mocks.userStore.cachedUsers = new Map();
});
@@ -170,7 +181,7 @@ describe('NotificationItem.vue', () => {
expect(wrapper.text()).toContain('Alice');
await wrapper.get('span.truncate.cursor-pointer').trigger('click');
expect(mocks.userStore.showUserDialog).toHaveBeenCalledWith('usr_123');
expect(mocks.showUserDialog).toHaveBeenCalledWith('usr_123');
});
test('clicking accept icon calls acceptFriendRequestNotification', async () => {