General source code refactoring
This commit is contained in:
36
tests/fixtures/consumption-trend.html
vendored
36
tests/fixtures/consumption-trend.html
vendored
@@ -12,25 +12,21 @@
|
||||
</head>
|
||||
<body>
|
||||
<div id="opportunities-extension-modal" class="opportunities-extension-modal" data-theme="light"></div>
|
||||
<script src="/fixture-runtime.js"></script>
|
||||
<script>
|
||||
window.chrome = { runtime: { onMessage: { addListener() {} } } };
|
||||
|
||||
async function initialize() {
|
||||
const source = await fetch("/src/content.js").then((response) => response.text());
|
||||
const marker = /\r?\n if \(insertTile\(\)\) \{/;
|
||||
const exposure = `
|
||||
window.__trendHarness = {
|
||||
ensureStyles: ensureExtensionStyles,
|
||||
createAccountPlanDetails,
|
||||
createConsumptionTrendSection,
|
||||
renderConsumptionTrendChart
|
||||
};
|
||||
return;
|
||||
`;
|
||||
const testableSource = source
|
||||
.replace(" if (!isAllowedPage()) {", " if (false) {")
|
||||
.replace(marker, `${exposure}\n if (insertTile()) {`);
|
||||
window.eval(testableSource);
|
||||
const app = window.createFixtureApplication({
|
||||
fetch: () => Promise.reject(new Error("Network disabled in fixture")),
|
||||
browser: undefined,
|
||||
chrome: undefined
|
||||
});
|
||||
const harness = {
|
||||
ensureStyles: app.contentStyles.ensureExtensionStyles,
|
||||
createAccountPlanDetails: app.consumptionPlansView.createAccountPlanDetails,
|
||||
createConsumptionTrendSection: app.consumptionTrendController.createConsumptionTrendSection,
|
||||
renderConsumptionTrendChart: app.consumptionChart.renderConsumptionTrendChart
|
||||
};
|
||||
|
||||
const plan = {
|
||||
subPlanNum: "11276098",
|
||||
@@ -63,7 +59,7 @@
|
||||
return rows;
|
||||
});
|
||||
|
||||
window.__trendHarness.ensureStyles();
|
||||
harness.ensureStyles();
|
||||
const overlay = document.getElementById("opportunities-extension-modal");
|
||||
overlay.dataset.theme = new URLSearchParams(window.location.search).get("theme") === "dark"
|
||||
? "dark"
|
||||
@@ -82,13 +78,13 @@
|
||||
tabs.innerHTML = '<button class="opportunities-extension-account-plan-tab" aria-selected="true"><span class="opportunities-extension-account-plan-status-indicator" data-active="true"></span>Universal Credits 11276098</button>';
|
||||
const panel = document.createElement("section");
|
||||
panel.className = "opportunities-extension-account-plan-panel";
|
||||
const trend = window.__trendHarness.createConsumptionTrendSection(plan);
|
||||
panel.append(window.__trendHarness.createAccountPlanDetails(plan), trend);
|
||||
const trend = harness.createConsumptionTrendSection(plan);
|
||||
panel.append(harness.createAccountPlanDetails(plan), trend);
|
||||
content.append(tabs, panel);
|
||||
dialog.append(header, content);
|
||||
modal.append(dialog);
|
||||
overlay.append(modal);
|
||||
window.__trendHarness.renderConsumptionTrendChart(
|
||||
harness.renderConsumptionTrendChart(
|
||||
trend,
|
||||
trend.querySelector(".opportunities-extension-consumption-chart"),
|
||||
items,
|
||||
|
||||
Reference in New Issue
Block a user