Skip to content

Commit 6488c50

Browse files
committed
fix: ran prettier on statistics.test.js
1 parent 73123bf commit 6488c50

File tree

1 file changed

+44
-41
lines changed

1 file changed

+44
-41
lines changed

js/widgets/statistics.test.js

Lines changed: 44 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* MusicBlocks
33
*
4-
* @author Om-A-osc
4+
* @author Om-A-osc
55
*
66
* @copyright 2026 Om-A-osc
77
*
@@ -20,9 +20,9 @@
2020
* along with this program. If not, see <https://www.gnu.org/licenses/>.
2121
*/
2222

23-
const { StatsWindow } = require('./statistics.js');
23+
const { StatsWindow } = require("./statistics.js");
2424

25-
describe('StatsWindow', () => {
25+
describe("StatsWindow", () => {
2626
let statsWindow;
2727
let mockActivity;
2828
let mockWidgetWindowInstance;
@@ -38,7 +38,7 @@ describe('StatsWindow', () => {
3838

3939
// Mock DOM elements and global functions/objects
4040
const mockBody = {
41-
innerHTML: '',
41+
innerHTML: "",
4242
style: {},
4343
appendChild: jest.fn(),
4444
getBoundingClientRect: jest.fn(() => ({ height: 500 }))
@@ -63,42 +63,46 @@ describe('StatsWindow', () => {
6363
const MockWidgetWindows = {
6464
windowFor: jest.fn(() => mockWidgetWindowInstance)
6565
};
66-
Object.defineProperty(window, 'widgetWindows', {
66+
Object.defineProperty(window, "widgetWindows", {
6767
writable: true,
6868
value: MockWidgetWindows
6969
});
7070

7171
mockMyChart = {
72-
getContext: jest.fn(() => ({})), // Return a mock context
72+
getContext: jest.fn(() => ({})) // Return a mock context
7373
};
74-
global.docById = jest.fn((id) => {
75-
if (id === 'myChart') {
74+
global.docById = jest.fn(id => {
75+
if (id === "myChart") {
7676
return mockMyChart;
7777
}
78-
return document.createElement('ul');
78+
return document.createElement("ul");
7979
});
80-
81-
document.createElement = jest.fn((tag) => {
82-
if (tag === 'ul') {
80+
81+
document.createElement = jest.fn(tag => {
82+
if (tag === "ul") {
8383
return {
8484
style: {},
85-
innerHTML: ''
85+
innerHTML: ""
8686
};
8787
}
8888
return {};
8989
});
9090

91-
global.analyzeProject = jest.fn(() => ({ /* mock scores */ }));
91+
global.analyzeProject = jest.fn(() => ({
92+
/* mock scores */
93+
}));
9294
global.runAnalytics = jest.fn();
93-
global.scoreToChartData = jest.fn(() => ({ /* mock chart data */ }));
94-
95+
global.scoreToChartData = jest.fn(() => ({
96+
/* mock chart data */
97+
}));
98+
9599
const mockRadarChart = {
96-
toBase64Image: jest.fn(() => 'data:image/png;base64,mocked-image-data')
100+
toBase64Image: jest.fn(() => "data:image/png;base64,mocked-image-data")
97101
};
98-
102+
99103
// The callback needs to be captured to be called manually.
100104
let onCompleteCallback;
101-
global.getChartOptions = jest.fn((callback) => {
105+
global.getChartOptions = jest.fn(callback => {
102106
onCompleteCallback = callback;
103107
return {
104108
animation: {
@@ -120,18 +124,18 @@ describe('StatsWindow', () => {
120124
global.Chart = mockChartConstructor;
121125

122126
mockImageConstructor = jest.fn(() => ({
123-
src: '',
127+
src: "",
124128
width: 0,
125129
style: {}
126130
}));
127131
global.Image = mockImageConstructor;
128132

129133
// Mock document.body.style
130-
Object.defineProperty(document, 'body', {
134+
Object.defineProperty(document, "body", {
131135
writable: true,
132136
value: {
133137
style: {
134-
cursor: 'default'
138+
cursor: "default"
135139
}
136140
}
137141
});
@@ -141,13 +145,13 @@ describe('StatsWindow', () => {
141145
blocks: {
142146
showBlocks: jest.fn(),
143147
hideBlocks: jest.fn(),
144-
activeBlock: null,
148+
activeBlock: null
145149
},
146150
logo: {
147-
statsWindow: null,
151+
statsWindow: null
148152
},
149153
loading: false,
150-
showBlocksAfterRun: false,
154+
showBlocksAfterRun: false
151155
};
152156

153157
statsWindow = new StatsWindow(mockActivity);
@@ -158,7 +162,7 @@ describe('StatsWindow', () => {
158162
}
159163
});
160164

161-
test('constructor initializes correctly', () => {
165+
test("constructor initializes correctly", () => {
162166
expect(statsWindow).toBeDefined();
163167
expect(statsWindow.activity).toBe(mockActivity);
164168
expect(statsWindow.isOpen).toBe(true);
@@ -170,7 +174,7 @@ describe('StatsWindow', () => {
170174
expect(global.analyzeProject).toHaveBeenCalledWith(mockActivity);
171175
});
172176

173-
test('onclose callback sets isOpen to false, shows blocks, destroys window, and nulls statsWindow', () => {
177+
test("onclose callback sets isOpen to false, shows blocks, destroys window, and nulls statsWindow", () => {
174178
expect(statsWindow.widgetWindow.onclose).toBeInstanceOf(Function);
175179

176180
statsWindow.widgetWindow.onclose();
@@ -181,7 +185,7 @@ describe('StatsWindow', () => {
181185
expect(mockActivity.logo.statsWindow).toBeNull();
182186
});
183187

184-
test('doAnalytics calls analytics functions and updates DOM', () => {
188+
test("doAnalytics calls analytics functions and updates DOM", () => {
185189
// Since doAnalytics is called in the constructor, we can check the effects.
186190
expect(mockActivity.blocks.activeBlock).toBeNull();
187191
expect(global.docById).toHaveBeenCalledWith("myChart");
@@ -201,7 +205,7 @@ describe('StatsWindow', () => {
201205
// After the Chart callback, check Image and appendChild
202206
expect(mockImageConstructor).toHaveBeenCalled();
203207
const imgInstance = mockImageConstructor.mock.results[0].value;
204-
expect(imgInstance.src).toBe('data:image/png;base64,mocked-image-data');
208+
expect(imgInstance.src).toBe("data:image/png;base64,mocked-image-data");
205209
expect(imgInstance.width).toBe(200); // Not maximized by default
206210
expect(mockGetWidgetBody().appendChild).toHaveBeenCalledWith(imgInstance);
207211

@@ -213,14 +217,14 @@ describe('StatsWindow', () => {
213217
expect(statsWindow.jsonObject.style.float).toBe("left");
214218
expect(mockGetWidgetBody().appendChild).toHaveBeenCalledWith(statsWindow.jsonObject);
215219
});
216-
217-
test('doAnalytics adjusts image width when maximized', () => {
220+
221+
test("doAnalytics adjusts image width when maximized", () => {
218222
// This test is now self-contained
219223
jest.clearAllMocks(); // Clear all mocks to avoid interference from beforeEach
220224

221225
// Redefine mocks needed for this specific test
222226
let capturedOnComplete;
223-
const mockRadarChart = { toBase64Image: () => 'data:image/png;base64,mocked-image-data' };
227+
const mockRadarChart = { toBase64Image: () => "data:image/png;base64,mocked-image-data" };
224228
mockChartConstructor = jest.fn().mockImplementation(() => ({
225229
Radar: jest.fn((data, options) => {
226230
if (options && options.animation && options.animation.onComplete) {
@@ -230,13 +234,13 @@ describe('StatsWindow', () => {
230234
})
231235
}));
232236
global.Chart = mockChartConstructor;
233-
global.Image = jest.fn(() => ({ src: '', width: 0, style: {} }));
237+
global.Image = jest.fn(() => ({ src: "", width: 0, style: {} }));
234238
global.docById = jest.fn(() => ({ getContext: () => ({}) }));
235-
239+
236240
mockWidgetWindowInstance.isMaximized.mockReturnValue(true); // Simulate maximized state
237-
241+
238242
statsWindow.doAnalytics();
239-
243+
240244
// Manually fire the callback that was captured inside this specific doAnalytics call
241245
if (capturedOnComplete) {
242246
capturedOnComplete();
@@ -247,7 +251,7 @@ describe('StatsWindow', () => {
247251
expect(imgInstance.width).toBe(500 - 80); // 420
248252
});
249253

250-
test('displayInfo correctly updates jsonObject innerHTML', () => {
254+
test("displayInfo correctly updates jsonObject innerHTML", () => {
251255
const mockStats = {
252256
duples: 10,
253257
triplets: 5,
@@ -277,9 +281,9 @@ describe('StatsWindow', () => {
277281
expect(statsWindow.jsonObject.innerHTML).toBe(expectedHtml);
278282
});
279283

280-
test('onmaximize callback handles maximized and unmaximized states', () => {
284+
test("onmaximize callback handles maximized and unmaximized states", () => {
281285
let capturedOnComplete;
282-
global.getChartOptions = jest.fn((callback) => {
286+
global.getChartOptions = jest.fn(callback => {
283287
capturedOnComplete = callback;
284288
return {
285289
animation: { onComplete: callback }
@@ -303,9 +307,8 @@ describe('StatsWindow', () => {
303307
mockWidgetWindowInstance.isMaximized.mockReturnValue(false);
304308
statsWindow.widgetWindow.onmaximize();
305309
if (capturedOnComplete) capturedOnComplete();
306-
310+
307311
expect(widgetBody.innerHTML).toBe(""); // Cleared again
308312
expect(widgetBody.style.padding).toBe("0 0");
309313
});
310-
311314
});

0 commit comments

Comments
 (0)