« get me outta code hell

hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/test/unit/data/composite
diff options
context:
space:
mode:
Diffstat (limited to 'test/unit/data/composite')
-rw-r--r--test/unit/data/composite/data/withPropertyFromObject.js8
-rw-r--r--test/unit/data/composite/things/track/withAlbum.js119
-rw-r--r--test/unit/data/composite/wiki-data/withParsedCommentaryEntries.js102
3 files changed, 6 insertions, 223 deletions
diff --git a/test/unit/data/composite/data/withPropertyFromObject.js b/test/unit/data/composite/data/withPropertyFromObject.js
index 912c924c..068932e2 100644
--- a/test/unit/data/composite/data/withPropertyFromObject.js
+++ b/test/unit/data/composite/data/withPropertyFromObject.js
@@ -61,7 +61,7 @@ t.test(`withPropertyFromObject: "internal" input`, t => {
     ],
   });
 
-  const thing = new (class extends CacheableObject {
+  const constructor = class extends CacheableObject {
     static [CacheableObject.propertyDescriptors] = {
       foo: {
         flags: {update: true, expose: false},
@@ -78,7 +78,11 @@ t.test(`withPropertyFromObject: "internal" input`, t => {
         },
       },
     };
-  });
+  };
+
+  constructor.finalizeCacheableObjectPrototype();
+
+  const thing = Reflect.construct(constructor, []);
 
   thing.foo = 100;
   thing.bar = 200;
diff --git a/test/unit/data/composite/things/track/withAlbum.js b/test/unit/data/composite/things/track/withAlbum.js
deleted file mode 100644
index 6f50776b..00000000
--- a/test/unit/data/composite/things/track/withAlbum.js
+++ /dev/null
@@ -1,119 +0,0 @@
-import t from 'tap';
-
-import '#import-heck';
-
-import Thing from '#thing';
-
-import {compositeFrom, input} from '#composite';
-import {exposeConstant, exposeDependency} from '#composite/control-flow';
-import {withAlbum} from '#composite/things/track';
-
-t.test(`withAlbum: basic behavior`, t => {
-  t.plan(3);
-
-  const composite = compositeFrom({
-    compose: false,
-    steps: [
-      withAlbum(),
-      exposeDependency({dependency: '#album'}),
-    ],
-  });
-
-  t.match(composite, {
-    expose: {
-      dependencies: ['albumData', 'this'],
-    },
-  });
-
-  const fakeTrack1 = {
-    [Thing.isThing]: true,
-    directory: 'foo',
-  };
-
-  const fakeTrack2 = {
-    [Thing.isThing]: true,
-    directory: 'bar',
-  };
-
-  const fakeAlbum = {
-    [Thing.isThing]: true,
-    directory: 'baz',
-    tracks: [fakeTrack1],
-  };
-
-  t.equal(
-    composite.expose.compute({
-      albumData: [fakeAlbum],
-      this: fakeTrack1,
-    }),
-    fakeAlbum);
-
-  t.equal(
-    composite.expose.compute({
-      albumData: [fakeAlbum],
-      this: fakeTrack2,
-    }),
-    null);
-});
-
-t.test(`withAlbum: early exit conditions`, t => {
-  t.plan(4);
-
-  const composite = compositeFrom({
-    compose: false,
-    steps: [
-      withAlbum(),
-      exposeConstant({
-        value: input.value('bimbam'),
-      }),
-    ],
-  });
-
-  const fakeTrack1 = {
-    [Thing.isThing]: true,
-    directory: 'foo',
-  };
-
-  const fakeTrack2 = {
-    [Thing.isThing]: true,
-    directory: 'bar',
-  };
-
-  const fakeAlbum = {
-    [Thing.isThing]: true,
-    directory: 'baz',
-    tracks: [fakeTrack1],
-  };
-
-  t.equal(
-    composite.expose.compute({
-      albumData: [fakeAlbum],
-      this: fakeTrack1,
-    }),
-    'bimbam',
-    `does not early exit if albumData is present and contains the track`);
-
-  t.equal(
-    composite.expose.compute({
-      albumData: [fakeAlbum],
-      this: fakeTrack2,
-    }),
-    'bimbam',
-    `does not early exit if albumData is present and does not contain the track`);
-
-  t.equal(
-    composite.expose.compute({
-      albumData: [],
-      this: fakeTrack1,
-    }),
-    'bimbam',
-    `does not early exit if albumData is empty array`);
-
-  t.equal(
-    composite.expose.compute({
-      albumData: null,
-      this: fakeTrack1,
-    }),
-    null,
-    `early exits if albumData is null`);
-});
diff --git a/test/unit/data/composite/wiki-data/withParsedCommentaryEntries.js b/test/unit/data/composite/wiki-data/withParsedCommentaryEntries.js
deleted file mode 100644
index babe4fae..00000000
--- a/test/unit/data/composite/wiki-data/withParsedCommentaryEntries.js
+++ /dev/null
@@ -1,102 +0,0 @@
-import t from 'tap';
-
-import {compositeFrom, input} from '#composite';
-import thingConstructors from '#things';
-
-import {exposeDependency} from '#composite/control-flow';
-import {withParsedCommentaryEntries} from '#composite/wiki-data';
-
-const {Artist} = thingConstructors;
-
-const composite = compositeFrom({
-  compose: false,
-
-  steps: [
-    withParsedCommentaryEntries({
-      from: 'from',
-    }),
-
-    exposeDependency({dependency: '#parsedCommentaryEntries'}),
-  ],
-});
-
-function stubArtist(artistName = `Test Artist`) {
-  const artist = new Artist();
-  artist.name = artistName;
-
-  return artist;
-}
-
-t.test(`withParsedCommentaryEntries: basic behavior`, t => {
-  t.plan(3);
-
-  const artist1 = stubArtist(`Mobius Trip`);
-  const artist2 = stubArtist(`Hadron Kaleido`);
-
-  const artistData = [artist1, artist2];
-
-  t.match(composite, {
-    expose: {
-      dependencies: ['from', 'artistData'],
-    },
-  });
-
-  t.same(composite.expose.compute({
-    artistData,
-    from:
-      `<i>Mobius Trip:</i>\n` +
-      `Some commentary.\n` +
-      `Very cool.\n`,
-  }), [
-    {
-      artists: [artist1],
-      artistDisplayText: null,
-      annotation: null,
-      date: null,
-      body: `Some commentary.\nVery cool.`,
-    },
-  ]);
-
-  t.same(composite.expose.compute({
-    artistData,
-    from:
-      `<i>Mobius Trip|Moo-bius Trip:</i> (music, art, 12 January 2015)\n` +
-      `First commentary entry.\n` +
-      `Very cool.\n` +
-      `<i>Hadron Kaleido|<b>[[artist:hadron-kaleido|The Ol' Hadron]]</b>:</i> (moral support, 4/4/2022)\n` +
-      `Second commentary entry. Yes. So cool.\n` +
-      `<i>Mystery Artist:</i> (pingas, August 25, 2023)\n` +
-      `Oh no.. Oh dear...\n` +
-      `<i>Mobius Trip, Hadron Kaleido:</i>\n` +
-      `And back around we go.`,
-  }), [
-    {
-      artists: [artist1],
-      artistDisplayText: `Moo-bius Trip`,
-      annotation: `music, art`,
-      date: new Date('12 January 2015'),
-      body: `First commentary entry.\nVery cool.`,
-    },
-    {
-      artists: [artist2],
-      artistDisplayText: `<b>[[artist:hadron-kaleido|The Ol' Hadron]]</b>`,
-      annotation: `moral support`,
-      date: new Date('4 April 2022'),
-      body: `Second commentary entry. Yes. So cool.`,
-    },
-    {
-      artists: [],
-      artistDisplayText: null,
-      annotation: `pingas`,
-      date: new Date('25 August 2023'),
-      body: `Oh no.. Oh dear...`,
-    },
-    {
-      artists: [artist1, artist2],
-      artistDisplayText: null,
-      annotation: null,
-      date: null,
-      body: `And back around we go.`,
-    },
-  ]);
-});