« get me outta code hell

generateContributionLinks.js « dependencies « content « unit « test - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/test/unit/content/dependencies/generateContributionLinks.js
blob: a0bb64eccf18b79dc899dace1281db00b4648541 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
import t from 'tap';
import {testContentFunctions} from '../../../lib/content-function.js';

t.test('generateContributionLinks (unit)', async t => {
  await testContentFunctions(t, 'generateContributionLinks (unit 1)', async (t, evaluate) => {
    const artist1 = {
      name: 'Clark Powell',
      urls: ['https://soundcloud.com/plazmataz'],
    };

    const artist2 = {
      name: 'Grounder & Scratch',
      urls: [],
    };

    const artist3 = {
      name: 'Toby Fox',
      urls: ['https://tobyfox.bandcamp.com/', 'https://toby.fox/'],
    };

    const contributions = [
      {who: artist1, what: null},
      {who: artist2, what: 'Snooping'},
      {who: artist3, what: 'Arrangement'},
    ];

    const config = {
      showContribution: true,
      showIcons: true,
    };

    await evaluate.load({
      mock: evaluate.mock(mock => ({
        linkArtist: {
          relations: mock.function('linkArtist.relations', () => ({}))
            .args([undefined, artist1]).next()
            .args([undefined, artist2]).next()
            .args([undefined, artist3]),

          data: mock.function('linkArtist.data', () => ({}))
            .args([artist1]).next()
            .args([artist2]).next()
            .args([artist3]),

          // This can be tweaked to return a specific (mocked) template
          // for each artist if we need to test for slots in the future.
          generate: mock.function(() => 'artist link')
            .repeat(3),
        },
      })),
    });

    evaluate({
      name: 'generateContributionLinks',
      args: [contributions, config],
      extraDependencies: evaluate.mock(mock => ({
        iconifyURL: mock.function(() => 'icon')
          .args([artist1.urls[0], undefined]).next()
          .args([artist3.urls[0], undefined]).next()
          .args([artist3.urls[1], undefined]),
      })),
    });
  });

  await testContentFunctions(t, 'generateContributionLinks (unit 2)', async (t, evaluate) => {
    const artist1 = {
      name: 'Clark Powell',
      urls: ['https://soundcloud.com/plazmataz'],
    };

    const artist2 = {
      name: 'Grounder & Scratch',
      urls: [],
    };

    const artist3 = {
      name: 'Toby Fox',
      urls: ['https://tobyfox.bandcamp.com/', 'https://toby.fox/'],
    };

    const contributions = [
      {who: artist1, what: null},
      {who: artist2, what: 'Snooping'},
      {who: artist3, what: 'Arrangement'},
    ];

    const config = {
      showContribution: false,
      showIcons: false,
    };

    await evaluate.load({
      mock: evaluate.mock(mock => ({
        linkArtist: {
          relations: mock.function('linkArtist.relations', () => ({}))
            .args([undefined, artist1]).next()
            .args([undefined, artist2]).next()
            .args([undefined, artist3]),

          data: mock.function('linkArtist.data', () => ({}))
            .args([artist1]).next()
            .args([artist2]).next()
            .args([artist3]),

          generate: mock.function(() => 'artist link')
            .repeat(3),
        },
      })),
    });

    evaluate({
      name: 'generateContributionLinks',
      args: [contributions, config],
      extraDependencies: evaluate.mock(mock => ({
        iconifyURL: mock.function(() => 'icon')
          .neverCalled(),
      })),
    });
  });
});