feat: add is_empty method to richtext

This commit is contained in:
ThetaDev 2023-11-21 13:29:46 +01:00
parent 8458d878e7
commit 22deccb408
2 changed files with 30 additions and 0 deletions

View file

@ -72,6 +72,13 @@ pub trait ToMarkdown {
fn to_markdown_yt_host(&self, yt_host: &str) -> String;
}
impl RichText {
/// Returns `true` if the rich text contains no text components.
pub fn is_empty(&self) -> bool {
self.0.is_empty()
}
}
impl TextComponent {
/// Get the text from the component
pub fn get_text(&self) -> &str {

View file

@ -730,6 +730,29 @@ fn get_video_details_agegate(rp: RustyPipe) {
assert!(details.recommended.items.is_empty());
}
#[rstest]
fn get_video_details_no_desc(rp: RustyPipe) {
let details = tokio_test::block_on(rp.query().video_details("VYJNSQ_ANyA")).unwrap();
assert_eq!(details.id, "VYJNSQ_ANyA");
assert_eq!(details.name, "Cricket comedy by Modi");
assert_eq!(details.channel.id, "UC8gBy2lByHxIyoPMglerNWg");
assert_eq!(details.channel.name, "TMP VIBES");
assert!(!details.channel.avatar.is_empty(), "no channel avatars");
assert!(
details.description.is_empty(),
"got desc: `{}`",
details.description.to_plaintext()
);
let date = details.publish_date.unwrap();
assert_eq!(date.date(), date!(2023 - 11 - 21));
assert!(!details.is_live);
assert!(!details.is_ccommons);
}
#[rstest]
fn get_video_details_not_found(rp: RustyPipe) {
let err = tokio_test::block_on(rp.query().video_details("abcdefgLi5X")).unwrap_err();