From 50d37a444e732cb27e38311e42e7f79c4f1c7754 Mon Sep 17 00:00:00 2001
From: "ayoub.bouhmadi@usmba.ac.ma"
Date: Mon, 26 Oct 2026 16:37:13 +0100
Subject: [PATCH 01/11] add game rules to index.html
---
index.html | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/index.html b/index.html
index bdaf182..dd68134 100644
--- a/index.html
+++ b/index.html
@@ -69,7 +69,11 @@ 2048
-
+
+ How to play:
+ Use your arrow keys to move the tiles. When two tiles with
+ the same number touch, they merge into one! first commit
+
From ee9f9e39b5c4b0b7f410f9c0151f4536990e905f Mon Sep 17 00:00:00 2001
From: "ayoub.bouhmadi@usmba.ac.ma"
Date: Mon, 26 Oct 2026 18:04:34 +0100
Subject: [PATCH 02/11] fix tests
---
__tests__/keyboard_input_manager.test.ts | 117 ++++++++++++++++++++++-
1 file changed, 114 insertions(+), 3 deletions(-)
diff --git a/__tests__/keyboard_input_manager.test.ts b/__tests__/keyboard_input_manager.test.ts
index 15a53d2..68a066a 100644
--- a/__tests__/keyboard_input_manager.test.ts
+++ b/__tests__/keyboard_input_manager.test.ts
@@ -1,13 +1,124 @@
import { jest } from '@jest/globals'
+const { KeyboardInputManager } = await import(
+ '../src/keyboard_input_manager.js'
+)
+
describe('KeyboardInputManager', () => {
afterEach(() => {
jest.resetAllMocks()
})
- describe('todo', () => {
- it('Create some unit tests', async () => {
- expect(true).toBe(true)
+ describe('on()', () => {
+ it('Registers an event listener', async () => {
+ KeyboardInputManager.events['test'] = []
+
+ KeyboardInputManager.on('test', () => {})
+
+ expect(KeyboardInputManager.events['test'].length).toBe(1)
+ })
+
+ it('Creates an listener array if it does not exist', async () => {
+ KeyboardInputManager.events = {}
+
+ KeyboardInputManager.on('test', () => {})
+
+ expect(KeyboardInputManager.events['test'].length).toBe(1)
+ })
+ })
+
+ describe('emit()', () => {
+ let callback1: any
+ let callback2: any
+
+ beforeEach(() => {
+ callback1 = jest.fn()
+ callback2 = jest.fn()
+ })
+
+ it('Emits an event to all listeners', async () => {
+ KeyboardInputManager.events['test'] = [callback1, callback2]
+ KeyboardInputManager.emit('test')
+
+ expect(callback1).toHaveBeenCalledTimes(1)
+ expect(callback2).toHaveBeenCalledTimes(1)
+ })
+
+ it('Passes data to listeners', async () => {
+ KeyboardInputManager.events['test'] = [callback1, callback2]
+ KeyboardInputManager.emit('test', 'data')
+
+ expect(callback1).toHaveBeenCalledWith('data')
+ expect(callback2).toHaveBeenCalledWith('data')
+ })
+
+ it('Does nothing if the event does not exist', async () => {
+ KeyboardInputManager.events = {}
+ KeyboardInputManager.emit('test')
+
+ expect(callback1).not.toHaveBeenCalled()
+ expect(callback2).not.toHaveBeenCalled()
+ })
+ })
+
+ describe('restart()', () => {
+ it('Emits a restart event', async () => {
+ const preventDefault = jest.fn()
+ const event = {
+ preventDefault
+ }
+ const emit = jest
+ .spyOn(KeyboardInputManager, 'emit')
+ .mockImplementation(() => {})
+
+ KeyboardInputManager.restart(event as unknown as Event)
+
+ expect(emit).toHaveBeenCalledTimes(1)
+ expect(preventDefault).toHaveBeenCalledTimes(1)
+ })
+ })
+
+ describe('constructor', () => {
+ it('Sets events and listens', async () => {
+ // Lab 3: Git Bisect
+ const listen = jest
+ .spyOn(KeyboardInputManager, 'listen')
+ .mockImplementation(() => {})
+
+ new KeyboardInputManager()
+
+ expect(KeyboardInputManager.events).toMatchObject({})
+ expect(listen).toHaveBeenCalledTimes(1)
+ })
+ })
+
+ describe('keepPlaying()', () => {
+ it('Emits a keepPlaying event', async () => {
+ const preventDefault = jest.fn()
+ const event = {
+ preventDefault
+ }
+ const emit = jest
+ .spyOn(KeyboardInputManager, 'emit')
+ .mockImplementation(() => {})
+
+ KeyboardInputManager.keepPlaying(event as unknown as Event)
+
+ expect(emit).toHaveBeenCalledTimes(1)
+ expect(preventDefault).toHaveBeenCalledTimes(1)
+ })
+ })
+
+ describe('bindButtonPress()', () => {
+ it('Binds a button press', async () => {
+ const addEventListener = jest.fn()
+ document.querySelector = jest.fn().mockReturnValue({
+ addEventListener
+ })
+
+ KeyboardInputManager.bindButtonPress('.test', () => {})
+
+ expect(addEventListener).toHaveBeenCalledTimes(1)
})
})
})
From d12619c142c2adb650bf34c7739a1b1557fd0785 Mon Sep 17 00:00:00 2001
From: "ayoub.bouhmadi@usmba.ac.ma"
Date: Mon, 26 Oct 2026 18:43:14 +0100
Subject: [PATCH 03/11] test git diff
---
index.html | 2 --
1 file changed, 2 deletions(-)
diff --git a/index.html b/index.html
index dd68134..8233a2b 100644
--- a/index.html
+++ b/index.html
@@ -75,8 +75,6 @@ 2048
the same number touch, they merge into one! first commit
-
-