From 67467aa70dff7324638d096091c3e8686112d863 Mon Sep 17 00:00:00 2001 From: Zed Date: Mon, 12 Aug 2019 17:02:07 +0200 Subject: [PATCH] Add quote tests --- src/views/tweet.nim | 6 ++--- tests/base.py | 14 ++++++++++ tests/test_quote.py | 66 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 83 insertions(+), 3 deletions(-) create mode 100644 tests/test_quote.py diff --git a/src/views/tweet.nim b/src/views/tweet.nim index 4209581..0fd5d9d 100644 --- a/src/views/tweet.nim +++ b/src/views/tweet.nim @@ -14,10 +14,10 @@ proc renderHeader(tweet: Tweet): VNode = span: text "📌 Pinned Tweet" tdiv(class="tweet-header"): - tdiv(class="tweet-name-row"): - a(class="tweet-avatar", href=("/" & tweet.profile.username)): - genImg(tweet.profile.getUserpic("_bigger"), class="avatar") + a(class="tweet-avatar", href=("/" & tweet.profile.username)): + genImg(tweet.profile.getUserpic("_bigger"), class="avatar") + tdiv(class="tweet-name-row"): tdiv(class="fullname-and-username"): linkUser(tweet.profile, class="fullname") linkUser(tweet.profile, class="username") diff --git a/tests/base.py b/tests/base.py index 3ef80b7..1e3030d 100644 --- a/tests/base.py +++ b/tests/base.py @@ -1,6 +1,20 @@ from seleniumbase import BaseCase +class Quote(object): + def __init__(self, tweet=''): + quote = tweet + '.quote ' + namerow = quote + '.fullname-and-username ' + self.link = quote + '.quote-link' + self.fullname = namerow + '.fullname' + self.username = namerow + '.username' + self.text = quote + '.quote-text' + self.media = quote + '.quote-media' + self.unavailable = quote + '.quote.unavailable' + self.sensitive = quote + '.quote-sensitive' + self.badge = quote + '.quote-badge' + + class Tweet(object): def __init__(self, tweet=''): namerow = tweet + '.tweet-header ' diff --git a/tests/test_quote.py b/tests/test_quote.py new file mode 100644 index 0000000..dde1cc8 --- /dev/null +++ b/tests/test_quote.py @@ -0,0 +1,66 @@ +from base import BaseTestCase, Quote, Conversation +from parameterized import parameterized + +text = [ + ['elonmusk/status/1138136540096319488', + 'Tesla Owners Online', '@Model3Owners', + """As of March 58.4% of new car sales in Norway are electric. + +What are we doing wrong? reuters.com/article/us-norwa…"""], + + ['SpaceX/status/1136998058242088960', + 'SpaceX Jobs', '@SpaceXJobs', + 'Super excited to be number 1! Let’s make humanity multiplanetary 🚀 businessinsider.com/universu…'], + + ['nim_lang/status/924694255364341760', + 'Hacker News', '@newsycombinator', + 'Why Rust fails hard at scientific computing andre-ratsimbazafy.com/why-r…'] +] + +image = [ + ['elonmusk/status/1138827760107790336', 'D83h6Y8UIAE2Wlz'], + ['SpaceX/status/1067155053461426176', 'Ds9EYfxXoAAPNmx'] +] + +gif = [ + ['SpaceX/status/747497521593737216', 'Cl-R5yFWkAA_-3X'], + ['nim_lang/status/1068099315074248704', 'DtJSqP9WoAAKdRC'] +] + +video = [ + ['bkuensting/status/1067316003200217088', 'IyCaQlzF0q8u9vBd', '1:05'] +] + + +class QuoteTest(BaseTestCase): + @parameterized.expand(text) + def test_text(self, tweet, fullname, username, text): + self.open_nitter(tweet) + quote = Quote(Conversation.main + " ") + self.assert_text(fullname, quote.fullname) + self.assert_text(username, quote.username) + self.assert_text(text, quote.text) + + @parameterized.expand(image) + def test_image(self, tweet, url): + self.open_nitter(tweet) + quote = Quote(Conversation.main + " ") + self.assert_element_visible(quote.media) + self.assert_element_not_visible(quote.badge) + self.assertIn(url, self.get_image_url(quote.media + ' img')) + + @parameterized.expand(gif) + def test_gif(self, tweet, thumb): + self.open_nitter(tweet) + quote = Quote(Conversation.main + " ") + self.assert_element_visible(quote.badge) + self.assert_text('GIF', quote.badge) + self.assertIn(thumb, self.get_image_url(quote.media + ' img')) + + @parameterized.expand(video) + def test_video(self, tweet, thumb, length): + self.open_nitter(tweet) + quote = Quote(Conversation.main + " ") + self.assert_element_visible(quote.badge) + self.assert_text(length, quote.badge) + self.assertIn(thumb, self.get_image_url(quote.media + ' img'))