Skip to content

Instantly share code, notes, and snippets.

@YonatanKra
Created August 4, 2021 04:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save YonatanKra/3240fa72ce9668ef24d2cbe44f6ac700 to your computer and use it in GitHub Desktop.
Save YonatanKra/3240fa72ce9668ef24d2cbe44f6ac700 to your computer and use it in GitHub Desktop.
describe(`draw`, function() {
let house: House, canvas: HTMLCanvasElement, ctx: CanvasRenderingContext2D | any;
beforeEach(function() {
canvas = document.createElement('canvas');
ctx = canvas.getContext('2d') as any;
house = {
id: '2',
level: 1,
ownerId: '11',
position: { x: 17, y: 14 },
resourceTimer: { lastCollectionTime: 0, resourceCollectionTime: 0 },
resources: { gold: 0 }
};
});
it(`should return the shape's path`, function() {
const shapePath: Path2D = HouseWarsHouse.draw(house, ctx);
expect(shapePath instanceof Path2D).toBeTruthy();
});
it(`should draw a house on the canvas using the main ctx`, function() {
HouseWarsHouse.draw(house, ctx);
const events = ctx.__getEvents();
expect(events).toMatchSnapshot();
});
it(`should draw a house with given color`, function() {
HouseWarsHouse.draw(house, ctx, { color: 'gray', stroke: 'white'});
const events = ctx.__getEvents();
expect(events).toMatchSnapshot();
});
it(`should draw a house with given color and selected state`, function() {
HouseWarsHouse.draw(house, ctx, { color: 'gray', stroke: 'white', selected: true});
const events = ctx.__getEvents();
expect(events).toMatchSnapshot();
});
it(`should draw a house with default color and selected state`, function() {
HouseWarsHouse.draw(house, ctx, { selected: true});
const events = ctx.__getEvents();
expect(events).toMatchSnapshot();
});
it(`should draw a house with select color and selected state`, function() {
HouseWarsHouse.draw(house, ctx, { selected: true, selectColor: '#456ddd', selectStroke: '#ddd456'});
const events = ctx.__getEvents();
expect(events).toMatchSnapshot();
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment