class IMDGLoginTest(IMDGBaseTest):
    def setUp(self):
        super().setUp()

    def test_001_login_with_correct_credential(self):
        #Instantiate an object of LoginPage class. When the constructor of LoginPage
        #is called, it opens up the browser and navigates to Login Page of IMDA iCheck
        #then login using provided credential
        self.loginPage = LoginPage(self.driver)
        self.loginPage.login()

        #Assert that redirect to Home page with Extract name is visible at the page
        self.assertTrue(self.loginPage.is_visible(Locators.APP_NAME))

    @unittest.skip("Not first time login")
    def test_002a_first_time_login_then_logout(self):

        self.loginPage = LoginPage(self.driver)
        self.loginPage.login()

        # Asserting that claim application list is not present
        self.homePage = HomePage(self.loginPage.driver)
        self.assertFalse(
            self.homePage.is_clickable(Locators.CLAIM_APPLICATION_ROW_2))
        self.homePage.logout()

        #Asserting redirection to Login page with Login button is visible
        self.assertTrue(self.homePage.is_visible(Locators.LOGIN_PAGE_TITLE))

    def test_002b_login_then_logout(self):
        self.loginPage = LoginPage(self.driver)
        self.loginPage.login()

        self.homePage = HomePage(self.loginPage.driver)
        self.assertTrue(
            self.homePage.is_clickable(Locators.CLAIM_APPLICATION_ROW_2))
        self.homePage.logout()

        #Asserting redirection to Login page with Login button is visible
        self.assertFalse(self.homePage.is_visible(Locators.LOGIN_PAGE_TITLE))
class IMDGClaimOfficerTest(IMDGBaseTest):
    def setUp(self):
        super().setUp()

    def test_001_login_with_claim_officer_role(self):
        #Instantiate an object of LoginPage class and login using provided credential
        self.loginPage = LoginPage(self.driver)
        self.loginPage.login()

        #Instantiate an object of HomePage class and go to Claim Officer role
        self.homePage = HomePage(self.loginPage.driver)
        self.homePage.claim_officer_role()

        # Assert Claim Applications table is visible and the applications with Pending Approval status
        # are clickable
        self.assertTrue(self.homePage.is_clickable(Locators.CLAIM_APPLICATION_ROW_2_APPLICANT_NAME))
        #Assert Create New Application is not visible
        self.assertFalse(self.homePage.is_visible(Locators.CREATE_NEW_APPLICATION))

    def test_002_click_pending_application(self):
        self.loginPage = LoginPage(self.driver)
        self.loginPage.login()

        self.homePage = HomePage(self.loginPage.driver)
        self.homePage.claim_officer_role()
        self.assertTrue(self.homePage.is_clickable(Locators.CLAIM_APPLICATION_ROW_2))

        #Click application with 'Pending Approval' status and assert redirection to Application Detail page
        self.homePage.verify_application()
        self.assertTrue(self.homePage.is_visible(Locators.VERIFY_APPLICATION_BUTTON))

    def test_003_reject_application(self):
        self.loginPage = LoginPage(self.driver)
        self.loginPage.login()

        self.homePage = HomePage(self.loginPage.driver)
        self.homePage.create_application()
        self.createApplicationPage = CreateEditApplicationPage(self.homePage.driver)

        # Upload required documents and check a checkmark when the upload process is finished
        self.createApplicationPage.upload(Locators.UPLOAD_NRIC_BUTTON, TestData.NRIC_PATH)
        self.createApplicationPage.is_visible_long(Locators.NRIC_SUCCESS_ICON)

        #Submit the application
        self.createApplicationPage.submit_application()

        #Instantiate an object of HomePage class and check a toaster appear
        self.homePage = HomePage(self.createApplicationPage.driver)
        self.homePage.is_enabled(Locators.NOTIFICATION_TOASTER)
        self.homePage.is_clickable(Locators.CLAIM_APPLICATION_ROW_2)

        #Go to Claim Officer role and sort the claim list by the latest entries
        self.homePage.claim_officer_role()
        self.homePage.sort_by_latest()
        self.homePage.is_clickable(Locators.CLAIM_APPLICATION_ROW_1)

        # Go to the latest application details, instantiate an object of
        # ApplicationPage class and reject the application then assert
        # it has been rejected
        self.applicationDetailPage = ApplicationDetailPage(self.homePage.driver)
        self.applicationDetailPage.reject_application()
        self.applicationDetailPage.is_clickable(Locators.CLAIM_APPLICATION_ROW_2)

        self.homePage = HomePage(self.applicationDetailPage.driver)
        self.homePage.sort_by_latest()
        self.assertTrue(self.homePage.assert_element_text(Locators.CLAIM_APPLICATION_ROW_1_STATUS, TestData.STATUS_REJECTED))

    def test_004_verify_application(self):
        self.loginPage = LoginPage(self.driver)
        self.loginPage.login()

        self.homePage = HomePage(self.loginPage.driver)
        self.homePage.create_application()
        self.createApplicationPage = CreateEditApplicationPage(self.homePage.driver)

        # Upload required documents and check a checkmark when the upload process is finished
        self.createApplicationPage.upload(Locators.UPLOAD_NRIC_BUTTON, TestData.NRIC_PATH)
        self.createApplicationPage.is_visible_long(Locators.NRIC_SUCCESS_ICON)

        #Submit the application
        self.createApplicationPage.submit_application()

        #Instantiate an object of HomePage class and check a toaster appear
        self.homePage = HomePage(self.createApplicationPage.driver)
        self.homePage.is_enabled(Locators.NOTIFICATION_TOASTER)
        self.homePage.is_clickable(Locators.CLAIM_APPLICATION_ROW_2)

        #Go to Claim Officer role and sort the claim list by the latest entries
        self.homePage.claim_officer_role()
        self.homePage.sort_by_latest()
        self.homePage.is_clickable(Locators.CLAIM_APPLICATION_ROW_1)

        # Go to the latest application details, instantiate an object of
        # ApplicationPage class and verify the application then assert
        # it has been verified
        self.applicationDetailPage = ApplicationDetailPage(self.homePage.driver)
        self.applicationDetailPage.verify_application()
        self.applicationDetailPage.is_clickable(Locators.CLAIM_APPLICATION_ROW_2)

        self.homePage = HomePage(self.applicationDetailPage.driver)
        self.homePage.sort_by_latest()
        self.assertTrue(self.homePage.assert_element_text(Locators.CLAIM_APPLICATION_ROW_1_STATUS, TestData.STATUS_VERIFIED))