Skip to content

Commit

Permalink
Bugfix 570 / Fix highlighting errors with right quote in Greek Word (#…
Browse files Browse the repository at this point in the history
…181)

* useSelections fix useEffect dependencies and add more checking

* update dependencies

* update dependencies

* v5.5.7-beta.3

* cleanup

* update dependency for tc-ui-toolkit

* fixing unit tests

* fixing unit tests

* fixing unit tests

* fixing unit tests

* fixing unit tests

* fixing unit tests

* merge master

* bump version

* fix to make scripture selection easier.

* Revert "fix to make scripture selection easier."

This reverts commit b3c9bb4.

---------

Co-authored-by: PhotoNomad0 <[email protected]>
  • Loading branch information
PhotoNomad0 and PhotoNomad0 authored Dec 4, 2023
1 parent f5da0e4 commit 07d5069
Show file tree
Hide file tree
Showing 9 changed files with 120 additions and 80 deletions.
14 changes: 14 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
.yalc/
.vscode/
.idea/
.editorconfig
**/__tests__/
coverage/
cypress/
node_modules/
scripts/
src/
styleguide.config.js
styleguide.styles.js
styleguide/
yalc.lock
13 changes: 12 additions & 1 deletion __tests__/fixtures/highlighting/tit/1-1-3.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,16 @@ module.exports = {
verse: 1,
quote: "Θεοῦ & ἀπόστολος",
occurrence: -1,
expected: [],
expected: [
{
"occurrence": 1,
"occurrences": 2,
"text": "Θεοῦ",
},
{
"occurrence": 1,
"occurrences": 1,
"text": "ἀπόστολος",
},
],
};
8 changes: 7 additions & 1 deletion __tests__/greek-highlighting-helpers.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import deepEqual from 'deep-equal';
import ugnt_tit from './fixtures/books/ugnt_tit.js';
import ugnt_3jn from './fixtures/books/ugnt_3jn.js';
import ugnt_php from './fixtures/books/ugnt_php.js';
import { flattenVerseObjects } from "../src/core";

describe('selectionHelpers.selectionsFromQuoteAndVerseObjects PHP', () => {
it('should have all words highlighted PHP 2:1', () => {
Expand Down Expand Up @@ -146,7 +147,12 @@ function generateTest(fileName) {
}

const { verseObjects } = books[bookName].chapters[chapter][verse];
const selections = selectionsFromQuoteAndVerseObjects({ quote, verseObjects, occurrence });
const _verseObjects = flattenVerseObjects(verseObjects);
const verseObjectsMap = new Map();
let ref = `${chapter}:${verse}`;
verseObjectsMap.set(ref, _verseObjects);
const selections_ = selectionsFromQuoteAndVerseObjects({ quote, verseObjectsMap, occurrence });
const selections = selections_.get(ref) || [];

// log details to console if there is a miscompare of data
if (!deepEqual(selections, expected)) {
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "scripture-resources-rcl",
"description": "A React Component Library for Rendering Scripture Resources.",
"version": "5.5.7",
"version": "5.5.8",
"homepage": "https://scripture-resources-rcl.netlify.com/",
"repository": {
"type": "git",
Expand Down Expand Up @@ -44,11 +44,11 @@
"nyc": "^15.0.0-beta.3",
"prop-types": "^15.8.1",
"react-waypoint": "^9.0.2",
"string-punctuation-tokenizer": "2.1.2",
"string-punctuation-tokenizer": "^2.2.0",
"tc-ui-toolkit": "^5.3.3",
"use-deep-compare-effect": "^1.3.1",
"usfm-js": "^3.4.2",
"uw-quote-helpers": "^1.0.0",
"uw-quote-helpers": "^1.1.0",
"word-aligner": "^1.0.0",
"xregexp": "^4.1.1"
},
Expand Down
5 changes: 1 addition & 4 deletions src/components/parallel-scripture/ParallelScripture.spec.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
import React from "react";
import { TextField } from "@material-ui/core";
import {
ParallelScripture,
ResourcesContextProvider,
} from "scripture-resources-rcl";
import { resourceFromResourceLink } from "../../core";

// To do: Implement a new strategy for how to test functional components
// - probably by using React Testing Library instead of Enzyme
Expand Down
8 changes: 4 additions & 4 deletions src/components/selections/useSelections.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ function useSelections({

useDeepCompareEffectNoCheck(() => {
try {
const _selections = bookObject ? getQuoteMatchesInBookRef({
const _selections = quote && refString && bookObject ? getQuoteMatchesInBookRef({
quote,
ref: refString,
bookObject,
Expand All @@ -28,7 +28,7 @@ function useSelections({
} catch (error) {
console.error(`Selections broken:\n`, error);
}
}, [quote, currentOccurrenceValue, bookObject]);
}, [quote, currentOccurrenceValue, bookObject, refString]);

useDeepCompareEffectNoCheck(() => {
if (bookObject && onQuote) {
Expand Down Expand Up @@ -108,11 +108,11 @@ useSelections.propTypes = {
onSelections: PropTypes.func.isRequired,
/** the quote to be selected */
quote: PropTypes.string.isRequired,
/** all chapter-verses where quote may be found */
/** all chapter-verses where quote may be found - note this is either original language bible or aligned bible */
bookObject: PropTypes.object,
/** string chapter-verse reference. i.e. 1:5-6 */
refString: PropTypes.string,
/** if quote occurs mulitple times, this is the occurence of the one selected */
/** if quote occurs mulitple times, this is the occurrence of the one selected */
occurrence: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
/** action taken when quote is provided */
onQuote: PropTypes.func,
Expand Down
2 changes: 1 addition & 1 deletion src/core/selections/selections.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export const selectionsFromQuoteAndVerseObjects = ({
}) => {
let selections = new Map();
let stringMap = new Map();
stringMap = verseObjectsToString(verseObjectsMap);
stringMap = verseObjectsToString(verseObjectsMap);
selections = selectionsFromQuoteAndString({ quote, stringMap, occurrence });
return selections;
};
Expand Down
103 changes: 61 additions & 42 deletions src/core/selections/selections.spec.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import {
selectionsFromQuoteAndString,
generateSelection,
getPrecedingText,
normalizeString,
selectionsFromQuoteAndString,
} from "./selections";

const normalizedText = (arr) => arr.map( obj => {
Expand All @@ -12,15 +12,23 @@ const normalizedText = (arr) => arr.map( obj => {
}
})

function createStringMap(ref, rawString) {
const stringMap = new Map();
stringMap.set(ref, rawString);
return stringMap;
}

describe("selectionsFromQuoteAndString", () => {
const ref = '1:2';

it("phrase at beginning", () => {
const input = {
quote: "ἐν ἀρχῇ ἦν",
string:
"ἐν ἀρχῇ ἦν ὁ λόγος, καὶ ὁ λόγος ἦν πρὸς τὸν Θεόν, καὶ Θεὸς ἦν ὁ λόγος.",
stringMap: createStringMap(ref,
"ἐν ἀρχῇ ἦν ὁ λόγος, καὶ ὁ λόγος ἦν πρὸς τὸν Θεόν, καὶ Θεὸς ἦν ὁ λόγος."),
occurrence: 1,
};
const output = selectionsFromQuoteAndString(input);
const output = selectionsFromQuoteAndString(input).get(ref);
const expected = [
{ text: "ἐν", occurrence: 1, occurrences: 1 },
{ text: "ἀρχῇ", occurrence: 1, occurrences: 1 },
Expand All @@ -32,11 +40,11 @@ describe("selectionsFromQuoteAndString", () => {
it("all occurrences -1", () => {
const input = {
quote: "καὶ",
string:
"διὰ τοῦτο, ἐὰν ἔλθω, ὑπομνήσω αὐτοῦ τὰ ἔργα, ἃ ποιεῖ, λόγοις πονηροῖς φλυαρῶν ἡμᾶς; καὶ μὴ ἀρκούμενος ἐπὶ τούτοις, οὔτε αὐτὸς ἐπιδέχεται τοὺς ἀδελφοὺς, καὶ τοὺς βουλομένους κωλύει, καὶ ἐκ τῆς ἐκκλησίας ἐκβάλλει.",
stringMap: createStringMap(ref,
"διὰ τοῦτο, ἐὰν ἔλθω, ὑπομνήσω αὐτοῦ τὰ ἔργα, ἃ ποιεῖ, λόγοις πονηροῖς φλυαρῶν ἡμᾶς; καὶ μὴ ἀρκούμενος ἐπὶ τούτοις, οὔτε αὐτὸς ἐπιδέχεται τοὺς ἀδελφοὺς, καὶ τοὺς βουλομένους κωλύει, καὶ ἐκ τῆς ἐκκλησίας ἐκβάλλει."),
occurrence: -1,
};
const output = selectionsFromQuoteAndString(input);
const output = selectionsFromQuoteAndString(input).get(ref);
const expected = [
{ text: "καὶ", occurrence: 1, occurrences: 3 },
{ text: "καὶ", occurrence: 2, occurrences: 3 },
Expand All @@ -48,23 +56,34 @@ describe("selectionsFromQuoteAndString", () => {
it("skip -1 with ampersand", () => {
const input = {
quote: "καὶ & μὴ",
string:
"διὰ τοῦτο, ἐὰν ἔλθω, ὑπομνήσω αὐτοῦ τὰ ἔργα, ἃ ποιεῖ, λόγοις πονηροῖς φλυαρῶν ἡμᾶς; καὶ μὴ ἀρκούμενος ἐπὶ τούτοις, οὔτε αὐτὸς ἐπιδέχεται τοὺς ἀδελφοὺς, καὶ τοὺς βουλομένους κωλύει, καὶ ἐκ τῆς ἐκκλησίας ἐκβάλλει.",
stringMap: createStringMap(ref,
"διὰ τοῦτο, ἐὰν ἔλθω, ὑπομνήσω αὐτοῦ τὰ ἔργα, ἃ ποιεῖ, λόγοις πονηροῖς φλυαρῶν ἡμᾶς; καὶ μὴ ἀρκούμενος ἐπὶ τούτοις, οὔτε αὐτὸς ἐπιδέχεται τοὺς ἀδελφοὺς, καὶ τοὺς βουλομένους κωλύει, καὶ ἐκ τῆς ἐκκλησίας ἐκβάλλει."),
occurrence: -1,
};
const output = selectionsFromQuoteAndString(input);
const expected = [];
const output = selectionsFromQuoteAndString(input).get(ref);
const expected = [
{
"occurrence": 1,
"occurrences": 3,
"text": "καὶ"
},
{
"occurrence": 1,
"occurrences": 1,
"text": "μὴ"
}
];
expect(output).toStrictEqual(normalizedText(expected));
});

it("ampersand: repeated word", () => {
const input = {
quote: "Θεοῦ & Θεοῦ",
string:
"Παῦλος, δοῦλος Θεοῦ, ἀπόστολος δὲ Ἰησοῦ Χριστοῦ, κατὰ πίστιν ἐκλεκτῶν Θεοῦ, καὶ ἐπίγνωσιν ἀληθείας, τῆς κατ’ εὐσέβειαν",
stringMap: createStringMap(ref,
"Παῦλος, δοῦλος Θεοῦ, ἀπόστολος δὲ Ἰησοῦ Χριστοῦ, κατὰ πίστιν ἐκλεκτῶν Θεοῦ, καὶ ἐπίγνωσιν ἀληθείας, τῆς κατ’ εὐσέβειαν"),
occurrence: 1,
};
const output = selectionsFromQuoteAndString(input);
const output = selectionsFromQuoteAndString(input).get(ref);
const expected = [
{ text: "Θεοῦ", occurrence: 1, occurrences: 2 },
{ text: "Θεοῦ", occurrence: 2, occurrences: 2 },
Expand All @@ -75,11 +94,11 @@ describe("selectionsFromQuoteAndString", () => {
it("ampersand: repeating ending word preceding first.", () => {
const input = {
quote: "Θεὸς & λόγος",
string:
"ἐν ἀρχῇ ἦν ὁ λόγος, καὶ ὁ λόγος ἦν πρὸς τὸν Θεόν, καὶ Θεὸς ἦν ὁ λόγος.",
stringMap: createStringMap(ref,
"ἐν ἀρχῇ ἦν ὁ λόγος, καὶ ὁ λόγος ἦν πρὸς τὸν Θεόν, καὶ Θεὸς ἦν ὁ λόγος."),
occurrence: 1,
};
const output = selectionsFromQuoteAndString(input);
const output = selectionsFromQuoteAndString(input).get(ref);
const expected = [
{ text: "Θεὸς", occurrence: 1, occurrences: 1 },
{ text: "λόγος", occurrence: 3, occurrences: 3 },
Expand All @@ -90,26 +109,26 @@ describe("selectionsFromQuoteAndString", () => {
it("ampersand: repeating ending word preceding first.", () => {
const input = {
quote: "Θεὸς & λόγος",
string:
"ἐν ἀρχῇ ἦν ὁ λόγος, καὶ Θεὸς ὁ λόγος ἦν πρὸς τὸν Θεόν, καὶ Θεὸς ἦν ὁ λόγος.",
stringMap: createStringMap(ref,
"ἐν ἀρχῇ ἦν ὁ λόγος, καὶ Θεὸς ὁ λόγος ἦν πρὸς τὸν Θεόν, καὶ Θεὸς ἦν ὁ λόγος."),
occurrence: 2,
};
const output = selectionsFromQuoteAndString(input);
const output = selectionsFromQuoteAndString(input).get(ref);
const expected = [
{ text: "Θεὸς", occurrence: 2, occurrences: 2 },
{ text: "λόγος", occurrence: 3, occurrences: 3 },
{ text: "Θεὸς", occurrence: 1, occurrences: 2 },
{ text: "λόγος", occurrence: 2, occurrences: 3 },
];
expect(output).toStrictEqual(normalizedText(expected));
});

it("ampersand: simple, short", () => {
const input = {
quote: "ὁ λόγος & πρὸς",
string:
"ἐν ἀρχῇ ἦν ὁ λόγος, καὶ ὁ λόγος ἦν πρὸς τὸν Θεόν, καὶ Θεὸς ἦν ὁ λόγος.",
stringMap: createStringMap(ref,
"ἐν ἀρχῇ ἦν ὁ λόγος, καὶ ὁ λόγος ἦν πρὸς τὸν Θεόν, καὶ Θεὸς ἦν ὁ λόγος."),
occurrence: 1,
};
const output = selectionsFromQuoteAndString(input);
const output = selectionsFromQuoteAndString(input).get(ref);
const expected = [
{ text: "ὁ", occurrence: 1, occurrences: 3 },
{ text: "λόγος", occurrence: 1, occurrences: 3 },
Expand All @@ -121,11 +140,11 @@ describe("selectionsFromQuoteAndString", () => {
it("ampersand: first occurrence of repeated quote", () => {
const input = {
quote: "ὁ λόγος & Θεόν",
string:
"ἐν ἀρχῇ ἦν ὁ λόγος, καὶ ὁ λόγος ἦν πρὸς τὸν Θεόν, καὶ Θεὸς ἦν ὁ λόγος.",
stringMap: createStringMap(ref,
"ἐν ἀρχῇ ἦν ὁ λόγος, καὶ ὁ λόγος ἦν πρὸς τὸν Θεόν, καὶ Θεὸς ἦν ὁ λόγος."),
occurrence: 1,
};
const output = selectionsFromQuoteAndString(input);
const output = selectionsFromQuoteAndString(input).get(ref);
const expected = [
{ text: "ὁ", occurrence: 1, occurrences: 3 },
{ text: "λόγος", occurrence: 1, occurrences: 3 },
Expand All @@ -137,14 +156,14 @@ describe("selectionsFromQuoteAndString", () => {
it("ampersand: second occurrence of repeated quote", () => {
const input = {
quote: "ὁ λόγος & Θεόν",
string:
"ἐν ἀρχῇ ἦν ὁ λόγος, καὶ ὁ λόγος ἦν πρὸς τὸν Θεόν, καὶ Θεὸς ἦν ὁ λόγος.",
stringMap: createStringMap(ref,
"ἐν ἀρχῇ ἦν ὁ λόγος, καὶ ὁ λόγος ἦν πρὸς τὸν Θεόν, καὶ Θεὸς ἦν ὁ λόγος."),
occurrence: 2,
};
const output = selectionsFromQuoteAndString(input);
const output = selectionsFromQuoteAndString(input).get(ref);
const expected = [
{ text: "ὁ", occurrence: 2, occurrences: 3 },
{ text: "λόγος", occurrence: 2, occurrences: 3 },
{ text: "ὁ", occurrence: 1, occurrences: 3 },
{ text: "λόγος", occurrence: 1, occurrences: 3 },
{ text: "Θεόν", occurrence: 1, occurrences: 1 },
];
expect(output).toStrictEqual(normalizedText(expected));
Expand All @@ -153,11 +172,11 @@ describe("selectionsFromQuoteAndString", () => {
it("repeated phrase: first occurrence", () => {
const input = {
quote: "ὁ λόγος",
string:
"ἐν ἀρχῇ ἦν ὁ λόγος, καὶ ὁ λόγος ἦν πρὸς τὸν Θεόν, καὶ Θεὸς ἦν ὁ λόγος.",
stringMap: createStringMap(ref,
"ἐν ἀρχῇ ἦν ὁ λόγος, καὶ ὁ λόγος ἦν πρὸς τὸν Θεόν, καὶ Θεὸς ἦν ὁ λόγος."),
occurrence: 1,
};
const output = selectionsFromQuoteAndString(input);
const output = selectionsFromQuoteAndString(input).get(ref);
const expected = [
{ text: "ὁ", occurrence: 1, occurrences: 3 },
{ text: "λόγος", occurrence: 1, occurrences: 3 },
Expand All @@ -168,11 +187,11 @@ describe("selectionsFromQuoteAndString", () => {
it("repeated phrase: second occurrence", () => {
const input = {
quote: "ὁ λόγος",
string:
"ἐν ἀρχῇ ἦν ὁ λόγος, καὶ ὁ λόγος ἦν πρὸς τὸν Θεόν, καὶ Θεὸς ἦν ὁ λόγος.",
stringMap: createStringMap(ref,
"ἐν ἀρχῇ ἦν ὁ λόγος, καὶ ὁ λόγος ἦν πρὸς τὸν Θεόν, καὶ Θεὸς ἦν ὁ λόγος."),
occurrence: 2,
};
const output = selectionsFromQuoteAndString(input);
const output = selectionsFromQuoteAndString(input).get(ref);
const expected = [
{ text: "ὁ", occurrence: 2, occurrences: 3 },
{ text: "λόγος", occurrence: 2, occurrences: 3 },
Expand All @@ -183,11 +202,11 @@ describe("selectionsFromQuoteAndString", () => {
it("repeated phrase: last occurrence", () => {
const input = {
quote: "ὁ λόγος",
string:
"ἐν ἀρχῇ ἦν ὁ λόγος, καὶ ὁ λόγος ἦν πρὸς τὸν Θεόν, καὶ Θεὸς ἦν ὁ λόγος.",
stringMap: createStringMap(ref,
"ἐν ἀρχῇ ἦν ὁ λόγος, καὶ ὁ λόγος ἦν πρὸς τὸν Θεόν, καὶ Θεὸς ἦν ὁ λόγος."),
occurrence: 3,
};
const output = selectionsFromQuoteAndString(input);
const output = selectionsFromQuoteAndString(input).get(ref);
const expected = [
{ text: "ὁ", occurrence: 3, occurrences: 3 },
{ text: "λόγος", occurrence: 3, occurrences: 3 },
Expand Down
Loading

0 comments on commit 07d5069

Please sign in to comment.