From a19102f82e874bd77bb3359ebdd9dfee1445f225 Mon Sep 17 00:00:00 2001 From: Sorrel Bri Date: Sun, 16 Feb 2020 18:28:43 -0800 Subject: [PATCH] display results of run in Output component --- src/PhonoChangeApplier.js | 4 ++-- src/components/Output.js | 3 ++- src/components/Output.test.js | 2 +- src/reducers/reducer.init.js | 12 ++++++------ src/reducers/reducer.results.js | 6 +++--- src/reducers/reducer.results.test.js | 28 ++++++++++++++++++++++------ 6 files changed, 36 insertions(+), 19 deletions(-) diff --git a/src/PhonoChangeApplier.js b/src/PhonoChangeApplier.js index 54ff38b..d68d48c 100644 --- a/src/PhonoChangeApplier.js +++ b/src/PhonoChangeApplier.js @@ -82,8 +82,8 @@ const PhonoChangeApplier = () => { } startingIndex = index; }) - lexemeBundle.unshift(['#']) - lexemeBundle.push(['#']) + // lexemeBundle.unshift(['#']) + // lexemeBundle.push(['#']) lexicalFeatureBundles.push(lexemeBundle); }) console.log(lexicalFeatureBundles) diff --git a/src/components/Output.js b/src/components/Output.js index 9c9e5e9..6861213 100644 --- a/src/components/Output.js +++ b/src/components/Output.js @@ -2,12 +2,13 @@ import React from 'react'; import './Output.scss'; const Output = props => { + const { results } = props; return (

Results of Run

- {props.results ? props.results.map((lexicalItem, i) =>

{lexicalItem}

) : <>} + {results && results.length ? results[0].lexicon.map((lexicalItem, i) =>

{lexicalItem}

) : <>}
); diff --git a/src/components/Output.test.js b/src/components/Output.test.js index a5de8c7..942226b 100644 --- a/src/components/Output.test.js +++ b/src/components/Output.test.js @@ -20,7 +20,7 @@ describe('Output', () => { }); it('renders output lexicon list from output hook', () => { - const { getByTestId } = render(); + const { getByTestId } = render(); expect(getByTestId('Output-lexicon')).toContainHTML('

word

lex

word

'); }); diff --git a/src/reducers/reducer.init.js b/src/reducers/reducer.init.js index 52ee767..5da2a86 100644 --- a/src/reducers/reducer.init.js +++ b/src/reducers/reducer.init.js @@ -11,12 +11,12 @@ export const initState = (changesArgument: number = -1): stateType => { { name: 'epoch 1', changes: [ - '[+ occlusive - nasal]>[+ occlusive nasal]/n_.', - 'at>ta/._#', - '[+ sonorant - low rounded high back]>0/._.', - 'nn>nun/._.', - '[+ nasal][+ obstruent]>[+ nasal obstruent aspirated ]/#_.', - '[+ sonorant rounded]>[+ sonorant - rounded]/._#' + '[+ occlusive - nasal]>[+ occlusive + nasal]/n_.', + // 'at>ta/._#', + // '[+ sonorant - low rounded high back]>0/._.', + // 'nn>nun/._.', + // '[+ nasal][+ obstruent]>[+ nasal obstruent aspirated ]/#_.', + // '[+ sonorant rounded]>[+ sonorant - rounded]/._#' ] } ], diff --git a/src/reducers/reducer.results.js b/src/reducers/reducer.results.js index 53c8e71..344495d 100644 --- a/src/reducers/reducer.results.js +++ b/src/reducers/reducer.results.js @@ -192,10 +192,10 @@ export const run = (state: stateType, action: resultsAction): stateType => { const passResults = transformLexicon(lexiconBundle)(ruleBundle)(features); const stringifiedPassResults = passResults.map(stringifyResults); - const pass = { + const pass = { pass: epoch.name, - results: stringifiedPassResults + lexicon: stringifiedPassResults } - return {...state, results: pass } + return {...state, results: [pass] } } \ No newline at end of file diff --git a/src/reducers/reducer.results.test.js b/src/reducers/reducer.results.test.js index c69b4d3..cfdaa6b 100644 --- a/src/reducers/reducer.results.test.js +++ b/src/reducers/reducer.results.test.js @@ -89,12 +89,28 @@ describe('Results', () => { it('results returned from first sound change rule', () => { const action = {type: 'RUN'}; state = initState(0) - expect(stateReducer(state, action).results).toEqual({ - pass: 'epoch 1', - results: [ - 'anna', 'anat', 'anət', 'anna', 'tan', 'ənna' - ] - }) + expect(stateReducer(state, action).results).toEqual([ + { + pass: 'epoch 1', + lexicon: [ + 'anna', 'anat', 'anət', 'anna', 'tan', 'ənna' + ] + } + ]); + }); + + if('results returned from sound change suite', () => { + const action = {type: 'RUN'}; + state = initState() + console.log(stateReducer(state, action).results) + expect(stateReducer(state, action).results).toEqual([ + { + pass: 'epoch 1', + lexicon: [ + 'anna', 'anat', 'anət', 'anna', 'tan', 'ənna' + ] + } + ]); }); }); \ No newline at end of file