reference-index.test.ts 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. import { expect } from 'chai'
  2. import { ReferenceIndex } from '@/features/ide-react/references/reference-index'
  3. class TestedReferenceIndex extends ReferenceIndex {
  4. updateIndex(): void {
  5. throw new Error('This is a test implementation')
  6. }
  7. }
  8. describe('ReferenceIndex', function () {
  9. beforeEach(function () {
  10. this.index = new TestedReferenceIndex()
  11. })
  12. describe('parseEntries', function () {
  13. it('should parse bib entry', function () {
  14. const content = `
  15. @article{sample2023,
  16. author = {John Doe},
  17. title = {Sample Title},
  18. journal = {Sample Journal},
  19. year = {2023},
  20. date = {2023-01-01}
  21. }
  22. `
  23. const entries = this.index.parseEntries(content)
  24. expect(entries).to.have.lengthOf(1)
  25. expect(entries[0]).to.deep.equal({
  26. EntryKey: 'sample2023',
  27. EntryType: 'article',
  28. Fields: {
  29. author: 'John Doe',
  30. title: 'Sample Title',
  31. journal: 'Sample Journal',
  32. year: '2023',
  33. date: '2023-01-01',
  34. },
  35. ObjectType: 'entry',
  36. })
  37. })
  38. it('should default missing fields to empty strings', function () {
  39. const content = `@article{sample2023,
  40. author = {John Doe},
  41. title = {Sample Title}
  42. }`
  43. const entries = this.index.parseEntries(content)
  44. expect(entries).to.have.lengthOf(1)
  45. expect(entries[0]).to.deep.equal({
  46. EntryKey: 'sample2023',
  47. EntryType: 'article',
  48. Fields: {
  49. author: 'John Doe',
  50. title: 'Sample Title',
  51. journal: '',
  52. year: '',
  53. date: '',
  54. },
  55. ObjectType: 'entry',
  56. })
  57. })
  58. it('should handle multiple entries', function () {
  59. const content = `@article{sample2023,
  60. author = {John Doe},
  61. title = {Sample Title},
  62. journal = {Sample Journal},
  63. year = {2023},
  64. date = {2023-01-01}
  65. }
  66. @book{example2022,
  67. author = {Jane Smith},
  68. title = {Example Book},
  69. journal = {Example Journal},
  70. year = {2022},
  71. date = {2022-05-15}
  72. }`
  73. const entries = this.index.parseEntries(content)
  74. expect(entries).to.have.lengthOf(2)
  75. expect(entries[0].EntryKey).to.equal('sample2023')
  76. expect(entries[1].EntryKey).to.equal('example2022')
  77. })
  78. })
  79. })