|
| 1 | +import { describe, it, expect } from 'vitest'; |
| 2 | +import { mountSuspended } from '@nuxt/test-utils/runtime'; |
| 3 | +import DiscoveryRail from '~/components/DiscoveryRail.vue'; |
| 4 | + |
| 5 | +const entries = [ |
| 6 | + { title: 'Berserk', coverUrl: 'http://c/1.jpg', url: 'https://anilist.co/manga/1', source: 'AniList', blurb: null }, |
| 7 | + { title: 'Pick Me Up', coverUrl: 'http://c/2.jpg', url: 'https://anilist.co/manga/2', source: 'AniList', blurb: 'gacha' }, |
| 8 | +]; |
| 9 | +const library = [ |
| 10 | + { key: 's1', name: 'berserk', description: '', releaseStatus: 'Continuing', sourceIds: [], fileLibraryId: 'lib1', originalLanguage: 'en', coverUrl: '' }, |
| 11 | +]; |
| 12 | + |
| 13 | +describe('DiscoveryRail', () => { |
| 14 | + it('marks entries already in the library and routes them to their series page', async () => { |
| 15 | + const wrapper = await mountSuspended(DiscoveryRail, { |
| 16 | + props: { title: 'Trending manga', entries, library }, |
| 17 | + }); |
| 18 | + |
| 19 | + expect(wrapper.text()).toContain('Berserk'); |
| 20 | + expect(wrapper.text()).toContain('In library'); |
| 21 | + |
| 22 | + await wrapper.findAll('button')[0]!.trigger('click'); |
| 23 | + expect(wrapper.emitted('open')).toEqual([['s1']]); |
| 24 | + }); |
| 25 | + |
| 26 | + it('routes new entries to the add flow', async () => { |
| 27 | + const wrapper = await mountSuspended(DiscoveryRail, { |
| 28 | + props: { title: 'Trending manga', entries, library }, |
| 29 | + }); |
| 30 | + |
| 31 | + await wrapper.findAll('button')[1]!.trigger('click'); |
| 32 | + const picked = wrapper.emitted('pick')!; |
| 33 | + expect((picked[0]![0] as { title: string }).title).toBe('Pick Me Up'); |
| 34 | + expect(wrapper.emitted('open')).toBeFalsy(); |
| 35 | + }); |
| 36 | + |
| 37 | + it('external rails link out instead of emitting', async () => { |
| 38 | + const wrapper = await mountSuspended(DiscoveryRail, { |
| 39 | + props: { title: 'From the feeds', entries, external: true }, |
| 40 | + }); |
| 41 | + |
| 42 | + const link = wrapper.find('a'); |
| 43 | + expect(link.attributes('href')).toBe('https://anilist.co/manga/1'); |
| 44 | + expect(link.attributes('target')).toBe('_blank'); |
| 45 | + expect(wrapper.text()).not.toContain('In library'); |
| 46 | + }); |
| 47 | + |
| 48 | + it('renders nothing while empty', async () => { |
| 49 | + const wrapper = await mountSuspended(DiscoveryRail, { props: { title: 'Trending manga', entries: [] } }); |
| 50 | + |
| 51 | + expect(wrapper.text()).toBe(''); |
| 52 | + }); |
| 53 | +}); |
0 commit comments