From a5ab5af29a74dcfe784f455d947941392afd93a2 Mon Sep 17 00:00:00 2001 From: absidue <48293849+absidue@users.noreply.github.com> Date: Wed, 1 Feb 2023 18:42:14 +0100 Subject: [PATCH 1/2] feat(Channel): Add getters for all optional tabs --- src/parser/youtube/Channel.ts | 16 ++++++++++++++++ test/constants.ts | 4 ++++ test/main.test.ts | 17 +++++++++++++++++ 3 files changed, 37 insertions(+) diff --git a/src/parser/youtube/Channel.ts b/src/parser/youtube/Channel.ts index 9057b0bdb..2a0ad0026 100644 --- a/src/parser/youtube/Channel.ts +++ b/src/parser/youtube/Channel.ts @@ -196,6 +196,10 @@ export default class Channel extends TabbedFeed { return new Channel(this.actions, page, true); } + get has_home(): boolean { + return this.hasTabWithURL('featured'); + } + get has_videos(): boolean { return this.hasTabWithURL('videos'); } @@ -216,6 +220,18 @@ export default class Channel extends TabbedFeed { return this.hasTabWithURL('community'); } + get has_channels(): boolean { + return this.hasTabWithURL('channels'); + } + + get has_about(): boolean { + return this.hasTabWithURL('about'); + } + + get has_search(): boolean { + return this.memo.getType(ExpandableTab)?.length > 0; + } + /** * Retrives list continuation. */ diff --git a/test/constants.ts b/test/constants.ts index c7706265a..6e44f5353 100644 --- a/test/constants.ts +++ b/test/constants.ts @@ -41,5 +41,9 @@ export const CHANNELS = [ { ID: 'UCt-oJR5teQIjOAxCmIQvcgA', NAME: "They're Just Movies" + }, + { + ID: 'UCOpNcN46UbXVtpKMrmU4Abg', + NAME: "Gaming" } ]; \ No newline at end of file diff --git a/test/main.test.ts b/test/main.test.ts index b25e8edf3..e55b9e0db 100644 --- a/test/main.test.ts +++ b/test/main.test.ts @@ -165,11 +165,28 @@ describe('YouTube.js Tests', () => { it('should detect missing channel tabs', async () => { const channel = await yt.getChannel(CHANNELS[2].ID); + expect(channel.has_home).toBe(true); expect(channel.has_videos).toBe(true); expect(channel.has_shorts).toBe(false); expect(channel.has_live_streams).toBe(false); expect(channel.has_playlists).toBe(true); expect(channel.has_community).toBe(true); + expect(channel.has_channels).toBe(true); + expect(channel.has_about).toBe(true); + expect(channel.has_search).toBe(true); + }) + + it('should have no channel tabs channel tabs', async () => { + const channel = await yt.getChannel(CHANNELS[3].ID); + expect(channel.has_home).toBe(false); + expect(channel.has_videos).toBe(false); + expect(channel.has_shorts).toBe(false); + expect(channel.has_live_streams).toBe(false); + expect(channel.has_playlists).toBe(false); + expect(channel.has_community).toBe(false); + expect(channel.has_channels).toBe(false); + expect(channel.has_about).toBe(false); + expect(channel.has_search).toBe(false); }) it('should retrieve home feed', async () => { From 91a6d3899ecd5dc43083aec8ec94f5ceaf6f6822 Mon Sep 17 00:00:00 2001 From: absidue <48293849+absidue@users.noreply.github.com> Date: Wed, 1 Feb 2023 21:30:14 +0100 Subject: [PATCH 2/2] Fix typo in test description Co-authored-by: LuanRT --- test/main.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/main.test.ts b/test/main.test.ts index e55b9e0db..cef22e1e5 100644 --- a/test/main.test.ts +++ b/test/main.test.ts @@ -176,7 +176,7 @@ describe('YouTube.js Tests', () => { expect(channel.has_search).toBe(true); }) - it('should have no channel tabs channel tabs', async () => { + it('should have no channel tabs', async () => { const channel = await yt.getChannel(CHANNELS[3].ID); expect(channel.has_home).toBe(false); expect(channel.has_videos).toBe(false);