class HeaderTests(unittest.TestCase):
    def setUp(self):
        self.driver = TestBrowser().get_browser()
        self.header = Header(self.driver)

    def tearDown(self):
        self.driver.quit()

    def test_movie_list(self):
        self.assertNotEqual(0, len(self.header.movieList), "Did not create movie list")
        self.assertNotEqual(0, len(self.header.movieList[0]), "Did not get a valid list of movies")

    def test_movie_selection(self):
        currentPage = self.driver.current_url
        i = self.header.select_random_movie()
        newPage = self.driver.current_url
        self.assertNotEqual(currentPage, newPage, "Selecting a movie did not navigate to a new page")
        self.assertEqual(self.header.movieList[i].lower(), self.driver.find_element_by_tag_name("h1").text.lower(),
                         "Did not end up on movie listing page for selected movie")

    def test_search(self):
        currentPage = self.driver.current_url
        self.header.do_search(_headerSearchTextNoSpaces)
        newPage = self.driver.current_url
        self.assertNotEqual(currentPage, newPage, "Searching did not navigate to a new page")
        self.assertIn(_headerSearchTextNoSpaces, newPage, "Search text not found in search URL string")

    def test_search_random_input_from_excel(self):
        # Get a random row greater than 0 to avoid the header and get that search data from the default input file
        # Within each row of data in the input file, [0] is the search string, [1] is the theater name, [2] is zip code
        index = randint(1,6)
        input = ReadExcel.get_sheet_values()

        searchText = input[index][0]
        expectedZip = str(input[index][2])
        currentPage = self.driver.current_url
        self.header.do_search(searchText)
        newPage = self.driver.current_url
        self.assertNotEqual(currentPage, newPage, "Searching did not navigate to a new page")
        self.assertIn(expectedZip, self.driver.page_source, "Expected zip code not found in results page")