patch to fix error messaging tests
This commit is contained in:
parent
22b4adb547
commit
c13cc33697
3 changed files with 79 additions and 22 deletions
|
@ -39,7 +39,7 @@ const Epochs = ({epochs, errors, dispatch}) => {
|
|||
}
|
||||
|
||||
const renderAddEpochButton = index => {
|
||||
if (index === epochs.length - 1 ) return (
|
||||
if (epochs && index === epochs.length - 1 ) return (
|
||||
<form onSubmit={e=>addEpoch(e)}>
|
||||
<input className="form form--add" type="submit" name="add-epoch" value="Add Epoch" ></input>
|
||||
</form>
|
||||
|
@ -48,7 +48,7 @@ const Epochs = ({epochs, errors, dispatch}) => {
|
|||
}
|
||||
|
||||
const renderEpochs = () => {
|
||||
if (epochs.length) return epochs.map((epoch, index) => {
|
||||
if (epochs && epochs.length) return epochs.map((epoch, index) => {
|
||||
const epochError = errors.epoch ? errors.error : null
|
||||
return (
|
||||
<div
|
||||
|
|
|
@ -6,7 +6,8 @@ describe('Epochs', () => {
|
|||
state.epochs = [
|
||||
{
|
||||
name: 'epoch 1',
|
||||
changes: ['']
|
||||
changes: [''],
|
||||
parent: null
|
||||
}
|
||||
]
|
||||
})
|
||||
|
@ -17,7 +18,7 @@ describe('Epochs', () => {
|
|||
});
|
||||
|
||||
it('epochs addition returns new epochs list', () => {
|
||||
const action = {type: 'ADD_EPOCH', value: { name: 'epoch 2', changes: ['']}};
|
||||
const action = {type: 'ADD_EPOCH', value: { name: 'epoch 2', changes: [''], parent: null}};
|
||||
expect(stateReducer(state, action)).toEqual({...state, epochs: [...state.epochs, action.value]})
|
||||
})
|
||||
|
||||
|
@ -28,8 +29,8 @@ describe('Epochs', () => {
|
|||
expect(stateReducer(secondState, secondAction)).toEqual(
|
||||
{...state,
|
||||
epochs: [
|
||||
{name: 'proto-lang', changes: ['']},
|
||||
{name: 'epoch 2', changes: ['']}
|
||||
{name: 'proto-lang', changes: [''], parent: null},
|
||||
{name: 'epoch 2', changes: [''], parent: null}
|
||||
]
|
||||
}
|
||||
);
|
||||
|
@ -42,8 +43,8 @@ describe('Epochs', () => {
|
|||
expect(stateReducer(secondState, secondAction)).toEqual(
|
||||
{...state,
|
||||
epochs: [
|
||||
{name: 'epoch 1', changes: ['n>t/_#', '[+plosive]>[+nasal -plosive]/_n']},
|
||||
{name: 'epoch 2', changes: ['']}
|
||||
{name: 'epoch 1', changes: ['n>t/_#', '[+plosive]>[+nasal -plosive]/_n'], parent: null},
|
||||
{name: 'epoch 2', changes: [''], parent: null}
|
||||
]
|
||||
}
|
||||
);
|
||||
|
@ -55,7 +56,7 @@ describe('Epochs', () => {
|
|||
const secondAction = {type: 'REMOVE_EPOCH', value: {index: 0, name: 'epoch 1'}}
|
||||
expect(stateReducer(stateWithTwoEpochs, secondAction)).toEqual({
|
||||
...state,
|
||||
epochs: [{ name: 'epoch 2', changes: ['']}]
|
||||
epochs: [{ name: 'epoch 2', changes: [''], parent: null}]
|
||||
});
|
||||
});
|
||||
|
||||
|
|
|
@ -22,43 +22,99 @@ describe('Results', () => {
|
|||
it('rule without ">" returns helpful error message', () => {
|
||||
const { phones } = initState();
|
||||
const epoch = { name: 'error epoch', changes: [ 't/n/_' ] }
|
||||
expect(decomposeRules(epoch, phones)).toEqual("Error in line 1: Insert '>' operator between target and result");
|
||||
const errorMessage = {epoch: 'error epoch', error: "Error in line 1: Insert '>' operator between target and result"};
|
||||
let receivedError;
|
||||
try {
|
||||
decomposeRules(epoch, phones)
|
||||
}
|
||||
catch (err) {
|
||||
receivedError=err;
|
||||
}
|
||||
expect(receivedError).toStrictEqual(errorMessage);
|
||||
})
|
||||
|
||||
|
||||
it('rule with too many ">" returns helpful error message', () => {
|
||||
const { phones } = initState();
|
||||
const epoch = { name: 'error epoch', changes: [ 't>n>/_' ] }
|
||||
expect(decomposeRules(epoch, phones)).toEqual("Error in line 1: Too many '>' operators");
|
||||
const errorMessage = {epoch: 'error epoch', error: "Error in line 1: Too many '>' operators"};
|
||||
let receivedError;
|
||||
try {
|
||||
decomposeRules(epoch, phones)
|
||||
}
|
||||
catch (err) {
|
||||
receivedError=err;
|
||||
}
|
||||
expect(receivedError).toStrictEqual(errorMessage);
|
||||
})
|
||||
|
||||
|
||||
it('rule without "/" returns helpful error message', () => {
|
||||
const { phones } = initState();
|
||||
const epoch = { name: 'error epoch', changes: [ 't>n_' ] }
|
||||
expect(decomposeRules(epoch, phones)).toEqual("Error in line 1: Insert '/' operator between change and environment");
|
||||
const errorMessage = {epoch: 'error epoch', error: "Error in line 1: Insert '/' operator between change and environment"};
|
||||
let receivedError;
|
||||
try {
|
||||
decomposeRules(epoch, phones)
|
||||
}
|
||||
catch (err) {
|
||||
receivedError=err;
|
||||
}
|
||||
expect(receivedError).toStrictEqual(errorMessage);
|
||||
})
|
||||
|
||||
|
||||
it('rule with too many "/" returns helpful error message', () => {
|
||||
const { phones } = initState();
|
||||
const epoch = { name: 'error epoch', changes: [ 't>n/_/' ] }
|
||||
expect(decomposeRules(epoch, phones)).toEqual("Error in line 1: Too many '/' operators");
|
||||
const errorMessage = {epoch: 'error epoch', error: "Error in line 1: Too many '/' operators"};
|
||||
let receivedError;
|
||||
try {
|
||||
decomposeRules(epoch, phones)
|
||||
}
|
||||
catch (err) {
|
||||
receivedError=err;
|
||||
}
|
||||
expect(receivedError).toStrictEqual(errorMessage);
|
||||
})
|
||||
|
||||
|
||||
it('rule without "_" returns helpful error message', () => {
|
||||
const { phones } = initState();
|
||||
const epoch = { name: 'error epoch', changes: [ 't>n/' ] }
|
||||
expect(decomposeRules(epoch, phones)).toEqual("Error in line 1: Insert '_' operator in environment");
|
||||
const errorMessage = {epoch: 'error epoch', error: "Error in line 1: Insert '_' operator in environment"};
|
||||
let receivedError;
|
||||
try {
|
||||
decomposeRules(epoch, phones)
|
||||
}
|
||||
catch (err) {
|
||||
receivedError=err;
|
||||
}
|
||||
expect(receivedError).toStrictEqual(errorMessage);
|
||||
})
|
||||
|
||||
|
||||
it('rule with too many "_" returns helpful error message', () => {
|
||||
const { phones } = initState();
|
||||
const epoch = { name: 'error epoch', changes: [ 't>n/__' ] }
|
||||
expect(decomposeRules(epoch, phones)).toEqual("Error in line 1: Too many '_' operators");
|
||||
const errorMessage = {epoch: 'error epoch', error: "Error in line 1: Too many '_' operators"};
|
||||
let receivedError;
|
||||
try {
|
||||
decomposeRules(epoch, phones)
|
||||
}
|
||||
catch (err) {
|
||||
receivedError=err;
|
||||
}
|
||||
expect(receivedError).toStrictEqual(errorMessage);
|
||||
})
|
||||
|
||||
|
||||
it('rule with incorrect feature syntax returns helpful error message', () => {
|
||||
const { phones } = initState();
|
||||
const epoch = { name: 'error epoch', changes: [ '[+ occlusive - nasal = obstruent]>n/_' ] }
|
||||
expect(decomposeRules(epoch, phones)).toEqual("Error in line 1: Unknown token '='");
|
||||
const errorMessage = {epoch: 'error epoch', error: "Error in line 1: Unknown token '='"};
|
||||
let receivedError;
|
||||
try {
|
||||
decomposeRules(epoch, phones)
|
||||
}
|
||||
catch (err) {
|
||||
receivedError=err;
|
||||
}
|
||||
expect(receivedError).toStrictEqual(errorMessage);
|
||||
})
|
||||
|
||||
it('expect transform lexeme to apply rule to lexeme', () => {
|
||||
|
|
Loading…
Reference in a new issue