~phw/discourse-listenbrainz

95f5fe6673cfe6af66de3d357d5932b4a7b70e42 — Philipp Wolfer 9 months ago 0d8ada9
Fixed acceptance tests and added tests for pinned recording
M test/javascripts/acceptance/listenbrainz-listening-card-test.js => test/javascripts/acceptance/listenbrainz-listening-card-test.js +87 -4
@@ 21,13 21,14 @@ acceptance('ListenBrainz - User Summary - Listen Card', needs => {
                listenbrainz_enable: true,
                listenbrainz_username: 'outsidecontext',
                listenbrainz_display: 'listening',
                listenbrainz_show_pinned_recording: false,
            }
            return helper.response(response)
        })

        server.get('/listenbrainz/now-playing/19', () => {
            const response = cloneJSON(
                listenbrainzFixtures['/listenbrainz/now-playing/19']
                listenbrainzFixtures['listenbrainz-now-playing']
            )
            return helper.response(response)
        })


@@ 51,9 52,15 @@ acceptance('ListenBrainz - User Summary - Listen Card', needs => {
        await waitFor('.listenbrainz-card-details')
        assert.equal(
            query('.listenbrainz-card-title').innerText.trim().replace('\s+', ' '),
            '🎶 Orange Forest',
            'Orange Forest',
            'it shows the now-playing track title'
        )
        assert.ok(
            query('.listenbrainz-card-title .d-icon').classList.contains(
                'd-icon-music'
            ),
            'it shows music icon'
        )
        assert.equal(
            query('.listenbrainz-card-title a').href,
            'https://musicbrainz.org/recording/3f2bdbbd-063e-478c-a394-6da0cb303302',


@@ 98,7 105,12 @@ acceptance('ListenBrainz - User Summary - Listen Card', needs => {
        assert.equal(
            query('.listenbrainz-play-button').href,
            'https://listenbrainz.org/player?recording_mbids=3f2bdbbd-063e-478c-a394-6da0cb303302',
            'it links to LB plaxer'
            'it links to LB player'
        )
        assert.equal(
            query('.listenbrainz-card-listen-time .relative-date').title,
            'Feb 15, 2023 4:51 pm',
            'it shows the pin time'
        )
    })
})


@@ 113,13 125,14 @@ acceptance('ListenBrainz - User Summary - Listen Card - No Artist Credits', need
                listenbrainz_enable: true,
                listenbrainz_username: 'outsidecontext',
                listenbrainz_display: 'listening',
                listenbrainz_show_pinned_recording: false,
            }
            return helper.response(response)
        })

        server.get('/listenbrainz/now-playing/19', () => {
            const response = cloneJSON(
                listenbrainzFixtures['/listenbrainz/now-playing/19']
                listenbrainzFixtures['listenbrainz-now-playing']
            )
            response.track_metadata.mbid_mapping.artists = null
            return helper.response(response)


@@ 140,3 153,73 @@ acceptance('ListenBrainz - User Summary - Listen Card - No Artist Credits', need
        )
    })
})

acceptance('ListenBrainz - User Summary - Listen Card - Pinned Recording', needs => {
    needs.settings({ listenbrainz_enabled: true })
    needs.user()
    needs.pretender((server, helper) => {
        server.get('/u/eviltrout.json', () => {
            const response = cloneJSON(userFixtures['/u/eviltrout.json'])
            response.user.custom_fields = {
                listenbrainz_enable: true,
                listenbrainz_username: 'outsidecontext',
                listenbrainz_display: 'listening',
                listenbrainz_show_pinned_recording: true,
            }
            return helper.response(response)
        })

        server.get('/listenbrainz/now-playing/19', () => {
            const response = cloneJSON(
                listenbrainzFixtures['listenbrainz-now-playing-pin']
            )
            return helper.response(response)
        })
    })

    test('Shows user ListenBrainz pinned recording', async assert => {
        await visit('/u/eviltrout/summary')
        await waitFor('.listenbrainz-card-details')
        assert.equal(
            query('.listenbrainz-card-title').innerText.trim().replace('\s+', ' '),
            'Into the Unknown',
            'it shows the pin track title'
        )
        assert.ok(
            query('.listenbrainz-card-title .d-icon').classList.contains(
                'd-icon-thumbtack'
            ),
            'it shows thumbtack icon'
        )
        assert.equal(
            query('.listenbrainz-card-title a').href,
            'https://musicbrainz.org/recording/6959eb42-770c-4ebe-a4c0-681b3abed3b7',
            'it links the track title to MB recording page'
        )
        assert.equal(
            query('.listenbrainz-card-duration').innerText.trim(),
            '',
            'it has empty track duration'
        )
        assert.equal(
            query('.listenbrainz-card-secondary').innerText.trim(),
            'The Vision Bleak',
            'it shows the artist credits'
        )
        assert.equal(
            new query('.listenbrainz-card-thumbnail img').src,
            'https://coverartarchive.org/release/d6a2e5ae-370b-43ee-8054-44259ad22258/front-250',
            'it uses the coverart URL'
        )
        assert.equal(
            query('.listenbrainz-card-listen-time .relative-date').title,
            'May 12, 2023 8:43 am',
            'it shows the pin time'
        )
        assert.equal(
            query('.listenbrainz-card-additional-content blockquote').innerText.trim(),
            'The Vision Bleak sound a lot like Paradise Lost on this track, in a very positive way.',
            'it shows the pin blurb text'
        )
    })
})

M test/javascripts/acceptance/listenbrainz-profile-card-test.js => test/javascripts/acceptance/listenbrainz-profile-card-test.js +1 -1
@@ 29,7 29,7 @@ acceptance('ListenBrainz - User Summary - Profile Card', needs => {

        server.get('/listenbrainz/profile/19', () => {
            const response = cloneJSON(
                listenbrainzFixtures['/listenbrainz/profile/19']
                listenbrainzFixtures['listenbrainz-profile']
            )
            return helper.response(response)
        })

M test/javascripts/fixtures/listenbrainz-fixtures.js => test/javascripts/fixtures/listenbrainz-fixtures.js +33 -2
@@ 1,5 1,5 @@
export default {
    '/listenbrainz/now-playing/19': {
    'listenbrainz-now-playing': {
        playing_now: true,
        track_metadata: {
            artist_name: 'Airghoul',


@@ 37,7 37,38 @@ export default {
        coverart_url: '/plugins/listenbrainz/images/cover-art-placeholder.png'
    },

    '/listenbrainz/profile/19': {
    'listenbrainz-now-playing-pin': {
        blurb_content: 'The Vision Bleak sound a lot like Paradise Lost on this track, in a very positive way.',
        created: 1683873831,
        pinned_until: 1684478631,
        recording_mbid: '6959eb42-770c-4ebe-a4c0-681b3abed3b7',
        recording_msid: null,
        row_id: 868,
        track_metadata: {
            artist_name: 'The Vision Bleak',
            mbid_mapping: {
                artist_mbids: [
                    '14f29e73fa2b-4b90-8489-ea1702744ebb'
                ],
                artists: [
                    {
                        artist_credit_name: 'The Vision Bleak',
                        artist_mbid: '14f29e73-fa2b-4b90-8489-ea1702744ebb',
                        join_phrase: ''
                    }
                ],
                caa_id: 13533516480,
                caa_release_mbid: 'd6a2e5ae-370b-43ee-8054-44259ad22258',
                recording_mbid: '6959eb42-770c-4ebe-a4c0-681b3abed3b7',
                release_mbid: '961db5c6-c130-482d-8a85-d931956899c5'
            },
            release_name: 'The Unknown',
            track_name: 'Into the Unknown'
        },
        coverart_url: 'https://coverartarchive.org/release/d6a2e5ae-370b-43ee-8054-44259ad22258/front-250'
    },

    'listenbrainz-profile': {
        username: 'outsidecontext',
        range: 'this_year',
        listening_activity: [