From 324b74cef03ca5f21e938ed3bb9a43e564b377fa Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Sat, 24 Jun 2023 17:41:24 -0300 Subject: test: generateAlbumTrackList (snapshot, unit) --- .../snapshot/generateAlbumTrackList.js.test.cjs | 30 ++++++++++++++++ test/snapshot/generateAlbumTrackList.js | 41 ++++++++++++++++++++++ .../content/dependencies/generateAlbumTrackList.js | 40 +++++++++++++++++++++ 3 files changed, 111 insertions(+) create mode 100644 tap-snapshots/test/snapshot/generateAlbumTrackList.js.test.cjs create mode 100644 test/snapshot/generateAlbumTrackList.js create mode 100644 test/unit/content/dependencies/generateAlbumTrackList.js diff --git a/tap-snapshots/test/snapshot/generateAlbumTrackList.js.test.cjs b/tap-snapshots/test/snapshot/generateAlbumTrackList.js.test.cjs new file mode 100644 index 00000000..14316988 --- /dev/null +++ b/tap-snapshots/test/snapshot/generateAlbumTrackList.js.test.cjs @@ -0,0 +1,30 @@ +/* IMPORTANT + * This snapshot file is auto-generated, but designed for humans. + * It should be checked into source control and tracked carefully. + * Re-generate by setting TAP_SNAPSHOT=1 and running tests. + * Make sure to inspect the output below. Do not ignore changes! + */ +'use strict' +exports[`test/snapshot/generateAlbumTrackList.js TAP generateAlbumTrackList (snapshot) > basic behavior, default track section 1`] = ` + +` + +exports[`test/snapshot/generateAlbumTrackList.js TAP generateAlbumTrackList (snapshot) > basic behavior, with track sections 1`] = ` +
+
First section (~1:30):
+
+
    +
  • Item: Track 1
  • +
  • Item: Track 2
  • +
  • Item: Track 3
  • +
+
+
Second section (0:05):
+
  • Item: Track 4
+
+` diff --git a/test/snapshot/generateAlbumTrackList.js b/test/snapshot/generateAlbumTrackList.js new file mode 100644 index 00000000..055f189e --- /dev/null +++ b/test/snapshot/generateAlbumTrackList.js @@ -0,0 +1,41 @@ +import t from 'tap'; +import {testContentFunctions} from '../lib/content-function.js'; + +testContentFunctions(t, 'generateAlbumTrackList (snapshot)', async (t, evaluate) => { + await evaluate.load({ + mock: { + generateAlbumTrackListItem: { + extraDependencies: ['html'], + data: track => track.name, + generate: (name, {html}) => + html.tag('li', `Item: ${name}`), + }, + }, + }); + + const tracks = [ + {name: 'Track 1', duration: 20}, + {name: 'Track 2', duration: 30}, + {name: 'Track 3', duration: 40}, + {name: 'Track 4', duration: 5}, + ]; + + evaluate.snapshot('basic behavior, with track sections', { + name: 'generateAlbumTrackList', + args: [{ + trackSections: [ + {name: 'First section', tracks: tracks.slice(0, 3)}, + {name: 'Second section', tracks: tracks.slice(3)}, + ], + tracks, + }], + }); + + evaluate.snapshot('basic behavior, default track section', { + name: 'generateAlbumTrackList', + args: [{ + trackSections: [{isDefaultTrackSection: true, tracks}], + tracks, + }], + }); +}); diff --git a/test/unit/content/dependencies/generateAlbumTrackList.js b/test/unit/content/dependencies/generateAlbumTrackList.js new file mode 100644 index 00000000..80b086ca --- /dev/null +++ b/test/unit/content/dependencies/generateAlbumTrackList.js @@ -0,0 +1,40 @@ +import t from 'tap'; +import {testContentFunctions} from '../../../lib/content-function.js'; + +testContentFunctions(t, 'generateAlbumTrackList (unit)', async (t, evaluate) => { + await evaluate.load({ + mock: { + generateAlbumTrackListItem: { + extraDependencies: ['html'], + data: track => track.name, + generate: (name, {html}) => + html.tag('li', `Item: ${name}`), + }, + }, + }); + + let readDuration = false; + + const track = (name, duration) => ({ + name, + get duration() { + readDuration = true; + return duration; + }, + }); + + const tracks = [ + track('Track 1', 30), + track('Track 2', 15), + ]; + + evaluate({ + name: 'generateAlbumTrackList', + args: [{ + trackSections: [{isDefaultTrackSection: true, tracks}], + tracks, + }], + }); + + t.notOk(readDuration, 'expect no access to track.duration property'); +}); -- cgit 1.3.0-6-gf8a5