fix Features test, clear Features cruft
This commit is contained in:
parent
5d98f91b0f
commit
9a8563ebd7
2 changed files with 10 additions and 38 deletions
|
@ -29,39 +29,6 @@ const parsePhonesFromFeatureObject = featureObject => {
|
||||||
}
|
}
|
||||||
|
|
||||||
const featureMap = getFeatureMap(featureObject);
|
const featureMap = getFeatureMap(featureObject);
|
||||||
console.log(featureMap)
|
|
||||||
const featureMapJSX = getFeatureMapJSX(featureMap);
|
|
||||||
return featureMapJSX;
|
|
||||||
}
|
|
||||||
|
|
||||||
const parseFeaturesFromPhonemeObject = phonesObject => {
|
|
||||||
|
|
||||||
const getFeatureMap = (phonesObject) => {
|
|
||||||
return Object.keys(phonesObject).reduce((featureObject, phoneName) => {
|
|
||||||
let phone = phonesObject[phoneName];
|
|
||||||
Object.keys(phone.features).forEach(feature => {
|
|
||||||
if (!featureObject[feature]) featureObject[feature] = {plus: [], minus: []}
|
|
||||||
if (phone.features[feature]) featureObject[feature].plus.push(phone.grapheme)
|
|
||||||
else featureObject[feature].minus.push(phone.grapheme)
|
|
||||||
});
|
|
||||||
return featureObject;
|
|
||||||
}, {})
|
|
||||||
}
|
|
||||||
|
|
||||||
const getFeatureMapJSX = (featureMap) => {
|
|
||||||
return Object.keys(featureMap).map(feature => {
|
|
||||||
const plusPhones = featureMap[feature].plus.join('|');
|
|
||||||
const minusPhones = featureMap[feature].minus.join('|');
|
|
||||||
return (
|
|
||||||
<li key={`feature__${feature}`}>
|
|
||||||
<span className="plus-phones">{`[+ ${feature}] = ${plusPhones}`}</span>
|
|
||||||
<span className="minus-phones">{`[- ${feature}] = ${minusPhones}`}</span>
|
|
||||||
</li>
|
|
||||||
)
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
const featureMap = getFeatureMap(phonesObject);
|
|
||||||
const featureMapJSX = getFeatureMapJSX(featureMap);
|
const featureMapJSX = getFeatureMapJSX(featureMap);
|
||||||
return featureMapJSX;
|
return featureMapJSX;
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,11 +20,16 @@ describe('Features', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('renders features from phonemes hook', () => {
|
it('renders features from phonemes hook', () => {
|
||||||
const { getByTestId } = render(<Features phones={
|
const nPhone = {n:{
|
||||||
{n:{
|
grapheme: 'n',
|
||||||
grapheme: 'n',
|
features: { nasal: true, occlusive: true, vowel: false } }}
|
||||||
features: { nasal: true, occlusive: true, vowel: false } }}
|
const { getByTestId } = render(<Features phones={{nPhone}}
|
||||||
}/>);
|
features={{
|
||||||
|
nasal: {positive: [nPhone.n], negative: []},
|
||||||
|
occlusive:{ positive: [nPhone.n], negative:[]},
|
||||||
|
vowel:{positive: [], negative: [nPhone.n]}
|
||||||
|
}}
|
||||||
|
/>);
|
||||||
|
|
||||||
expect(getByTestId('Features-list'))
|
expect(getByTestId('Features-list'))
|
||||||
.toContainHTML('<ul class="Features__list" data-testid="Features-list"><li><span class="plus-phones">[+ nasal] = n</span><span class="minus-phones">[- nasal] = </span></li><li><span class="plus-phones">[+ occlusive] = n</span><span class="minus-phones">[- occlusive] = </span></li><li><span class="plus-phones">[+ vowel] = </span><span class="minus-phones">[- vowel] = n</span></li></ul>');
|
.toContainHTML('<ul class="Features__list" data-testid="Features-list"><li><span class="plus-phones">[+ nasal] = n</span><span class="minus-phones">[- nasal] = </span></li><li><span class="plus-phones">[+ occlusive] = n</span><span class="minus-phones">[- occlusive] = </span></li><li><span class="plus-phones">[+ vowel] = </span><span class="minus-phones">[- vowel] = n</span></li></ul>');
|
||||||
|
|
Loading…
Reference in a new issue