Skip to content

Commit

Permalink
feat(Channel): Add getters for all optional tabs (#303)
Browse files Browse the repository at this point in the history
* feat(Channel): Add getters for all optional tabs

* Fix typo in test description

Co-authored-by: LuanRT <[email protected]>

---------

Co-authored-by: LuanRT <[email protected]>
  • Loading branch information
absidue and LuanRT authored Feb 2, 2023
1 parent d612590 commit b2900f4
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/parser/youtube/Channel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
Expand All @@ -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.
*/
Expand Down
4 changes: 4 additions & 0 deletions test/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,9 @@ export const CHANNELS = [
{
ID: 'UCt-oJR5teQIjOAxCmIQvcgA',
NAME: "They're Just Movies"
},
{
ID: 'UCOpNcN46UbXVtpKMrmU4Abg',
NAME: "Gaming"
}
];
17 changes: 17 additions & 0 deletions test/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', 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 () => {
Expand Down

0 comments on commit b2900f4

Please sign in to comment.