1QUnit.module('getKeyFicInfo', () => {
2 function assertGetsTheRightKeyInfo(assert, path, expectedInfo) {
3 const done = assert.async();
5 JSZipUtils.getBinaryContent(path, function(err, data) {
10 JSZip.loadAsync(data).then(async function (zip) {
11 const ficInfo = await getKeyFicInfo(zip);
12 assert.deepEqual(ficInfo, expectedInfo);
18 // This EPUB file was downloaded from one of my fics,
19 // retrieved 26 January 2025
20 QUnit.test('it finds the key info from one of my fics', (assert) => {
21 assertGetsTheRightKeyInfo(
23 'test/fixtures/Operation_Cameo.epub',
25 title: 'Operation Cameo',
27 fandom: 'Operation Mincemeat: A New Musical - SpitLip',
32 // This EPUB file was downloaded from David MacIver's fic "Stargate Physics",
33 // retrieved 26 January 2025
34 QUnit.test('it finds the fandom if there are multiple fandoms', (assert) => {
35 assertGetsTheRightKeyInfo(
37 'test/fixtures/Stargate_Physics_101.epub',
39 title: 'Stargate Physics 101',
41 fandom: 'Stargate - All Series, Stargate SG-1'
46 // Downloaded from https://archiveofourown.org/works/32257177, 10 August 2026
47 QUnit.test('it escapes ampersands in the title', (assert) => {
48 assertGetsTheRightKeyInfo(
50 'test/fixtures/Loki_Sylvie_Two.epub',
52 title: 'Loki & Sylvie: Two Awesomely Genderfluid Variants',
53 author: 'KetchupOnToast',
54 fandom: 'Loki (TV 2021)'
64QUnit.module('chooseColour', () => {
65 QUnit.test('it chooses the colour in a reproducible way', (assert) => {
66 const fandom = 'Operation Mincemeat: A New Musical - SpitLip';
67 assert.deepEqual(chooseColour(fandom), ["#0ca67d", "#075f48"]);
70 QUnit.test('it chooses different colours for Star Wars and Star Trek', (assert) => {
71 assert.deepEqual(chooseColour('Star Wars'), ["#760ca6", "#44075f"]);
72 assert.deepEqual(chooseColour('Star Trek'), ["#0ca66e", "#075f3f"]);
75 QUnit.test('it creates the same colour for all Star Trek shows', (assert) => {
76 assert.deepEqual(chooseColour('Star Trek'), ["#0ca66e", "#075f3f"]);
77 assert.deepEqual(chooseColour('Star Trek TOS'), ["#0ca66e", "#075f3f"]);
78 assert.deepEqual(chooseColour('Star Trek: Lower Decks'), ["#0ca66e", "#075f3f"]);
86QUnit.module('getTitleLines', () => {
87 QUnit.test('it splits a title on spaces', (assert) => {
88 const canvas = document.createElement("canvas");
89 canvas.setAttribute("width", 600);
90 canvas.setAttribute("height", 900);
91 const ctx = canvas.getContext("2d");
92 ctx.font = '95px Georgia';
94 const lines = getTitleLines({
95 ctx, title: 'Operation Cameo', maxWidth: 480,
98 assert.deepEqual(lines, ['Operation', 'Cameo']);