mirror of
https://github.com/MrUnknownDE/VRCX.git
synced 2026-05-05 14:26:06 +02:00
refactor store
This commit is contained in:
@@ -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 () => {
|
||||
|
||||
Reference in New Issue
Block a user