|
| 1 | +const assert = require('node:assert'); |
| 2 | +const http = require('node:http'); |
| 3 | +const { describe, it } = require('node:test'); |
| 4 | + |
| 5 | +describe('scientific charts, part 2', () => { |
| 6 | + describe('heatmaps', () => { |
| 7 | + it('Basic Heatmap', () => { |
| 8 | + const options = { |
| 9 | + port: 3000, |
| 10 | + host: 'localhost', |
| 11 | + method: 'POST' |
| 12 | + }; |
| 13 | + |
| 14 | + const req = http.request(options); |
| 15 | + // Data taken from https://plotly.com/javascript/heatmaps/#basic-heatmap example. |
| 16 | + const payload = `{ |
| 17 | + "data": [ |
| 18 | + { |
| 19 | + "z": [ [ 1, 20, 30 ], |
| 20 | + [ 20, 1, 60 ], |
| 21 | + [ 30, 60, 1 ] |
| 22 | + ], |
| 23 | + "type": "heatmap" |
| 24 | + } |
| 25 | + ], |
| 26 | + "layout": {} |
| 27 | + }`; |
| 28 | + req.write(payload); |
| 29 | + req.end(); |
| 30 | + |
| 31 | + req.on('response', (response) => { |
| 32 | + assert.strictEqual(500, response.statusCode); |
| 33 | + let body = ''; |
| 34 | + response.on('data', (chunk) => { |
| 35 | + body += chunk; |
| 36 | + }); |
| 37 | + response.on('end', () => { |
| 38 | + // Browser-based answer is an SVG with embedded binary PNG image data |
| 39 | + // (due to heatmap colouring). |
| 40 | + |
| 41 | + // Currently, the server cannot handle that and returns HTTP status code 500. |
| 42 | + // Reasons seem to be the heatmap colouring and the labels. |
| 43 | + assert.ok(body == '{"success":false,"failure":"promise-rejected"}'); |
| 44 | + }); |
| 45 | + }); |
| 46 | + }); |
| 47 | + |
| 48 | + // TODO: Heatmap with Categorical Axis Labels - https://plotly.com/javascript/heatmaps/#heatmap-with-categorical-axis-labels |
| 49 | + // TODO: Annotated Heatmap - https://plotly.com/javascript/heatmaps/#annotated-heatmap |
| 50 | + // TODO: Heatmap with Unequal Block Sizes - https://plotly.com/javascript/heatmaps/#heatmap-with-unequal-block-sizes |
| 51 | + |
| 52 | +/* |
| 53 | + it('request with different data', () => { |
| 54 | + const options = { |
| 55 | + port: 3000, |
| 56 | + host: 'localhost', |
| 57 | + method: 'POST' |
| 58 | + }; |
| 59 | +
|
| 60 | + const req = http.request(options); |
| 61 | + // Data taken from https://plotly.com/javascript/... example. |
| 62 | + const payload = '{ "x": ["2013-10-04 22:23:00", "2013-11-04 22:23:00", "2013-12-04 22:23:00"], "y": [1, 3, 6], "type": "scatter" }'; |
| 63 | + req.write(payload); |
| 64 | + req.end(); |
| 65 | +
|
| 66 | + req.on('response', (response) => { |
| 67 | + assert.strictEqual(200, response.statusCode); |
| 68 | + let body = ''; |
| 69 | + response.on('data', (chunk) => { |
| 70 | + body += chunk; |
| 71 | + }); |
| 72 | + response.on('end', () => { |
| 73 | + assert.ok(body.startsWith('<svg')); |
| 74 | + assert.ok(body.endsWith('</svg>')); |
| 75 | +
|
| 76 | + // Browser-based answer is something like |
| 77 | + // <svg .. |
| 78 | +
|
| 79 | + // Current server response is visually almost the same. |
| 80 | + // <svg ... |
| 81 | +
|
| 82 | + // Check partial matches, avoiding the random id bits. |
| 83 | + assert.ok(body.indexOf('') >= 0); |
| 84 | + assert.ok(body.indexOf('') > 0); |
| 85 | + assert.ok(body.indexOf('') > 0); |
| 86 | + }); |
| 87 | + }); |
| 88 | + }); |
| 89 | + */ |
| 90 | + }); |
| 91 | +}); |
0 commit comments