diff --git a/integration_tests/frontend/test_full_e2e.py b/integration_tests/frontend/test_full_e2e.py new file mode 100644 index 0000000..5dba467 --- /dev/null +++ b/integration_tests/frontend/test_full_e2e.py @@ -0,0 +1,55 @@ +import re +from ..base import BaseCase +from playwright.sync_api import sync_playwright, expect + + +class HomePage(BaseCase): + def setUp(self): + self.p = sync_playwright().start() + self.browser = self.p.chromium.launch() + self.context = self.browser.new_context() + self.page = self.context.new_page() + self.page.goto("http://frontend:3000") + + def tearDown(self): + self.page.close() + self.context.close() + self.browser.close() + self.p.stop() + + + def test_e2e(self): + # Sign in as admin user + self.page.get_by_role("link", name="Sign in").click() + self.page.get_by_label("Email address*").click() + self.page.get_by_label("Email address*").fill("admin@unibasement.local") + self.page.get_by_label("Password*").click() + self.page.get_by_label("Password*").fill("Admin_Password") + self.page.get_by_role("button", name="Continue", exact=True).click() + + # Check that the user is redirected to the home page which shows a greeting + # , admin + expect(self.page.locator("body")).to_contain_text(", admin") + + # Go to courses + self.page.get_by_role("link", name="Courses").click() + + # Expect to see the add courses button as admin + expect(self.page.get_by_role("link", name="Add Course")).to_be_visible() + + # Add a course + self.page.get_by_role("link", name="Add Course").click() + expect(self.page.url).to_equal("http://frontend:3000/courses/add") + expect(self.page.get_by_text("Add Course")).to_be_visible() + + # Fill in form + self.page.locator("input[name=\"courseCode\"]").click() + self.page.locator("input[name=\"courseCode\"]").fill("CSSE6400") + self.page.locator("input[name=\"courseName\"]").click() + self.page.locator("input[name=\"courseName\"]").fill("Software Architectures") + self.page.locator("textarea[name=\"courseDescription\"]").click() + self.page.locator("textarea[name=\"courseDescription\"]").fill("My favourite course :)") + self.page.get_by_role("button", name="Submit").click() + + # Expect to be redirected to the courses page on submit + expect(self.page.url).to_equal("http://frontend:3000/courses")