fix(form): address remaining review findings

This commit is contained in:
Adam Moussa 2026-07-30 19:08:49 -04:00
parent 3fb550b394
commit 411c8bcadb
No known key found for this signature in database
4 changed files with 55 additions and 64 deletions

View file

@ -16,9 +16,11 @@ jobs:
runs-on: ubuntu-latest runs-on: ubuntu-latest
timeout-minutes: 15 timeout-minutes: 15
steps: steps:
- uses: actions/checkout@v7 - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.x
with:
persist-credentials: false
- uses: actions/setup-python@v7 - uses: actions/setup-python@5fda3b95a4ea91299a34e894583c3862153e4b97 # v7.x
with: with:
python-version: "3.12" python-version: "3.12"

View file

@ -81,8 +81,9 @@ function buildAddItemSelect(availableMeals) {
availableMeals.forEach(m => { availableMeals.forEach(m => {
const opt = document.createElement('option'); const opt = document.createElement('option');
const price = m.price || 0;
opt.value = m.name; opt.value = m.name;
opt.textContent = m.name + ' ($' + m.price.toFixed(2) + ')'; opt.textContent = m.name + ' ($' + price.toFixed(2) + ')';
select.appendChild(opt); select.appendChild(opt);
}); });

View file

@ -31,16 +31,6 @@ let mealsListDelegationBound = false;
window.googleCredential = null; window.googleCredential = null;
function escapeHtml(str) {
if (!str) return '';
return String(str)
.replace(/&/g, '&')
.replace(/</g, '&lt;')
.replace(/>/g, '&gt;')
.replace(/"/g, '&quot;')
.replace(/'/g, '&#39;');
}
function employeePrice(retail) { function employeePrice(retail) {
if (!retail) return 0; if (!retail) return 0;
const bulkPrice = Math.round(retail * (1 - BULK_DISCOUNT / 100) * 100 + 1e-8) / 100; const bulkPrice = Math.round(retail * (1 - BULK_DISCOUNT / 100) * 100 + 1e-8) / 100;
@ -48,7 +38,7 @@ function employeePrice(retail) {
return empPrice; return empPrice;
} }
window.FormUtils = { escapeHtml, employeePrice }; window.FormUtils = { employeePrice };
function syncGoogleCredential() { function syncGoogleCredential() {
window.googleCredential = googleCredential; window.googleCredential = googleCredential;
@ -374,33 +364,26 @@ async function submitOrder() {
} }
async function loadRoster() { async function loadRoster() {
let employees = ROSTER;
try { try {
const res = await fetch(ROSTER_URL); const res = await fetch(ROSTER_URL);
const data = await res.json(); const data = await res.json();
const select = document.getElementById('emp-name'); employees = data.employees || ROSTER;
select.innerHTML = '<option value="">Select your name</option>'; } catch (e) {}
(data.employees || ROSTER).forEach(emp => {
const opt = document.createElement('option'); const select = document.getElementById('emp-name');
opt.value = emp.name; select.innerHTML = '<option value="">Select your name</option>';
opt.dataset.email = emp.email; employees.forEach(emp => {
opt.textContent = emp.name; const opt = document.createElement('option');
select.appendChild(opt); opt.value = emp.name;
}); opt.dataset.email = emp.email;
select.addEventListener('change', () => { opt.textContent = emp.name;
const selected = select.options[select.selectedIndex]; select.appendChild(opt);
document.getElementById('emp-email').value = selected?.dataset?.email || ''; });
}); select.addEventListener('change', () => {
} catch (e) { const selected = select.options[select.selectedIndex];
const select = document.getElementById('emp-name'); document.getElementById('emp-email').value = selected?.dataset?.email || '';
select.innerHTML = '<option value="">Select your name</option>'; });
ROSTER.forEach(emp => {
const opt = document.createElement('option');
opt.value = emp.name;
opt.dataset.email = emp.email;
opt.textContent = emp.name;
select.appendChild(opt);
});
}
} }
function showClosedOverlay() { function showClosedOverlay() {

View file

@ -206,33 +206,38 @@ class TestGenerateFormPlaywright:
"Chromium is required for form Playwright tests. " "Chromium is required for form Playwright tests. "
"Run: playwright install --with-deps chromium" "Run: playwright install --with-deps chromium"
) from exc ) from exc
page = browser.new_page() try:
page.route( page = browser.new_page()
"**/api/form-status/**", page.route(
lambda route: route.fulfill( "**/api/form-status/**",
status=200, lambda route: route.fulfill(
content_type="application/json", status=200,
body='{"status":"open"}', content_type="application/json",
), body='{"status":"open"}',
)
page.route(
"**/api/roster**",
lambda route: route.fulfill(
status=200,
content_type="application/json",
body=json.dumps(
{
"employees": [
{"name": "Ada Lovelace", "email": "ada@example.com"}
]
}
), ),
), )
) page.route(
page.goto(out.as_uri()) "**/api/roster**",
page.wait_for_selector('[data-meal-index="0"]') lambda route: route.fulfill(
yield page status=200,
browser.close() content_type="application/json",
body=json.dumps(
{
"employees": [
{
"name": "Ada Lovelace",
"email": "ada@example.com",
}
]
}
),
),
)
page.goto(out.as_uri())
page.wait_for_selector('[data-meal-index="0"]')
yield page
finally:
browser.close()
def test_admin_bundle_loads(self, browser_page): def test_admin_bundle_loads(self, browser_page):
assert browser_page.evaluate("typeof window.loadWeekOrders") == "function" assert browser_page.evaluate("typeof window.loadWeekOrders") == "function"