< Summary - Frontend Coverage Report (Windows)

Information
Class: src\components\MaintenanceForm.js
Assembly: Default
File(s): src\components\MaintenanceForm.js
Line coverage
100%
Covered lines: 80
Uncovered lines: 0
Coverable lines: 80
Total lines: 80
Line coverage: 100%
Branch coverage
100%
Covered branches: 4
Total branches: 4
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

File(s)

src\components\MaintenanceForm.js

#LineLine coverage
 11import React, { useState, useRef } from 'react';
 12import { useMaintenanceDispatch } from '../context/MaintenanceContext.js';
 13
 14export function MaintenanceForm() {
 195    const [name, setName] = useState('');
 196    const [status, setStatus] = useState('Operational');
 197
 198    // Point 3: useRef - DOM focus
 199    const inputRef = useRef(null);
 1910
 1911    const dispatch = useMaintenanceDispatch();
 1912
 1913    const handleSubmit = (e) => {
 214        e.preventDefault();
 215        if (!name) {
 116            // Point 3: Direct DOM manipulation for UX
 117            inputRef.current.focus();
 118            return;
 119        }
 120
 121        dispatch({
 122            type: 'ADD_MACHINE',
 123            payload: { id: Date.now(), name, status }
 124        });
 125
 126        setName('');
 127        // Auto focus back to input for better workflow
 128        inputRef.current.focus();
 229    };
 1930
 1931    return (
 1932        <div style={{ backgroundColor: '#fff', padding: '20px', borderRadius: '8px', boxShadow: '0 2px 4px rgba(0,0,0,0.
 1933            <h3 style={{ marginTop: 0 }}>Equipment Onboarding</h3>
 1934            <form onSubmit={handleSubmit} style={{ display: 'flex', flexDirection: 'column', gap: '15px' }}>
 1935                <div>
 1936                    <label style={{ display: 'block', marginBottom: '5px', fontSize: '0.9em' }}>Machine Designation</lab
 1937                    <input
 1938                        ref={inputRef} // Point 3: Hooking the DOM
 1939                        type="text"
 1940                        placeholder="e.g. Laser Cutter X-1"
 1941                        value={name}
 1942                        onChange={(e) => setName(e.target.value)}
 1943                        style={{
 1944                            width: '100%',
 1945                            padding: '10px',
 1946                            borderRadius: '4px',
 1947                            border: '1px solid #ddd',
 1948                            boxSizing: 'border-box'
 1949                        }}
 1950                    />
 1951                </div>
 1952
 1953                <div style={{ display: 'grid', gridTemplateColumns: '1fr 1fr', gap: '10px' }}>
 1954                    <div>
 1955                        <label style={{ display: 'block', marginBottom: '5px', fontSize: '0.9em' }}>Initial Status</labe
 1956                        <select
 1957                            value={status}
 1958                            onChange={(e) => setStatus(e.target.value)}
 1959                            style={{ width: '100%', padding: '10px', borderRadius: '4px', border: '1px solid #ddd' }}
 1960                        >
 1961                            <option value="Operational">Operational</option>
 1962                            <option value="Warning">Warning</option>
 1963                            <option value="Maintenance">Maintenance</option>
 1964                        </select>
 1965                    </div>
 1966                    <button type="submit" style={{
 1967                        alignSelf: 'end',
 1968                        padding: '10px',
 1969                        backgroundColor: '#27ae60',
 1970                        color: 'white',
 1971                        border: 'none',
 1972                        borderRadius: '4px',
 1973                        cursor: 'pointer',
 1974                        fontWeight: 'bold'
 1975                    }}>Register Asset</button>
 1976                </div>
 1977            </form>
 1978        </div>
 1979    );
 1980}