Skip to content

Commit d5a1abe

Browse files
authored
NGINXaaS: update NGINXaaS Cost Estimator with Tiered pricing
1 parent 15fe69a commit d5a1abe

File tree

4 files changed

+81
-18
lines changed

4 files changed

+81
-18
lines changed

.github/workflows/playwright.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,16 @@ on:
33
push:
44
branches: [main]
55
paths:
6-
- 'static/nginxaas-azure/js/cost-calculator_v2.js'
6+
- 'static/nginxaas-azure/js/cost-calculator_v2.js'
77
- 'content/nginxaas-azure/billing/usage-and-cost-estimator.md'
8+
- 'static/nginxaas-google/js/cost-calculator_gc.js'
9+
- 'content/nginxaas-google/billing/usage-and-cost-estimator.md'
810
pull_request:
911
paths:
1012
- 'static/nginxaas-azure/js/cost-calculator_v2.js'
1113
- 'content/nginxaas-azure/billing/usage-and-cost-estimator.md'
14+
- 'static/nginxaas-google/js/cost-calculator_gc.js'
15+
- 'content/nginxaas-google/billing/usage-and-cost-estimator.md'
1216
permissions:
1317
contents: read
1418
jobs:

content/nginxaas-google/billing/usage-and-cost-estimator.md

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,25 @@ nd-product: NGOOGL
1111
{{< raw-html >}}
1212
<link rel="stylesheet" href="/nginxaas-google/css/cost-calculator_v2.css">
1313
<div id="calculator">
14-
<h3 id="calculator-section-heading">
14+
<h3 id="calculator-section-heading" data-testid="calculator-section-heading">
1515
Cost Estimation for Enterprise Plan
1616
<button id="printButton">Print Estimate</button>
1717
</h3>
1818

19-
<div class="section">
19+
<div class="section" data-testid="calculator-section-content">
2020
<div class="form-section">
2121
<div class="form-section-content">
2222
<h4 id="calculator-section-heading">Estimate Monthly Cost</h4>
2323

24+
<div class="form-field">
25+
<label for="tierSelect">Tier</label>
26+
<select id="tierSelect">
27+
<option value="tier1">Tier 1</option>
28+
<option value="tier2">Tier 2</option>
29+
<option value="tier3">Tier 3</option>
30+
</select>
31+
</div>
32+
2433
<div class="form-field">
2534
<label for="numNcus">NCUs</label>
2635
<input id="numNcus" type="number" step="10" min="10" />
@@ -42,7 +51,7 @@ nd-product: NGOOGL
4251
<div class="form-section-content">
4352
<div id="totals-section">
4453
<span class="total-text">Total Monthly Payment</span>
45-
<span id="total-value" class="total-text">--</span>
54+
<span id="total-value" class="total-text" data-testid="total-value">--</span>
4655

4756
<details id="total-cost-details">
4857
<summary>Show calculations</summary>

static/nginxaas-google/js/cost-calculator_gc.js

Lines changed: 38 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,25 @@
11
// /nginxaas-google/js/cost-calculator_v2.js
22
(() => {
3-
// ---- Single-tier pricing ----
4-
const costs = {
5-
fixedHourly: 0.10, // $/hour
6-
ncuHourly: 0.008, // $/NCU/hour
7-
dataPerGb: 0.0096 // $/GB (monthly)
3+
// ---- Multi-tier pricing ----
4+
const tierCosts = {
5+
tier1: {
6+
fixedHourly: 0.10, // $/hour
7+
ncuHourly: 0.008, // $/NCU/hour
8+
dataPerGb: 0.0096 // $/GB (monthly)
9+
},
10+
tier2: {
11+
fixedHourly: 0.133,
12+
ncuHourly: 0.0106,
13+
dataPerGb: 0.0127
14+
},
15+
tier3: {
16+
fixedHourly: 0.166,
17+
ncuHourly: 0.0132,
18+
dataPerGb: 0.0159
19+
}
820
};
21+
let currentTier = "tier1";
22+
let costs = tierCosts[currentTier];
923

1024
const utils = {
1125
calculateCost: (costs, values) => {
@@ -31,6 +45,7 @@
3145

3246
// ---- Element refs ----
3347
const costFormElements = {
48+
tierSelect: document.getElementById("tierSelect"),
3449
numNcus: document.getElementById("numNcus"),
3550
numHours: document.getElementById("numHours"),
3651
dataProcessedGb: document.getElementById("dataProcessedGb"),
@@ -47,11 +62,17 @@
4762
};
4863

4964
// ---- Listeners ----
50-
const setupChangeListeners = (costs, values = calculatorValuesState) => {
65+
const setupChangeListeners = (values = calculatorValuesState) => {
5166
Object.keys(costFormElements).forEach((elName) => {
5267
costFormElements[elName].addEventListener("change", (evt) => {
53-
values[elName] = Number(evt.target.value);
54-
updateCost(costs);
68+
if (elName === "tierSelect") {
69+
currentTier = evt.target.value;
70+
costs = tierCosts[currentTier];
71+
updateCost(costs, values);
72+
} else {
73+
values[elName] = Number(evt.target.value);
74+
updateCost(costs, values);
75+
}
5576
});
5677
});
5778

@@ -65,7 +86,11 @@
6586
Object.keys(costFormElements).forEach((elName) => {
6687
const el = costFormElements[elName];
6788
if (el && (el.tagName.toLowerCase() === "input" || el.tagName.toLowerCase() === "select")) {
68-
el.value = values[elName];
89+
if (elName === "tierSelect") {
90+
el.value = currentTier;
91+
} else {
92+
el.value = values[elName];
93+
}
6994
}
7095
});
7196
};
@@ -74,10 +99,10 @@
7499
const updateCost = (costs, values = calculatorValuesState) => {
75100
const updatedTotalCost = utils.calculateCost(costs, values);
76101
document.getElementById("total-value").textContent = utils.currencyFormatter(updatedTotalCost);
77-
updateTotalCostDetails(values, updatedTotalCost);
102+
updateTotalCostDetails(values, updatedTotalCost, costs);
78103
};
79104

80-
const updateTotalCostDetails = (formValues, totalCost) => {
105+
const updateTotalCostDetails = (formValues, totalCost, costs) => {
81106
totalCostDetailElements.hours.textContent = formValues.numHours;
82107
totalCostDetailElements.ncus.textContent = formValues.numNcus;
83108
totalCostDetailElements.fixedHourly.textContent = utils.currencyFormatter(costs.fixedHourly, 3);
@@ -99,10 +124,9 @@
99124

100125
// ---- Boot ----
101126
const start = async () => {
102-
const loaded = costs;
103-
setupChangeListeners(loaded);
127+
setupChangeListeners();
104128
initializeValues(calculatorValuesState);
105-
updateCost(loaded); // immediately show total on load
129+
updateCost(costs, calculatorValuesState); // immediately show total on load
106130
};
107131
start();
108132
})();

tests/src/n4g-calculator.spec.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { expect, test } from "@playwright/test";
2+
import { handleConsentPopup, waitFor } from "../util";
3+
4+
test.describe("Testing for N4G calculator page", () => {
5+
test.beforeEach(async ({ page }) => {
6+
await page.goto("/nginxaas/google/billing/usage-and-cost-estimator/");
7+
await page.waitForLoadState("load");
8+
await waitFor(async () => await handleConsentPopup(page));
9+
});
10+
11+
test("calculator renders", async ({ page }) => {
12+
const header = page.getByTestId("calculator-section-heading");
13+
const content = page.getByTestId("calculator-section-content");
14+
15+
await expect(header).toBeVisible();
16+
await expect(content).toBeVisible();
17+
});
18+
19+
test("calculator values render", async ({ page }) => {
20+
// Conjunction - If outputs are rendered, it is safe to say the inputs are rendered.
21+
// NOT testing changing numbers will impact the total values as that should be the job of unit tests. This is just a smoke tests.
22+
const totalValue = page.getByTestId("total-value");
23+
24+
expect(await totalValue.textContent()).toBeTruthy();
25+
});
26+
});

0 commit comments

Comments
 (0)