在物理模拟中,我必须以第一种形式设置数据点。之后是第二种形式。我将在每个断点处单击并设置配置。
共。我有两种形式。第一个表单将设置第二个表单中的点数。
export const setBreakPointList = (numberOfBreakPoints) => {
//This will be a state for component
let tmp = [];
for (let i = 1; i <= numberOfBreakPoints; i++) {
tmp.push({
title: stringifyNumber(i),
breakPointNumber: i,
content: <ParticleHeatForm breakPointNumber={i}/>
})
}
return tmp;
};
export const ControlParametersReducer = (state = {
numberOfBreakPoints: Number(NUMBER_OF_TIME_BREAK_POINTS_DEFAULT),
maximumRunTime: Number(MAXIMUM_RUNTIME_DEFAULT),
steps: setBreakPointList(Number(NUMBER_OF_TIME_BREAK_POINTS_DEFAULT))
}, action) => {
switch (action.type) {
case NUMBER_OF_BREAK_POINTS_CHANGED:
return {
numberOfBreakPoints: action.payload.value,
maximumRunTime: state.maximumRunTime,
steps: setBreakPointList(action.payload.value)
};
case MAXIMUM_RUNTIME_CHANGED:
return {
numberOfBreakPoints: state.numberOfBreakPoints,
maximumRunTime: action.payload.value,
steps: state.steps
};
default:
return state;
}
};
test.js
it('ControlParametersReducer numberOfBreakPoints must change', () => {
const stateBefore = {
numberOfBreakPoints: Number(NUMBER_OF_TIME_BREAK_POINTS_DEFAULT),
maximumRunTime: Number(MAXIMUM_RUNTIME_DEFAULT),
steps: setBreakPointList(Number(NUMBER_OF_TIME_BREAK_POINTS_DEFAULT))
};
const stateAfter = {
numberOfBreakPoints: 10,
maximumRunTime: Number(MAXIMUM_RUNTIME_DEFAULT),
steps: setBreakPointList(Number(NUMBER_OF_TIME_BREAK_POINTS_DEFAULT))
};
const action = {
type: NUMBER_OF_BREAK_POINTS_CHANGED,
payload: {value: 10}
};
deepFreeze(stateBefore);
deepFreeze(stateAfter);
expect(
ControlParametersReducer(stateBefore, action)
).toEqual(stateAfter);
});
我知道reducer
必须是功能性的。因此,我跟deepFreeze
time.Sleep
问题:
我是否真的需要首先渲染我的组件然后做断言?