|
| 1 | +const Painter = require("../turtle-painter"); |
| 2 | +global.WRAP = true; |
| 3 | +const mockTurtle = { |
| 4 | + turtles: { |
| 5 | + screenX2turtleX: jest.fn(), |
| 6 | + screenY2turtleY: jest.fn(), |
| 7 | + turtleX2screenX: jest.fn(), |
| 8 | + turtleY2screenY: jest.fn(), |
| 9 | + scale: 1 |
| 10 | + }, |
| 11 | + activity: { refreshCanvas: jest.fn() }, |
| 12 | + container: { x: 0, y: 0, rotation: 0 }, |
| 13 | + ctx: { |
| 14 | + beginPath: jest.fn(), |
| 15 | + clearRect: jest.fn(), |
| 16 | + stroke: jest.fn(), |
| 17 | + closePath: jest.fn(), |
| 18 | + moveTo: jest.fn(), |
| 19 | + lineTo: jest.fn(), |
| 20 | + arc: jest.fn(), |
| 21 | + canvas: { width: 800, height: 600 } |
| 22 | + }, |
| 23 | + penstrokes: { image: null }, |
| 24 | + orientation: 0, |
| 25 | + updateCache: jest.fn(), |
| 26 | + blinking: jest.fn().mockReturnValue(false) |
| 27 | +}; |
| 28 | + |
| 29 | +describe("Painter Class", () => { |
| 30 | + let painter; |
| 31 | + |
| 32 | + beforeEach(() => { |
| 33 | + painter = new Painter(mockTurtle); |
| 34 | + }); |
| 35 | + |
| 36 | + describe("Constructor", () => { |
| 37 | + test("should initialize with default values", () => { |
| 38 | + expect(painter._color).toBe(0); |
| 39 | + expect(painter._stroke).toBe(5); |
| 40 | + expect(painter._penDown).toBe(true); |
| 41 | + }); |
| 42 | + }); |
| 43 | + |
| 44 | + describe("Setters and Getters", () => { |
| 45 | + test("should set and get color", () => { |
| 46 | + painter.color = 10; |
| 47 | + expect(painter.color).toBe(10); |
| 48 | + }); |
| 49 | + |
| 50 | + test("should set and get stroke", () => { |
| 51 | + painter.stroke = 8; |
| 52 | + expect(painter.stroke).toBe(8); |
| 53 | + }); |
| 54 | + }); |
| 55 | + |
| 56 | + describe("Actions", () => { |
| 57 | + test("should move forward", () => { |
| 58 | + painter.doForward(10); |
| 59 | + expect(mockTurtle.activity.refreshCanvas).toHaveBeenCalled(); |
| 60 | + }); |
| 61 | + |
| 62 | + test("should turn right", () => { |
| 63 | + painter.doRight(90); |
| 64 | + expect(mockTurtle.orientation).toBe(90); |
| 65 | + }); |
| 66 | + }); |
| 67 | +}); |
0 commit comments