|
6 | 6 | import {beforeEach, beforeAll, describe, expect, it} from "vitest"; |
7 | 7 | import {select as d3Select} from "d3-selection"; |
8 | 8 | import {format as d3Format} from "d3-format"; |
| 9 | +import sinon from "sinon"; |
9 | 10 | import {$AREA, $AXIS, $COMMON, $CIRCLE, $EVENT, $LEGEND, $LINE} from "../../src/config/classes"; |
10 | 11 | import util from "../assets/util"; |
11 | 12 |
|
@@ -1275,4 +1276,57 @@ describe("API load", function() { |
1275 | 1276 | }); |
1276 | 1277 | })); |
1277 | 1278 | }); |
| 1279 | + |
| 1280 | + describe("Unload callback sequence with transition duration 0", () => { |
| 1281 | + beforeAll(() => { |
| 1282 | + args = { |
| 1283 | + data: { |
| 1284 | + columns: [ |
| 1285 | + ["data1", 30, 200, 100, 400, 150, 250], |
| 1286 | + ["data2", 50, 20, 10, 40, 15, 25] |
| 1287 | + ], |
| 1288 | + empty: { |
| 1289 | + label: { |
| 1290 | + text: "No Data" |
| 1291 | + } |
| 1292 | + } |
| 1293 | + }, |
| 1294 | + transition: { |
| 1295 | + duration: 0 |
| 1296 | + } |
| 1297 | + }; |
| 1298 | + }); |
| 1299 | + |
| 1300 | + it("should show 'No Data' text after unload callback when transition.duration=0", () => new Promise(done => { |
| 1301 | + const doneSpy = sinon.spy(); |
| 1302 | + const {$el} = chart.internal; |
| 1303 | + |
| 1304 | + // Verify "No Data" text is not visible initially |
| 1305 | + let emptyText = $el.main.select("text.bb-text.bb-empty"); |
| 1306 | + expect(emptyText.empty() || emptyText.style("display") === "none").to.be.true; |
| 1307 | + |
| 1308 | + // when |
| 1309 | + chart.unload({ |
| 1310 | + ids: ["data1", "data2"], |
| 1311 | + done() { |
| 1312 | + doneSpy(); |
| 1313 | + |
| 1314 | + // Check if "No Data" text is visible after unload callback |
| 1315 | + // This tests the fix where unload callback should run after data are unloaded |
| 1316 | + const {$el} = this.internal; |
| 1317 | + const emptyText = $el.main.select("text.bb-text.bb-empty"); |
| 1318 | + |
| 1319 | + expect(doneSpy.calledOnce).to.be.true; |
| 1320 | + expect(emptyText.empty()).to.be.false; |
| 1321 | + expect(emptyText.text()).to.be.equal("No Data"); |
| 1322 | + expect(emptyText.style("display")).to.not.equal("none"); |
| 1323 | + |
| 1324 | + // Verify that all data has been unloaded |
| 1325 | + expect(this.data().length).to.be.equal(0); |
| 1326 | + |
| 1327 | + done(1); |
| 1328 | + } |
| 1329 | + }); |
| 1330 | + })); |
| 1331 | + }); |
1278 | 1332 | }); |
0 commit comments