Skip to content

Commit

Permalink
verification testing initial files
Browse files Browse the repository at this point in the history
  • Loading branch information
tjc234 committed Dec 4, 2023
1 parent 2a6b98c commit 27b8ded
Show file tree
Hide file tree
Showing 2 changed files with 93 additions and 54 deletions.
84 changes: 30 additions & 54 deletions .github/workflows/automated_testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,74 +2,50 @@ name: Python and JS Test Workflow

on: [push, pull_request]

defaults:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: 3.9

- name: Install Python dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
- name: Set up headless Chrome
run: |
sudo apt-get update
sudo apt-get install -y libgconf-2-4
wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
sudo dpkg -i google-chrome-stable_current_amd64.deb
rm google-chrome-stable_current_amd64.deb
jobs:
test-server:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: 3.9

- name: Install Python dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
- name: Set up headless Chrome
run: |
sudo apt-get update
sudo apt-get install -y libgconf-2-4
wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
sudo dpkg -i google-chrome-stable_current_amd64.deb
rm google-chrome-stable_current_amd64.deb
- name: Install Selenium
run: python -m pip install selenium

- name: Run Python tests with pytest
run: |
python -m pip install selenium
pytest testing/test_server.py
run: pytest testing/test_server.py

acceptance-test:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: 3.9

- name: Install Python dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
- name: Set up headless Chrome
run: |
sudo apt-get update
sudo apt-get install -y libgconf-2-4
wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
sudo dpkg -i google-chrome-stable_current_amd64.deb
rm google-chrome-stable_current_amd64.deb
- name: Install Selenium
run: python -m pip install selenium

- name: Run acceptance tests with pytest
run: |
python -m pip install selenium
pytest testing/acceptance_test.py
run: pytest testing/acceptance_test.py

test-javascript:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Set up Node.js
uses: actions/setup-node@v3
with:
Expand Down
63 changes: 63 additions & 0 deletions testing/__tests__/board.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
// board.test.js

const {
createBoard,
renderBoard,
makeListeners,
isValidMove,
movePiece,
getRowAndCol,
botThinkHelper,
getPositionScore,
botMovePieceInCalculation,
getPiecePositions,
getPossibleMoves,
availableSpot,
canJump,
isOppositeColor,
} = require('../src/gamboard_dev/board');

describe('Checkers Board', () => {
// Mock data for testing
const mockBoard = [
['empty', 'black', 'empty', 'black', 'empty', 'black', 'empty', 'black'],
['black', 'empty', 'black', 'empty', 'black', 'empty', 'black', 'empty'],
['empty', 'black', 'empty', 'black', 'empty', 'black', 'empty', 'black'],
['empty', 'empty', 'empty', 'empty', 'empty', 'empty', 'empty', 'empty'],
['empty', 'empty', 'empty', 'empty', 'empty', 'empty', 'empty', 'empty'],
['red', 'empty', 'red', 'empty', 'red', 'empty', 'red', 'empty'],
['empty', 'red', 'empty', 'red', 'empty', 'red', 'empty', 'red'],
['red', 'empty', 'red', 'empty', 'red', 'empty', 'red', 'empty']
];


beforeEach(() => {
// Set up a fresh board before each test
document.body.innerHTML = '<div id="gameboard"></div>';
createBoard();
});

test('Board creation', () => {
// Verify that the board is created correctly
const gameboard = document.getElementById('gameboard');
expect(gameboard).toBeTruthy();
});

test('Piece movement', () => {
// Mock a drag-and-drop event
const dragStartEvent = new Event('dragstart');
const dragEndEvent = new Event('drop');
const square1 = document.querySelector('.square[square-id="0"]');
const square2 = document.querySelector('.square[square-id="9"]');
square1.dispatchEvent(dragStartEvent);
square2.dispatchEvent(dragEndEvent);

// Validate that the piece has moved
const pieceInSquare1 = document.querySelector('.square[square-id="0"] img');
const pieceInSquare2 = document.querySelector('.square[square-id="9"] img');
expect(pieceInSquare1).toBeFalsy();
expect(pieceInSquare2).toBeTruthy();
});

});

0 comments on commit 27b8ded

Please sign in to comment.