patch to fix error messaging tests

This commit is contained in:
Sorrel Bri 2020-03-01 12:59:41 -08:00
parent 22b4adb547
commit c13cc33697
3 changed files with 79 additions and 22 deletions

View file

@ -39,7 +39,7 @@ const Epochs = ({epochs, errors, dispatch}) => {
} }
const renderAddEpochButton = index => { const renderAddEpochButton = index => {
if (index === epochs.length - 1 ) return ( if (epochs && index === epochs.length - 1 ) return (
<form onSubmit={e=>addEpoch(e)}> <form onSubmit={e=>addEpoch(e)}>
<input className="form form--add" type="submit" name="add-epoch" value="Add Epoch" ></input> <input className="form form--add" type="submit" name="add-epoch" value="Add Epoch" ></input>
</form> </form>
@ -48,7 +48,7 @@ const Epochs = ({epochs, errors, dispatch}) => {
} }
const renderEpochs = () => { 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 const epochError = errors.epoch ? errors.error : null
return ( return (
<div <div

View file

@ -6,7 +6,8 @@ describe('Epochs', () => {
state.epochs = [ state.epochs = [
{ {
name: 'epoch 1', name: 'epoch 1',
changes: [''] changes: [''],
parent: null
} }
] ]
}) })
@ -17,7 +18,7 @@ describe('Epochs', () => {
}); });
it('epochs addition returns new epochs list', () => { 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]}) expect(stateReducer(state, action)).toEqual({...state, epochs: [...state.epochs, action.value]})
}) })
@ -28,8 +29,8 @@ describe('Epochs', () => {
expect(stateReducer(secondState, secondAction)).toEqual( expect(stateReducer(secondState, secondAction)).toEqual(
{...state, {...state,
epochs: [ epochs: [
{name: 'proto-lang', changes: ['']}, {name: 'proto-lang', changes: [''], parent: null},
{name: 'epoch 2', changes: ['']} {name: 'epoch 2', changes: [''], parent: null}
] ]
} }
); );
@ -42,8 +43,8 @@ describe('Epochs', () => {
expect(stateReducer(secondState, secondAction)).toEqual( expect(stateReducer(secondState, secondAction)).toEqual(
{...state, {...state,
epochs: [ epochs: [
{name: 'epoch 1', changes: ['n>t/_#', '[+plosive]>[+nasal -plosive]/_n']}, {name: 'epoch 1', changes: ['n>t/_#', '[+plosive]>[+nasal -plosive]/_n'], parent: null},
{name: 'epoch 2', changes: ['']} {name: 'epoch 2', changes: [''], parent: null}
] ]
} }
); );
@ -55,7 +56,7 @@ describe('Epochs', () => {
const secondAction = {type: 'REMOVE_EPOCH', value: {index: 0, name: 'epoch 1'}} const secondAction = {type: 'REMOVE_EPOCH', value: {index: 0, name: 'epoch 1'}}
expect(stateReducer(stateWithTwoEpochs, secondAction)).toEqual({ expect(stateReducer(stateWithTwoEpochs, secondAction)).toEqual({
...state, ...state,
epochs: [{ name: 'epoch 2', changes: ['']}] epochs: [{ name: 'epoch 2', changes: [''], parent: null}]
}); });
}); });

View file

@ -22,43 +22,99 @@ describe('Results', () => {
it('rule without ">" returns helpful error message', () => { it('rule without ">" returns helpful error message', () => {
const { phones } = initState(); const { phones } = initState();
const epoch = { name: 'error epoch', changes: [ 't/n/_' ] } 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', () => { it('rule with too many ">" returns helpful error message', () => {
const { phones } = initState(); const { phones } = initState();
const epoch = { name: 'error epoch', changes: [ 't>n>/_' ] } 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', () => { it('rule without "/" returns helpful error message', () => {
const { phones } = initState(); const { phones } = initState();
const epoch = { name: 'error epoch', changes: [ 't>n_' ] } 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', () => { it('rule with too many "/" returns helpful error message', () => {
const { phones } = initState(); const { phones } = initState();
const epoch = { name: 'error epoch', changes: [ 't>n/_/' ] } 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', () => { it('rule without "_" returns helpful error message', () => {
const { phones } = initState(); const { phones } = initState();
const epoch = { name: 'error epoch', changes: [ 't>n/' ] } 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', () => { it('rule with too many "_" returns helpful error message', () => {
const { phones } = initState(); const { phones } = initState();
const epoch = { name: 'error epoch', changes: [ 't>n/__' ] } 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', () => { it('rule with incorrect feature syntax returns helpful error message', () => {
const { phones } = initState(); const { phones } = initState();
const epoch = { name: 'error epoch', changes: [ '[+ occlusive - nasal = obstruent]>n/_' ] } 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', () => { it('expect transform lexeme to apply rule to lexeme', () => {