Skip to content

Commit

Permalink
FInished fixing tests and reworking automatic testing
Browse files Browse the repository at this point in the history
  • Loading branch information
axelNTI committed Oct 10, 2024
1 parent 599a5cf commit 3ff451a
Show file tree
Hide file tree
Showing 18 changed files with 81 additions and 213 deletions.
22 changes: 17 additions & 5 deletions .github/workflows/automated-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ name: Index Page Automated Content Tests
on:
push:
branches:
- main
- live
- "**"

jobs:
test:
Expand All @@ -36,12 +35,25 @@ jobs:
with:
python-version: "3.12.5"

- name: "Install Node.js"
uses: actions/setup-node@v4
with:
node-version: "latest"

- name: Install dependencies
run: |
pip install pytest-playwright
pip install playwright
pip install pytest-json-report
pip install pytest-playwright playwright pytest-json-report python-dotenv
playwright install
npm install
- name: Create a .env file dynamically from environment variables
run: |
printenv | grep ^SECRET_ > .env
shell: bash

- name: Run server
run: |
npm run start
- name: Run tests with pytest-playwright
run: |
Expand Down
70 changes: 0 additions & 70 deletions .github/workflows/w3c-validation.yml

This file was deleted.

2 changes: 0 additions & 2 deletions database.env

This file was deleted.

37 changes: 17 additions & 20 deletions helpers/handlebars.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,60 +85,57 @@ const currentStatus = (location, lang, debugTime) => {
openHours = location.open_hours;
}

const openHoursToday = openHours.find((element) => element.index === now.getDay());

const tempDate = new Date(now);

// Get the weekday object for the current day
let openHoursToday = openHours.find((element) => element.index === tempDate.getDay());
let nextOpenHours = openHours.find((element) => element.index === tempDate.getDay());
// Increment tempDate by 1 day until a day is found where the store is open
while (
closedDates.map((element) => element.date).includes(`${tempDate.getMonth().toString().padStart(2, "0")}${tempDate.getDate().toString().padStart(2, "0")}`) || // Check if it is a holiday
openHoursToday.from_hour === null || // Check if it is a weekday that is normally not open
openHoursToday.to_hour === null || // Check if it is a weekday that is normally not open
openHoursToday.from_minute === null || // Check if it is a weekday that is normally not open
openHoursToday.to_minute === null || // Check if it is a weekday that is normally not open
(tempDate.getTime() === now.getTime() && (now.getHours() > openHoursToday.to_hour || (now.getHours() === openHoursToday.to_hour && now.getMinutes() >= openHoursToday.to_minute))) // Check if it is the first iteration and the store has closed for the day
nextOpenHours.from_hour === null || // Check if it is a weekday that is normally not open
nextOpenHours.to_hour === null || // Check if it is a weekday that is normally not open
nextOpenHours.from_minute === null || // Check if it is a weekday that is normally not open
nextOpenHours.to_minute === null || // Check if it is a weekday that is normally not open
(tempDate.getTime() === now.getTime() && (now.getHours() > nextOpenHours.to_hour || (now.getHours() === nextOpenHours.to_hour && now.getMinutes() >= nextOpenHours.to_minute))) // Check if it is the first iteration and the store has closed for the day
) {
// Increment tempDate by 1 day
tempDate.setDate(tempDate.getDate() + 1);

// Get the weekday object for the next day
openHoursToday = openHours.find((element) => element.index === tempDate.getDay());
nextOpenHours = openHours.find((element) => element.index === tempDate.getDay());
}

// Get the weekday object for the next open day
const nextOpenDayObject = openHours.find((element) => element.index === tempDate.getDay());

// Formats the current time to "MMDD"
const dateString = `${now.getMonth().toString().padStart(2, "0")}${now.getDate().toString().padStart(2, "0")}`;
// Check if it is a holiday
if (closedDates.map((element) => element.date).includes(dateString)) {
const holiday = closedDates.find((element) => element.date === dateString);
const nextOpenDay = lang[capitalize_weekdays] ? lang[nextOpenDayObject.day] : lang[nextOpenDayObject.day].toLowerCase();
const time = `${nextOpenDayObject.from_hour.toString().padStart(2, "0")}:${nextOpenDayObject.from_minute.toString().padStart(2, "0")}`;
const nextOpenDay = lang.capitalize_weekdays ? lang[nextOpenHours.day] : lang[nextOpenHours.day].toLowerCase();
const time = `${nextOpenHours.from_hour.toString().padStart(2, "0")}:${nextOpenHours.from_minute.toString().padStart(2, "0")}`;
return lang.closed_now_holiday.replace("${holiday}", holiday.name).replace("${next_open_day}", nextOpenDay).replace("${time}", time);
}

// Check if it is a weekday that is normally not open
if (openHoursToday.from_hour === null || openHoursToday.to_hour === null || openHoursToday.from_minute === null || openHoursToday.to_minute === null) {
const nextOpenDay = lang[capitalize_weekdays] ? lang[nextOpenDayObject.day] : lang[nextOpenDayObject.day].toLowerCase();
const time = `${nextOpenDayObject.from_hour.toString().padStart(2, "0")}:${nextOpenDayObject.from_minute.toString().padStart(2, "0")}`;
const nextOpenDay = lang.capitalize_weekdays ? lang[nextOpenHours.day] : lang[nextOpenHours.day].toLowerCase();
const time = `${nextOpenHours.from_hour.toString().padStart(2, "0")}:${nextOpenHours.from_minute.toString().padStart(2, "0")}`;
return lang.after_hours.replace("${next_open_day}", nextOpenDay).replace("${time}", time);
}
// Check if the store has not opened yet for the day
if (now.getHours() < openHoursToday.from_hour || (now.getHours() === openHoursToday.from_hour && now.getMinutes() < openHoursToday.from_minute)) {
const time = `${openHoursToday.from_hour.toString().padStart(2, "0")}:${openHoursToday.from_minute.toString().padStart(2, "0")}`;
const time = `${nextOpenHours.from_hour.toString().padStart(2, "0")}:${nextOpenHours.from_minute.toString().padStart(2, "0")}`;
return lang.not_open_yet.replace("${time}", time);
}

// Check if the store is currently open
if (now.getHours() < openHoursToday.to_hour || (now.getHours() === openHoursToday.to_hour && now.getMinutes() < openHoursToday.to_minute)) {
const time = `${openHoursToday.to_hour.toString().padStart(2, "0")}:${openHoursToday.to_minute.toString().padStart(2, "0")}`;
const time = `${nextOpenHours.to_hour.toString().padStart(2, "0")}:${nextOpenHours.to_minute.toString().padStart(2, "0")}`;
return lang.open_now.replace("${time}", time);
}

// Check if the store has closed for the day
const nextOpenDay = lang[capitalize_weekdays] ? lang[nextOpenDayObject.day] : lang[nextOpenDayObject.day].toLowerCase();
const time = `${nextOpenDayObject.from_hour.toString().padStart(2, "0")}:${nextOpenDayObject.from_minute.toString().padStart(2, "0")}`;
const nextOpenDay = lang.capitalize_weekdays ? lang[nextOpenHours.day] : lang[nextOpenHours.day].toLowerCase();
const time = `${nextOpenHours.from_hour.toString().padStart(2, "0")}:${nextOpenHours.from_minute.toString().padStart(2, "0")}`;
return lang.after_hours.replace("${next_open_day}", nextOpenDay).replace("${time}", time);
};

Expand Down
9 changes: 0 additions & 9 deletions public/css/no-script-hamburger-menu.css

This file was deleted.

17 changes: 0 additions & 17 deletions public/css/no-script-locale-dropdown.css

This file was deleted.

17 changes: 0 additions & 17 deletions public/css/no-script-location-dropdown.css

This file was deleted.

10 changes: 10 additions & 0 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,22 @@ app.get("/", (req, res) => {
app.post("/POST/language", (req, res) => {
const { language, route } = req.body;
req.session.language = language;
req.session.save((err) => {
if (err) {
console.error(err);
}
});
res.redirect(`/${route}`);
});

app.post("/POST/location", (req, res) => {
const { location, route } = req.body;
req.session.location = location;
req.session.save((err) => {
if (err) {
console.error(err);
}
});
res.redirect(`/${route}`);
});

Expand Down
1 change: 0 additions & 1 deletion tests/template.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import unittest
from utils import *


Expand Down
19 changes: 0 additions & 19 deletions tests/test_dynamic_open_hours_display.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
import unittest
import datetime
import dotenv
from os import path
from utils import *


Expand All @@ -16,21 +12,6 @@ def testSelfName(self) -> None:
if self.__class__.__name__ == "TestName":
self.fail("Test class name is not correct")

# helpers
def setPageTimeTo(self, year: int, month: int, day: int, hour: int, minute: int) -> None:
pass

def setAndTestTime(self, year: int, month: int, day: int, hour: int, minute: int, expected: list[str]) -> None:
# Convert the given time to unix time
time = str(int(datetime.datetime(year, month, day, hour, minute, tzinfo=datetime.datetime.now().astimezone().tzinfo).timestamp()) * 1000)
debugKey = dotenv.get_key(path.join(path.dirname(__file__), "..", ".env"), "DEBUG_KEY")
self.page.goto(f"http://localhost:4000/?debugTime={time}&debugKey={debugKey}")
self.page.wait_for_selector("#checkJsCompleted", state="attached")
self.assertInAllTextContent(expected)

def currentYear(self) -> int:
return datetime.datetime.now().year

# tests
def testWeekdays(self) -> None:
# monday before open. we expect the open time to show
Expand Down
2 changes: 0 additions & 2 deletions tests/test_essential_info.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import unittest
from utils import *
import datetime


class TestEssentialInfo(TemplateTest):
Expand Down
27 changes: 13 additions & 14 deletions tests/test_hamburger_menu.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import unittest
from utils import *


Expand All @@ -21,25 +20,25 @@ def testSelfName(self) -> None:

def testHamburgerMenuDropdown(self) -> None:
# Check that the dropdown menu switches between visible and hidden when the hamburger menu button is clicked
hamburgerMenuButton = self.page.query_selector(".hamburger-menu")
hamburgerMenuButton = self.page.locator("header > section > button")

self.assertFalse(self.page.is_visible(".dropdown-menu"))
self.assertFalse(self.page.is_visible("header > section > nav"))

hamburgerMenuButton.click()
hamburgerMenuButton.hover()

self.assertTrue(self.page.is_visible(".dropdown-menu"))
self.assertTrue(self.page.is_visible("header > section > nav"))

hamburgerMenuButton.click()
self.page.mouse.move(0, 812)

self.assertFalse(self.page.is_visible(".dropdown-menu"))
self.assertFalse(self.page.is_visible("header > section > nav"))

def testHamburgerMenuLinks(self) -> None:
# Check that the hamburger menu links are correct

hamburgerMenuButton = self.page.query_selector(".hamburger-menu")
hamburgerMenuLinks = self.page.query_selector_all(".dropdown-menu a")
hamburgerMenuButton = self.page.locator("header > section > button")
hamburgerMenuLinks = self.page.locator("header > section > nav > a").all()

hamburgerMenuButton.click()
hamburgerMenuButton.hover()

self.assertEqual(len(hamburgerMenuLinks), 4)

Expand All @@ -50,11 +49,11 @@ def testHamburgerMenuLinks(self) -> None:

def testHamburgerMenuLinkClick(self) -> None:
# Check that the hamburger menu links navigate to the correct sections
hamburgerMenuButton = self.page.query_selector(".hamburger-menu")
hamburgerMenuLinks = self.page.query_selector_all(".dropdown-menu a")
hamburgerMenuButton = self.page.locator("header > section > button")
hamburgerMenuLinks = self.page.locator("header > section > nav > a").all()

# Open the hamburger menu
hamburgerMenuButton.click()
hamburgerMenuButton.hover()

# Click the first link and verify the section title is in the viewport
hamburgerMenuLinks[0].click()
Expand All @@ -79,7 +78,7 @@ def testHamburgerMenuLinkClick(self) -> None:
self.assertTrue(isInViewport)

# Open the hamburger menu again
hamburgerMenuButton.click()
hamburgerMenuButton.hover()

# Click the fourth link and verify the section title is in the viewport
hamburgerMenuLinks[3].click()
Expand Down
Loading

0 comments on commit 3ff451a

Please sign in to comment.