summaryrefslogtreecommitdiff
path: root/scripts/test.sh
blob: a66915ea0e7967c8119ad6fc0a89916417125355 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#!/run/current-system/sw/bin/bash

# Test script for Nixtaml single-page website
# Checks file references and basic HTML structure

echo "=== Nixtaml Website Integration Test ==="

# Base directory
BASE_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
INDEX_FILE="$BASE_DIR/index.html"

# Check if index.html exists
if [ ! -f "$INDEX_FILE" ]; then
    echo "ERROR: index.html not found at $INDEX_FILE"
    exit 1
fi

echo "Checking file references in index.html..."

# Extract src attributes from script tags
SCRIPT_FILES=$(grep -oP 'src="\K[^"]+' "$INDEX_FILE")
# Extract href from link tags, excluding anchors
LINK_FILES=$(grep -oP 'href="\K[^"#][^"]*' "$INDEX_FILE")

# Combine and deduplicate
ALL_FILES=$(echo -e "$SCRIPT_FILES\n$LINK_FILES" | sort | uniq)

MISSING_FILES=()
for file in $ALL_FILES; do
    # Skip external URLs (starting with http)
    if [[ $file == http* ]]; then
        continue
    fi

    # Check if file exists relative to BASE_DIR
    if [ ! -f "$BASE_DIR/$file" ]; then
        MISSING_FILES+=("$file")
    fi
done

# Report missing files
if [ ${#MISSING_FILES[@]} -gt 0 ]; then
    echo "ERROR: Missing referenced files:"
    for file in "${MISSING_FILES[@]}"; do
        echo "  - $file"
    done
else
    echo "✓ All referenced files exist"
fi

# Basic HTML structure validation
echo "Validating basic HTML structure..."

# Check for required elements
if ! grep -q "<!DOCTYPE html>" "$INDEX_FILE"; then
    echo "WARNING: Missing DOCTYPE declaration"
fi

if ! grep -q "<html" "$INDEX_FILE"; then
    echo "ERROR: Missing <html> tag"
fi

if ! grep -q "</html>" "$INDEX_FILE"; then
    echo "ERROR: Missing </html> closing tag"
fi

if ! grep -q "<head>" "$INDEX_FILE"; then
    echo "ERROR: Missing <head> tag"
fi

if ! grep -q "<body>" "$INDEX_FILE"; then
    echo "ERROR: Missing <body> tag"
fi

# Check for balanced tags (basic check)
OPEN_TAGS=$(grep -o '<[^/][^>]*>' "$INDEX_FILE" | wc -l)
CLOSE_TAGS=$(grep -o '</[^>]*>' "$INDEX_FILE" | wc -l)

if [ "$OPEN_TAGS" -ne "$CLOSE_TAGS" ]; then
    echo "WARNING: Potential unbalanced tags (open: $OPEN_TAGS, close: $CLOSE_TAGS)"
else
    echo "✓ Basic tag balance looks good"
fi

# Check for required sections
REQUIRED_SECTIONS=("home" "install" "cookbook" "docs" "community")
for section in "${REQUIRED_SECTIONS[@]}"; do
    if ! grep -q "id=\"$section\"" "$INDEX_FILE"; then
        echo "ERROR: Missing section with id=\"$section\""
    fi
done

echo "✓ Section IDs present"

# Check for WebGL canvas insertion point
if ! grep -q "webgl-bg.js" "$INDEX_FILE"; then
    echo "WARNING: webgl-bg.js not referenced - WebGL background may not load"
fi

if ! grep -q "parallax.js" "$INDEX_FILE"; then
    echo "WARNING: parallax.js not referenced - Parallax effects may not work"
fi

echo "=== Test Complete ==="

if [ ${#MISSING_FILES[@]} -gt 0 ]; then
    echo "FAIL: Issues found"
    exit 1
else
    echo "PASS: All checks passed"
fi