Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(data): Refactor wordSearch and other methods for clarity and maintainability #1436

Open
wants to merge 30 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
7c94ddc
refactor(data): Refactor wordSearch to use lookup
tora-pan Feb 28, 2023
2ea4ed6
refactor(data): Remove missed console.logs
tora-pan Feb 28, 2023
e509cd3
refactor(data): Cherry pick test from other branch to follow contrib …
tora-pan Feb 28, 2023
5b7d512
refactor(data): Remove commented out code
tora-pan Feb 28, 2023
b0770b5
Revert "refactor(data): Cherry pick test from other branch to follow …
tora-pan Feb 28, 2023
1e093f1
Revert "refactor(data): Remove commented out code"
tora-pan Feb 28, 2023
fcea7eb
refactor(data): Remove accidently added file
tora-pan Feb 28, 2023
968c518
test(visual): Update baselines with new screenshots
github-actions[bot] Feb 28, 2023
ddb8635
Merge branch 'main' into refactor(data)_refactor-word-search
melink14 Mar 1, 2023
ba9349a
refactor(data): Fix regression bug and clean up test styling
tora-pan Mar 1, 2023
8415bfa
refactor(data): Fix logic causing regression and test styling
tora-pan Mar 1, 2023
912fd4a
refactor(data): Replace null type to wordSearch
tora-pan Mar 1, 2023
2f5637b
test(visual): Update baselines with new screenshots
github-actions[bot] Mar 1, 2023
35a9eb6
refactor(data): Comment out exec path for web-test-runner
tora-pan Mar 3, 2023
8b5a4ce
refactor(data): Fix logic causing regressions
tora-pan Mar 3, 2023
bea4823
Merge branch 'main' into refactor(data)_refactor-word-search
tora-pan Mar 3, 2023
5a7a430
style: Fix lint/formatting errors
github-actions[bot] Mar 3, 2023
5994c34
refactor(data): Fix merge conflicts from different stashes
tora-pan Mar 3, 2023
4cf1bee
refactor(data): Fix stashing mess
tora-pan Mar 3, 2023
f9c922c
test(visual): Update baselines with new screenshots
github-actions[bot] Mar 3, 2023
a457d52
refactor(data): Move normalizationMap to own file
tora-pan Mar 3, 2023
912fc7a
style: Fix lint/formatting errors
github-actions[bot] Mar 3, 2023
a9815b7
refactor(data): Revert deinflect method and types
tora-pan Mar 4, 2023
5e6f6d2
refactor(data): Add non kana break to hiragana conversion
tora-pan Mar 4, 2023
9e9af02
refactor(data): Fix selection regression bug, remove console log
tora-pan Mar 5, 2023
4b4ca61
test(visual): Update baselines with new screenshots
github-actions[bot] Mar 5, 2023
61878fe
refactor(data): Revert execPath for web-test-runner-config
tora-pan Mar 5, 2023
ccc8bcd
test(visual): Update baselines with new screenshots
github-actions[bot] Mar 5, 2023
92431c4
refactor(data): Add explicit check for halfWidthKatakana to converToH…
tora-pan Mar 9, 2023
448994a
Merge remote-tracking branch 'upstream/main' into refactor(data)_refa…
tora-pan Mar 12, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
414 changes: 311 additions & 103 deletions extension/data.ts

Large diffs are not rendered by default.

144 changes: 143 additions & 1 deletion extension/test/data_test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Config } from '../configuration';
import { RcxDict } from '../data';
import { DictEntryData, RcxDict } from '../data';
import { expect, use } from '@esm-bundle/chai';
import Sinon from 'sinon';
import chaiLike from 'chai-like';
import chaiThings from 'chai-things';
import sinonChrome from 'sinon-chrome';
Expand Down Expand Up @@ -63,4 +64,145 @@ describe('data.ts', function () {
).to.not.include.something.like({ entry: /^凡打 .*/ });
});
});
describe('kanjiSearch', function () {
it('should return null for kanji with char code < 0x3000', function () {
const result = rcxDict.kanjiSearch('A');
expect(result).to.be.null;
});

it('should return null if kanjiData entry is not properly formatted', function () {
const result = rcxDict.kanjiSearch('子9');
expect(result).to.be.null;
});

it('should return a DictEntryData object for valid kanji', function () {
const result: DictEntryData | null = rcxDict.kanjiSearch('日');
expect(result).to.deep.include({
kanji: '日',
eigo: 'day, sun, Japan, counter for days',
});
});

it('should set kanji property of DictEntryData object', function () {
const result = rcxDict.kanjiSearch('日');
expect(result?.kanji).to.equal('日');
});

it('should set misc property of DictEntryData object', function () {
tora-pan marked this conversation as resolved.
Show resolved Hide resolved
const result = rcxDict.kanjiSearch('日');
expect(result?.misc).to.deep.include({
tora-pan marked this conversation as resolved.
Show resolved Hide resolved
U: '65E5',
B: '72',
G: '1',
S: '4',
F: '1',
N: '2097',
V: '2410',
H: '3027',
DK: '1915',
L: '12 day',
DN: '12 day',
E: '62',
IN: '5',
P: '3-3-1',
I: '4c0.1',
Y: 'ri4',
});
});

it('should set onkun property of DictEntryData object', function () {
const result = rcxDict.kanjiSearch('日');
expect(result?.onkun).to.contain('ニチ、 ジツ、 ひ、 -び、 -か');
});

it('should set nanori property of DictEntryData object', function () {
const result = rcxDict.kanjiSearch('日');
expect(result?.nanori).to.contain(
'あ、 あき、 いる、 く、 くさ、 こう、 す、 たち、 に、 にっ、 につ、 へ'
);
});

it('should set bushumei property of DictEntryData object to empty string if null', function () {
const result = rcxDict.kanjiSearch('日');
expect(result?.bushumei).to.equal('');
});

it('should set eigo property of DictEntryData object', function () {
const result = rcxDict.kanjiSearch('日');
expect(result?.eigo).to.contain('day, sun, Japan');
});
});
describe('(fileRead)', function () {
it('should take a valid file url and return a response', function () {
const url = 'data/dict.dat';
const result = rcxDict.fileRead(url);
expect(result).to.be.a('string');
});
});
describe('(fileReadArray)', function () {
it('should call fileRead and return an array of data', function () {
const fileName = 'data/dict.dat';
const result = rcxDict.fileReadArray(fileName);
expect(result).to.be.an('array');
expect(result).to.have.lengthOf.at.least(1);
});
it('should remove any whitespace or newlines from end of array', function () {
const stub = Sinon.stub(rcxDict, 'fileReadArray').returns([
'testing',
'is',
'fun \n',
]);
const results: string[] = rcxDict.fileReadArray('someFile/here');
expect(results).to.be.an('array');
expect(results[results.length - 1].endsWith(' ')).to.be.false;
Sinon.assert.calledOnce(stub);
});
});
describe('(loadNames)', function () {
it('should load name dictionary information if not loaded already', function () {
// set nameDict to true or initiate and confirm that rcxDict.nameDict/Index is set.
rcxDict.nameDict = '';
rcxDict.nameIndex = '';
expect(rcxDict.nameDict).to.equal('');
expect(rcxDict.nameIndex).to.equal('');
rcxDict.loadNames();
expect(rcxDict.nameDict).to.exist;
expect(rcxDict.nameIndex).to.exist;
});
});
describe('isKana', function () {
it('should return true if charCode is a kana character', function () {
const kanaCode = 'て'.charCodeAt(0);
console.log(kanaCode);
expect(rcxDict.isKana(kanaCode)).to.be.true;
});
it('should return false if non kana character is searched', function () {
const nonKanaCode = 'Test'.charCodeAt(0);
expect(rcxDict.isKana(nonKanaCode)).to.be.false;
});
});
describe('convertToHiragana', function () {
it('should return hiragana character when passed half-width katakana', function () {
const kanaCode = 'テスト'.charCodeAt(0);
console.log(kanaCode);
expect(rcxDict.isKana(kanaCode)).to.be.true;
});
it('should return hiragana character when passed full-width katakana', function () {
const nonKanaCode = 'Test'.charCodeAt(0);
expect(rcxDict.isKana(nonKanaCode)).to.be.false;
});
it('should do correct hiragana lookup when parsing voiced and semi-voiced half-width katakana', function () {
// const expected = 'デッスクトップ'
const expected = 'ポジティブ';
expect(rcxDict.convertToHiragana(expected)).to.equal('ぽじてぃぶ');
});
});

// describe('(makeHtmlForRuby)', function () {
// it('should take a valid file url and return a response', function () {});
// });
// describe('(makeText)', function () {
// it('should return a string of data when given a valid kanji entry', function () {});
// it('should return and empty string when entry is null', function () {});
// });
});
Binary file modified screenshots/Chromium/baseline/ignoring-external-styles.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified screenshots/Chromium/baseline/name-entries-black.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified screenshots/Chromium/baseline/name-entries-blue.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified screenshots/Chromium/baseline/name-entries-lightblue.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified screenshots/Chromium/baseline/name-entries-yellow.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified screenshots/Chromium/baseline/title-translation-black.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified screenshots/Chromium/baseline/title-translation-blue.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified screenshots/Chromium/baseline/title-translation-lightblue.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified screenshots/Chromium/baseline/title-translation-yellow.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.