from selenium.webdriver.common.by import By

from apps.lyric.models import User


class MyPostsPage:
    def __init__(self, test):
        self.test = test

    def go_to_my_posts_page(self, email):
        self.test.browser.get(self.test.live_server_url)
        user = User.objects.get(email=email)
        self.test.browser.get(
            self.test.live_server_url + f'/billboard/users/{user.id}/'
        )
        self.test.wait_for(
            lambda: self.test.assertIn(
                email,
                self.test.browser.find_element(By.CSS_SELECTOR, ".navbar-identity").text.lower(),
            )
        )
        return self
