Add more unit tests

This commit is contained in:
Christian Paul 2022-05-01 15:20:17 +02:00
parent 3f4bd472cf
commit 7b80ac883a
4 changed files with 43 additions and 0 deletions

10
src/BrailleBuffer.spec.js Normal file
View File

@ -0,0 +1,10 @@
import BrailleBuffer from './BrailleBuffer.js';
const termReset = '\x1B[39;49m';
describe('BrailleBuffer', () => {
test('starts a frame with term reset characters', async () => {
const brailleBuffer = new BrailleBuffer(1, 1);
expect(brailleBuffer.frame().startsWith(termReset)).toBe(true);
});
});

21
src/Renderer.spec.js Normal file
View File

@ -0,0 +1,21 @@
import fsPromises from 'fs/promises';
import Renderer from './Renderer';
import TileSource from './TileSource.js';
const center = {
lat: 52.51298,
lon: 13.42012,
};
describe('Renderer', () => {
describe('with a HTTP source', () => {
test('does not crash when creating a Renderer', async () => {
const tileSource = new TileSource();
await tileSource.init('http://mapscii.me/');
const style = JSON.parse(await fsPromises.readFile('./styles/dark.json'));
const renderer = new Renderer(tileSource, style);
renderer.setSize(30, 30);
expect(await renderer.draw(center, 13)).toMatchSnapshot();
});
});
});

12
src/Styler.spec.js Normal file
View File

@ -0,0 +1,12 @@
import fsPromises from 'fs/promises';
import Styler from './Styler';
describe('Styler', () => {
describe('getStyleFor', () => {
test('returns false for landuse_park, line', async () => {
const style = JSON.parse(await fsPromises.readFile('./styles/dark.json'));
const styler = new Styler(style);
expect(styler.getStyleFor('landuse_park', 'line')).toBe(false);
});
});
});

Binary file not shown.