Skip to main content

Add test for fic with multiple fandoms

ID
d0297a3
date
2025-01-29 20:58:29+00:00
author
Alex Chan <alex@alexwlchan.net>
parent
30878bb
message
Add test for fic with multiple fandoms
changed files
3 files, 32 additions, 11 deletions

Changed files

static/app.js (14757 → 14788)

diff --git a/static/app.js b/static/app.js
index c395ad3..f055a23 100644
--- a/static/app.js
+++ b/static/app.js
@@ -147,7 +147,7 @@ async function getKeyFicInfo(zip) {
   //
   const fandom =
     Array.from(firstHtmlDoc.querySelectorAll('dt'))
-      .find(dt => dt.innerText === 'Fandom:')
+      .find(dt => dt.innerText === 'Fandom:' || dt.innerText === 'Fandoms:')
       .nextSibling
       .nextSibling
       .innerText;

test/app.js (1853 → 2491)

diff --git a/test/app.js b/test/app.js
index 9c3e8f8..f3913ab 100644
--- a/test/app.js
+++ b/test/app.js
@@ -1,25 +1,46 @@
 QUnit.module('getKeyFicInfo', () => {
-  QUnit.test('it finds the key info from one of my fics', (assert) => {
+  function assertGetsTheRightKeyInfo(assert, path, expectedInfo) {
     const done = assert.async();
     
-    JSZipUtils.getBinaryContent('test/fixtures/Operation_Cameo.epub', function(err, data) {
+    JSZipUtils.getBinaryContent(path, function(err, data) {
       if (err) {
         throw err;
       }
 
       JSZip.loadAsync(data).then(async function (zip) {
         const ficInfo = await getKeyFicInfo(zip);
-        assert.deepEqual(
-          ficInfo,
-          {
-            title: 'Operation Cameo',
-            author: 'alexwlchan',
-            fandom: 'Operation Mincemeat: A New Musical - SpitLip',
-          }
-        );
+        assert.deepEqual(ficInfo, expectedInfo);
         done();
       });
     });
+  }
+  
+  // This EPUB file was downloaded from one of my fics,
+  // retrieved 26 January 2025
+  QUnit.test('it finds the key info from one of my fics', (assert) => {
+    assertGetsTheRightKeyInfo(
+      assert,
+      'test/fixtures/Operation_Cameo.epub',
+      {
+        title: 'Operation Cameo',
+        author: 'alexwlchan',
+        fandom: 'Operation Mincemeat: A New Musical - SpitLip',
+      }
+    );
+  });
+  
+  // This EPUB file was downloaded from David MacIver's fic "Stargate Physics",
+  // retrieved 26 January 2025
+  QUnit.test('it finds the fandom if there are multiple fandoms', (assert) => {
+    assertGetsTheRightKeyInfo(
+      assert,
+      'test/fixtures/Stargate_Physics_101.epub',
+      {
+        title: 'Stargate Physics 101',
+        author: 'DRMacIver',
+        fandom: 'Stargate - All Series, Stargate SG-1'
+      }
+    );
   });
 });
 

test/fixtures/Stargate_Physics_101.epub (0 → 15412)

diff --git a/test/fixtures/Stargate_Physics_101.epub b/test/fixtures/Stargate_Physics_101.epub
new file mode 100644
index 0000000..6e244ff
Binary files /dev/null and b/test/fixtures/Stargate_Physics_101.epub differ