From f8fd7ee1a1943d42515514f12cc537f9977724f5 Mon Sep 17 00:00:00 2001 From: Mavamudi Date: Fri, 27 Nov 2026 23:02:56 -0300 Subject: [PATCH] Hide buyer shipping rates table --- index.html | 2 +- js/mall/mall-purchases.js | 35 ++------------------- tests/unit/purchase-payment-options.test.js | 24 +++++++++++--- 3 files changed, 22 insertions(+), 39 deletions(-) diff --git a/index.html b/index.html index b726488..947596b 100644 --- a/index.html +++ b/index.html @@ -1613,7 +1613,7 @@

Tótems de búsqueda

- + diff --git a/js/mall/mall-purchases.js b/js/mall/mall-purchases.js index 260d476..205032f 100644 --- a/js/mall/mall-purchases.js +++ b/js/mall/mall-purchases.js @@ -259,12 +259,6 @@ -
-

Costos de despacho de este local

-
-

Cargando tarifas...

-
-

Datos del comprador y despacho

@@ -336,19 +330,16 @@ window.closePurchaseForm = closePurchaseForm; function renderShippingRates(rates = []) { - const tableContainer = document.getElementById('purchase-shipping-table'); const select = document.getElementById('purchase-delivery-commune'); const submit = document.getElementById('purchase-submit'); - if (!tableContainer || !select || !submit) return; + if (!select || !submit) return; const selectedCommune = select.value; - tableContainer.innerHTML = ''; select.innerHTML = ''; select.appendChild(createElement('option', 'Selecciona una comuna')); select.firstElementChild.value = ''; if (!rates.length) { - tableContainer.appendChild(createElement('p', 'Este local aún no ha configurado costos de despacho.', 'purchase-muted')); SANTIAGO_COMMUNES.forEach((commune) => { const option = createElement('option', commune); option.value = commune; @@ -360,32 +351,12 @@ return; } - const table = document.createElement('table'); - table.className = 'purchase-shipping-table'; - const thead = document.createElement('thead'); - const headerRow = document.createElement('tr'); - headerRow.appendChild(createElement('th', 'Comuna')); - headerRow.appendChild(createElement('th', 'Costo de despacho')); - thead.appendChild(headerRow); - const tbody = document.createElement('tbody'); - const ratesByCommune = new Map(rates.map((rate) => [rate.commune.toLocaleLowerCase('es-CL'), rate])); - rates.forEach((rate) => { - const row = document.createElement('tr'); - row.appendChild(createElement('td', rate.commune)); - row.appendChild(createElement('td', formatCurrency(rate.shipping_cost))); - tbody.appendChild(row); - }); SANTIAGO_COMMUNES.forEach((commune) => { - const rate = ratesByCommune.get(commune.toLocaleLowerCase('es-CL')); - const option = createElement('option', rate - ? `${commune} - ${formatCurrency(rate.shipping_cost)}` - : `${commune} - Sin despacho configurado`); + const option = createElement('option', commune); option.value = commune; select.appendChild(option); }); if (SANTIAGO_COMMUNES.includes(selectedCommune)) select.value = selectedCommune; - table.append(thead, tbody); - tableContainer.appendChild(table); select.disabled = false; submit.disabled = true; } @@ -418,7 +389,6 @@ async function loadPurchaseRates(product, requestId) { const client = getClient(); - const table = document.getElementById('purchase-shipping-table'); const select = document.getElementById('purchase-delivery-commune'); const submit = document.getElementById('purchase-submit'); if (!client || !product?.storeId) { @@ -429,7 +399,6 @@ return; } - if (table) table.innerHTML = '

Cargando tarifas...

'; if (select) select.disabled = false; if (submit) submit.disabled = true; purchaseState.ratesLoading = true; diff --git a/tests/unit/purchase-payment-options.test.js b/tests/unit/purchase-payment-options.test.js index 3553bd9..8df8d2b 100644 --- a/tests/unit/purchase-payment-options.test.js +++ b/tests/unit/purchase-payment-options.test.js @@ -8,6 +8,15 @@ const purchases = fs.readFileSync(path.join(root, 'js/mall/mall-purchases.js'), const migration = fs.readFileSync(path.join(root, 'supabase/store_payment_options_20260927.sql'), 'utf8'); const ui = fs.readFileSync(path.join(root, 'js/mall/mall-ui.js'), 'utf8'); +assert.doesNotMatch(purchases, /purchase-shipping-table|purchase-shipping-table-wrap/, + 'The buyer checkout must not expose the full store commune and shipping-rate table.'); +assert.doesNotMatch(purchases, /Costos de despacho de este local/, + 'The buyer checkout must not show the removed shipping-rate section title.'); +assert.match(purchases, /id="purchase-delivery-commune"/, + 'The buyer keeps the commune selector.'); +assert.match(purchases, /id="purchase-shipping-summary"/, + 'The buyer keeps the selected shipping-cost summary.'); + const optionBlock = purchases.match(/const PAYMENT_OPTIONS = Object\.freeze\(\[([\s\S]*?)\]\);/); assert.ok(optionBlock, 'The checkout must declare its supported payment alternatives.'); const optionValues = [...optionBlock[1].matchAll(/value: '([^']+)'/g)].map((match) => match[1]); @@ -74,11 +83,9 @@ function makeElement(tagName) { return element; } -const shippingTable = makeElement('div'); const communeSelect = makeElement('select'); const purchaseButton = makeElement('button'); const shippingElements = { - 'purchase-shipping-table': shippingTable, 'purchase-delivery-commune': communeSelect, 'purchase-submit': purchaseButton }; @@ -104,12 +111,15 @@ renderContext.renderShippingRates([]); assert.equal(communeSelect.disabled, false, 'The commune selector stays enabled when the tenant has no rates yet.'); assert.equal(communeSelect.children.length, 53, 'All 52 communes remain available beside the placeholder.'); assert.ok(communeSelect.children.slice(1).every((option) => !option.disabled), 'No-rate communes remain selectable.'); +assert.ok(communeSelect.children.slice(1).every((option) => option.textContent === option.value), + 'Commune options show only their name when the tenant has no rates yet.'); assert.equal(purchaseButton.disabled, true, 'A purchase cannot be sent without a shipping price.'); renderContext.renderShippingRates([{commune: 'Providencia', shipping_cost: 2500}]); assert.equal(communeSelect.disabled, false); assert.ok(communeSelect.children.slice(1).every((option) => !option.disabled), 'Communes remain selectable while rates are partial.'); -assert.match(communeSelect.children.find((option) => option.value === 'Vitacura').textContent, /Sin despacho configurado/); +assert.ok(communeSelect.children.slice(1).every((option) => option.textContent === option.value), + 'Commune options do not expose rates or availability details.'); const shippingSummary = makeElement('p'); const selectedCommune = makeElement('select'); @@ -125,6 +135,7 @@ const summaryContext = { })[id] }, purchaseState: {rates: [{commune: 'Providencia', shipping_cost: 2500}]}, + formatCurrency: (value) => `$${value}`, updatePurchasePaymentSummary: () => { paymentSummaryUpdated = true; } }; const summaryStart = purchases.indexOf(' function updatePurchaseShippingSummary('); @@ -136,7 +147,11 @@ assert.match(shippingSummary.textContent, /no ha configurado el costo de despach assert.equal(summaryButton.disabled, true); assert.equal(paymentSummaryUpdated, true, 'Payment details refresh when the selected commune has no rate.'); -const loadingTable = makeElement('div'); +selectedCommune.value = 'Providencia'; +summaryContext.updatePurchaseShippingSummary(); +assert.match(shippingSummary.textContent, /Despacho a Providencia: \$2500/); +assert.equal(summaryButton.disabled, false, 'A purchase can continue when the selected commune has a valid rate.'); + const loadingSelect = makeElement('select'); loadingSelect.disabled = true; const loadingSubmit = makeElement('button'); @@ -151,7 +166,6 @@ const loadingState = {requestId: 7, rates: [], ratesLoading: false}; const loadingContext = { document: { getElementById: (id) => ({ - 'purchase-shipping-table': loadingTable, 'purchase-delivery-commune': loadingSelect, 'purchase-submit': loadingSubmit })[id]