-
Notifications
You must be signed in to change notification settings - Fork 2
feat: fromFile function add #5
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -29,6 +29,16 @@ class Glossary { | |
| this._entries[term] = description | ||
| } | ||
|
|
||
| fromFile (filename) { | ||
| let glossary = require(filename) | ||
| assert(Object.keys(glossary).length, 'The file seems to be empty') | ||
| glossary.forEach(term => { | ||
| assert(term, 'Term or description not found') | ||
| this.add(term[0], term[1]) | ||
| }) | ||
| this._entries = glossary | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| } | ||
|
|
||
| get entries () { | ||
| return this._entries | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -64,6 +64,22 @@ describe('glossary.add()', () => { | |
| }) | ||
| }) | ||
|
|
||
| describe('glossary.fromFile()', () => { | ||
| const glossary = Glossary({project: 'bar', crowdinKey: 'xyz'}) | ||
|
|
||
| test('is empty', () => { | ||
| expect(() => { | ||
| glossary.fromFile('./test/empty-file.json') | ||
| }).toThrow('The file seems to be empty') | ||
| }) | ||
|
|
||
| test('upload from a file', () => { | ||
| expect(() => { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should be something like: glossary.fromFile('./test/glossary_test.json')
expect(glossary.entries.length).toEq(2) |
||
| glossary.fromFile('./test/glossary_test.json') | ||
| }) | ||
| }) | ||
| }) | ||
|
|
||
| describe('glossary.webpage', () => { | ||
| test('is a crowdin URL', () => { | ||
| const glossary = Glossary({project: 'foo-bar', crowdinKey: 'xyz'}) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The docs and the implementation expect an array of arrays, not an object. |
||
|
|
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should also be an array, not an object. |
||
| "something": "this is something", | ||
| "other": "this is other" | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
assertis not necessary. This is already handled by theaddmethod.