chore: replace all cn comments of fe to en version by volc api (#320)
This commit is contained in:
@@ -22,9 +22,9 @@ const LOCAL_STORAGE_KEY = '__coz_biz_cache__';
|
||||
|
||||
describe('LocalStorageService', () => {
|
||||
beforeEach(() => {
|
||||
// 清除 localStorage
|
||||
// Clear localStorage
|
||||
localStorage.clear();
|
||||
// 重置 userId
|
||||
// Reset userId
|
||||
localStorageService.setUserId(undefined);
|
||||
});
|
||||
|
||||
@@ -49,7 +49,7 @@ describe('LocalStorageService', () => {
|
||||
|
||||
localStorageService.setValue(permanentKey, value);
|
||||
|
||||
// 等待 throttle
|
||||
// Waiting for throttle
|
||||
await new Promise(resolve => setTimeout(resolve, 400));
|
||||
|
||||
const storedData = JSON.parse(
|
||||
@@ -87,15 +87,15 @@ describe('LocalStorageService', () => {
|
||||
const value2 = 'user2-value';
|
||||
const userId2 = 'test-user-id-2';
|
||||
|
||||
// 第一个用户的数据
|
||||
// The first user's data
|
||||
localStorageService.setValue(userBindKey, value1);
|
||||
|
||||
// 切换到第二个用户
|
||||
// Switch to the second user
|
||||
localStorageService.setUserId(userId2);
|
||||
localStorageService.setValue(userBindKey, value2);
|
||||
expect(localStorageService.getValue(userBindKey)).toBe(value2);
|
||||
|
||||
// 切回第一个用户
|
||||
// Switch back to the first user
|
||||
localStorageService.setUserId(userId);
|
||||
expect(localStorageService.getValue(userBindKey)).toBe(value1);
|
||||
});
|
||||
@@ -111,7 +111,7 @@ describe('LocalStorageService', () => {
|
||||
localStorageService.on('change', changeHandler);
|
||||
localStorageService.setValue(permanentKey, value);
|
||||
|
||||
// 等待事件触发
|
||||
// Wait for the event to fire
|
||||
await new Promise(resolve => setTimeout(resolve, 0));
|
||||
|
||||
expect(changeHandler).toHaveBeenCalled();
|
||||
@@ -147,15 +147,15 @@ describe('LocalStorageService', () => {
|
||||
const userId = 'test-user-id';
|
||||
const value = 'test-value';
|
||||
|
||||
// 先设置值
|
||||
// Set the value first
|
||||
localStorageService.setUserId(userId);
|
||||
localStorageService.setValue('coachmark', value);
|
||||
localStorageService.setUserId(undefined);
|
||||
|
||||
// 异步获取值
|
||||
// Get value asynchronously
|
||||
const valuePromise = localStorageService.getValueSync('coachmark');
|
||||
|
||||
// 设置 userId
|
||||
// Set userId
|
||||
setTimeout(() => {
|
||||
localStorageService.setUserId(userId);
|
||||
}, 0);
|
||||
|
||||
@@ -32,7 +32,7 @@ describe('useValue', () => {
|
||||
const value = 'test-value';
|
||||
localStorageService.setValue(permanentKey, value);
|
||||
|
||||
// 等待事件触发
|
||||
// Wait for the event to fire
|
||||
await new Promise(resolve => setTimeout(resolve, 0));
|
||||
|
||||
const { result } = renderHook(() => useValue(permanentKey));
|
||||
@@ -42,12 +42,12 @@ describe('useValue', () => {
|
||||
it('当值改变时应该更新', async () => {
|
||||
const { result } = renderHook(() => useValue(permanentKey));
|
||||
|
||||
// 等待事件触发
|
||||
// Wait for the event to fire
|
||||
await new Promise(resolve => setTimeout(resolve, 0));
|
||||
|
||||
await act(async () => {
|
||||
localStorageService.setValue(permanentKey, 'new-value');
|
||||
// 等待事件触发
|
||||
// Wait for the event to fire
|
||||
await new Promise(resolve => setTimeout(resolve, 0));
|
||||
});
|
||||
|
||||
@@ -57,14 +57,14 @@ describe('useValue', () => {
|
||||
it('当值被删除时应该返回 undefined', async () => {
|
||||
localStorageService.setValue(permanentKey, 'test-value');
|
||||
|
||||
// 等待事件触发
|
||||
// Wait for the event to fire
|
||||
await new Promise(resolve => setTimeout(resolve, 0));
|
||||
|
||||
const { result } = renderHook(() => useValue(permanentKey));
|
||||
|
||||
await act(async () => {
|
||||
localStorageService.setValue(permanentKey, undefined);
|
||||
// 等待事件触发
|
||||
// Wait for the event to fire
|
||||
await new Promise(resolve => setTimeout(resolve, 0));
|
||||
});
|
||||
|
||||
@@ -74,18 +74,18 @@ describe('useValue', () => {
|
||||
it('卸载时应该清理事件监听', async () => {
|
||||
const { unmount } = renderHook(() => useValue(permanentKey));
|
||||
|
||||
// 等待事件触发
|
||||
// Wait for the event to fire
|
||||
await new Promise(resolve => setTimeout(resolve, 0));
|
||||
|
||||
unmount();
|
||||
|
||||
// 确保不会触发已卸载组件的状态更新
|
||||
// Make sure that status updates for uninstalled components are not triggered
|
||||
localStorageService.setValue(permanentKey, 'new-value');
|
||||
// 如果事件监听没有被清理,这里会抛出 React 警告
|
||||
// If the event listener is not cleaned up, a React warning will be thrown here
|
||||
});
|
||||
|
||||
describe('用户相关的值', () => {
|
||||
// 使用一个确定绑定了用户的 key
|
||||
// Use a key that confirms the user is bound.
|
||||
const userBindKey = 'coachmark' as const;
|
||||
const userId = 'test-user-id';
|
||||
|
||||
@@ -96,7 +96,7 @@ describe('useValue', () => {
|
||||
it('应该返回当前用户的值', async () => {
|
||||
localStorageService.setValue(userBindKey, 'user-value');
|
||||
|
||||
// 等待事件触发
|
||||
// Wait for the event to fire
|
||||
await new Promise(resolve => setTimeout(resolve, 0));
|
||||
|
||||
const { result } = renderHook(() => useValue(userBindKey));
|
||||
@@ -107,7 +107,7 @@ describe('useValue', () => {
|
||||
const userId2 = 'test-user-id-2';
|
||||
localStorageService.setValue(userBindKey, 'user1-value');
|
||||
|
||||
// 等待事件触发
|
||||
// Wait for the event to fire
|
||||
await new Promise(resolve => setTimeout(resolve, 0));
|
||||
|
||||
const { result } = renderHook(() => useValue(userBindKey));
|
||||
@@ -116,7 +116,7 @@ describe('useValue', () => {
|
||||
await act(async () => {
|
||||
localStorageService.setUserId(userId2);
|
||||
localStorageService.setValue(userBindKey, 'user2-value');
|
||||
// 等待事件触发
|
||||
// Wait for the event to fire
|
||||
await new Promise(resolve => setTimeout(resolve, 0));
|
||||
});
|
||||
|
||||
@@ -124,7 +124,7 @@ describe('useValue', () => {
|
||||
|
||||
await act(async () => {
|
||||
localStorageService.setUserId(userId);
|
||||
// 等待事件触发
|
||||
// Wait for the event to fire
|
||||
await new Promise(resolve => setTimeout(resolve, 0));
|
||||
});
|
||||
|
||||
|
||||
@@ -72,7 +72,7 @@ describe('解析工具函数', () => {
|
||||
it('应该返回空对象当永久缓存数据格式无效', () => {
|
||||
const data = {
|
||||
permanent: {
|
||||
key: 123, // 应该是字符串
|
||||
key: 123, // Should be string.
|
||||
},
|
||||
};
|
||||
expect(paseLocalStorageValue(JSON.stringify(data))).toEqual({});
|
||||
@@ -82,7 +82,7 @@ describe('解析工具函数', () => {
|
||||
const data = {
|
||||
userRelated: {
|
||||
'user-1': {
|
||||
key: 123, // 应该是字符串
|
||||
key: 123, // Should be string.
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user