Skip to content

Commit

Permalink
✅ test: 修复测试用例 && 更新 snapshot
Browse files Browse the repository at this point in the history
  • Loading branch information
rdmclin2 committed Aug 27, 2023
1 parent ae87491 commit acaf668
Show file tree
Hide file tree
Showing 3 changed files with 3,430 additions and 8,495 deletions.
20 changes: 10 additions & 10 deletions src/SortableList/store/listDataReducer.test.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import { listDataReducer } from './listDataReducer';

const listData = [
{ id: '1', title: '序号', dataIndex: 'indexBorder' },
{ id: 1, title: '序号', dataIndex: 'indexBorder' },
{
id: '2',
id: 2,
title: '授权企业名称',
dataIndex: 'text',
},
{ id: '3', title: '被授权企业', dataIndex: 'select' },
{ id: 3, title: '被授权企业', dataIndex: 'select' },
];

const newItem = { id: '4', title: '邮箱', dataIndex: 'text' };
const newItem = { id: 4, title: '邮箱', dataIndex: 'text' };

describe('listDataReducer', () => {
describe('moveItem', () => {
Expand All @@ -27,13 +27,13 @@ describe('listDataReducer', () => {
describe('addItem', () => {
it('添加一项到末尾', () => {
const listData = [
{ id: '1', title: '序号', dataIndex: 'indexBorder' },
{ id: 1, title: '序号', dataIndex: 'indexBorder' },
{
id: '2',
id: 2,
title: '授权企业名称',
dataIndex: 'text',
},
{ id: '3', title: '被授权企业', dataIndex: 'select' },
{ id: 3, title: '被授权企业', dataIndex: 'select' },
];

const data = listDataReducer(listData, {
Expand All @@ -46,13 +46,13 @@ describe('listDataReducer', () => {

it('添加一项到任意位置', () => {
const listData = [
{ id: '1', title: '序号', dataIndex: 'indexBorder' },
{ id: 1, title: '序号', dataIndex: 'indexBorder' },
{
id: '2',
id: 2,
title: '授权企业名称',
dataIndex: 'text',
},
{ id: '3', title: '被授权企业', dataIndex: 'select' },
{ id: 3, title: '被授权企业', dataIndex: 'select' },
];

const data = listDataReducer(listData, {
Expand Down
6 changes: 3 additions & 3 deletions src/SortableList/utils/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { UniqueIdentifier } from '@dnd-kit/core';
import isEqual from 'lodash.isequal';
import React from 'react';
import { useEffect, useState } from 'react';
import type { SortableItemList } from '../type';

const defaultInitializer = (index: number) => index;
Expand Down Expand Up @@ -52,8 +52,8 @@ export function move<T>(array: T[], moveIndex: number, toIndex: number) {
}

export const useLatest = (props: any) => {
const [state, setState] = React.useState(props);
React.useEffect(() => {
const [state, setState] = useState(props);
useEffect(() => {
if (!isEqual(props, state)) {
setState(props);
}
Expand Down
Loading

0 comments on commit acaf668

Please sign in to comment.