Files
pwap/tests/run-web-tests.sh
Claude db05f21e52 feat(tests): add comprehensive test infrastructure based on blockchain pallet tests
Created complete testing framework for web and mobile frontends based on 437 test scenarios extracted from 12 blockchain pallet test files.

Test Infrastructure:
- Mock data generators for all 12 pallets (Identity, Perwerde, Rewards, Treasury, etc.)
- Test helper utilities (async, blockchain mocks, validation, custom matchers)
- Example unit tests for web (KYC Application) and mobile (Education Course List)
- Example E2E tests using Cypress (web) and Detox (mobile)
- Executable test runner scripts with colored output
- Comprehensive documentation with all 437 test scenarios

Coverage:
- pallet-identity-kyc: 39 test scenarios
- pallet-perwerde: 30 test scenarios
- pallet-pez-rewards: 44 test scenarios
- pallet-pez-treasury: 58 test scenarios
- pallet-presale: 24 test scenarios
- pallet-referral: 17 test scenarios
- pallet-staking-score: 23 test scenarios
- pallet-tiki: 66 test scenarios
- pallet-token-wrapper: 18 test scenarios
- pallet-trust: 26 test scenarios
- pallet-validator-pool: 27 test scenarios
- pallet-welati: 65 test scenarios

Files created:
- tests/utils/mockDataGenerators.ts (550+ lines)
- tests/utils/testHelpers.ts (400+ lines)
- tests/web/unit/citizenship/KYCApplication.test.tsx
- tests/mobile/unit/education/CourseList.test.tsx
- tests/web/e2e/cypress/citizenship-kyc.cy.ts
- tests/mobile/e2e/detox/education-flow.e2e.ts
- tests/run-web-tests.sh (executable)
- tests/run-mobile-tests.sh (executable)
- tests/README.md (800+ lines of documentation)
2025-11-21 04:46:35 +00:00

142 lines
4.3 KiB
Bash
Executable File

#!/bin/bash
###############################################################################
# Web Frontend Test Runner
# Runs Jest unit tests and Cypress E2E tests for web application
###############################################################################
set -e
# Colors for output
GREEN='\033[0;32m'
BLUE='\033[0;34m'
RED='\033[0;31m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
echo -e "${BLUE}╔════════════════════════════════════════════════════════════╗${NC}"
echo -e "${BLUE}║ PezkuwiChain Web Frontend Test Suite ║${NC}"
echo -e "${BLUE}╚════════════════════════════════════════════════════════════╝${NC}"
echo ""
# Navigate to web directory
cd "$(dirname "$0")/../web"
# Function to run unit tests
run_unit_tests() {
echo -e "${YELLOW}Running Unit Tests (Jest + React Testing Library)...${NC}"
echo ""
npm run test -- \
--testPathPattern="tests/web/unit" \
--coverage \
--verbose
if [ $? -eq 0 ]; then
echo -e "${GREEN}✓ Unit tests passed!${NC}"
else
echo -e "${RED}✗ Unit tests failed!${NC}"
exit 1
fi
}
# Function to run E2E tests
run_e2e_tests() {
echo -e "${YELLOW}Running E2E Tests (Cypress)...${NC}"
echo ""
# Start dev server in background
echo "Starting development server..."
npm run dev > /dev/null 2>&1 &
DEV_SERVER_PID=$!
# Wait for server to be ready
echo "Waiting for server to start..."
sleep 5
# Run Cypress tests
npx cypress run --spec "../tests/web/e2e/cypress/**/*.cy.ts"
CYPRESS_EXIT_CODE=$?
# Kill dev server
kill $DEV_SERVER_PID
if [ $CYPRESS_EXIT_CODE -eq 0 ]; then
echo -e "${GREEN}✓ E2E tests passed!${NC}"
else
echo -e "${RED}✗ E2E tests failed!${NC}"
exit 1
fi
}
# Function to run specific test suite
run_specific_suite() {
echo -e "${YELLOW}Running specific test suite: $1${NC}"
echo ""
case $1 in
citizenship)
npm run test -- --testPathPattern="citizenship"
;;
education)
npm run test -- --testPathPattern="education"
;;
governance)
npm run test -- --testPathPattern="governance"
;;
p2p)
npm run test -- --testPathPattern="p2p"
;;
rewards)
npm run test -- --testPathPattern="rewards"
;;
treasury)
npm run test -- --testPathPattern="treasury"
;;
*)
echo -e "${RED}Unknown test suite: $1${NC}"
echo "Available suites: citizenship, education, governance, p2p, rewards, treasury"
exit 1
;;
esac
}
# Parse command line arguments
if [ $# -eq 0 ]; then
# No arguments: run all tests
echo -e "${BLUE}Running all tests...${NC}"
echo ""
run_unit_tests
echo ""
run_e2e_tests
elif [ "$1" == "unit" ]; then
run_unit_tests
elif [ "$1" == "e2e" ]; then
run_e2e_tests
elif [ "$1" == "suite" ] && [ -n "$2" ]; then
run_specific_suite "$2"
elif [ "$1" == "watch" ]; then
echo -e "${YELLOW}Running tests in watch mode...${NC}"
npm run test -- --watch
elif [ "$1" == "coverage" ]; then
echo -e "${YELLOW}Running tests with coverage report...${NC}"
npm run test -- --coverage --coverageReporters=html
echo ""
echo -e "${GREEN}Coverage report generated at: web/coverage/index.html${NC}"
else
echo -e "${RED}Usage:${NC}"
echo " $0 # Run all tests"
echo " $0 unit # Run only unit tests"
echo " $0 e2e # Run only E2E tests"
echo " $0 suite <name> # Run specific test suite"
echo " $0 watch # Run tests in watch mode"
echo " $0 coverage # Run tests with coverage report"
exit 1
fi
echo ""
echo -e "${GREEN}╔════════════════════════════════════════════════════════════╗${NC}"
echo -e "${GREEN}║ All tests completed successfully! ✓ ║${NC}"
echo -e "${GREEN}╚════════════════════════════════════════════════════════════╝${NC}"