Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 78 additions & 0 deletions generated.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
```javascript
/**
* @jest-environment jsdom
*/

const fs = require('fs');
const path = require('path');
const $ = require('jquery');

// --- Mocking global dependencies from main.js ---

// Mock the WOW.js library constructor, as it's not relevant to this test.
// The script calls `new WOW().init()`, so we need to mock this chain.
global.WOW = jest.fn(() => ({
init: jest.fn(),
}));

// Mock the owlCarousel jQuery plugin to prevent "is not a function" errors.
// The script calls this on two different elements.
$.fn.owlCarousel = jest.fn();

// --- Test Suite Setup ---

// Read the application script file content.
// This assumes the test file is located in a structure like `tests/main.test.js`
// relative to the `source code/js/main.js` file.
const mainJsPath = path.resolve(__dirname, '../../source code/js/main.js');
const mainJsContent = fs.readFileSync(mainJsPath, 'utf-8');

Comment on lines +27 to +29
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

🧩 Analysis chain

Validate main.js lookup path.

The test reads ../../source code/js/main.js, but the repository appears to keep assets under different directories (commonly source/js or assets/js). Please confirm the actual location so the test doesn't throw ENOENT.

Run this script from the repo root to see where main.js lives:


🏁 Script executed:

#!/bin/bash
set -euo pipefail
fd -H --type f --max-results 20 main.js

Length of output: 22


🏁 Script executed:

#!/bin/bash
set -euo pipefail
test_file=$(fd -H --type f generated.test.js)
echo "Test file: $test_file"
test_dir=$(dirname "$test_file")
echo "Checking resolution from $test_dir:"
target="$test_dir/../../source code/js/main.js"
if [[ -f "$target" ]]; then
  echo "Exists at:" $(realpath "$target")
else
  echo "Not found at $target"
fi

Length of output: 100


Fix main.js lookup path. In generated.test.js the code calls

path.resolve(__dirname, '../../source code/js/main.js')

but main.js lives at source code/js/main.js relative to the repo root. Update to:

path.resolve(__dirname, 'source code/js/main.js')
🤖 Prompt for AI Agents
In generated.test.js around lines 27 to 29, the path.resolve call incorrectly
uses '../../source code/js/main.js' which points outside the repo root; update
the lookup to use 'source code/js/main.js' relative to __dirname so the code
reads path.resolve(__dirname, 'source code/js/main.js') and keep the
fs.readFileSync usage as-is to read that resolved path.

describe('Sticky Navbar Scroll Behavior', () => {

beforeEach(() => {
// Set up a mock DOM for each test, including the target element.
document.body.innerHTML = `
<div id="spinner" class="show"></div>
<nav class="sticky-top" style="position: fixed; top: -100px;"></nav>
<div style="height: 2000px;"></div> <!-- Tall element to simulate a scrollable page -->
`;

// Make jQuery globally available for the script, which expects `(function ($) { ... })(jQuery);`.
window.$ = window.jQuery = $;

// Execute the main.js script in the JSDOM environment by adding it to the DOM.
// This attaches the scroll event listener that we want to test.
const script = document.createElement('script');
script.textContent = mainJsContent;
document.body.appendChild(script);

// Ensure the initial state is correctly set by the script based on the default scroll position.
// We set scroll position to 0 and manually trigger the event.
$(window).scrollTop(0);
$(window).trigger('scroll');
});

afterEach(() => {
// Clean up the DOM and mocks to ensure test isolation.
document.body.innerHTML = '';
jest.clearAllMocks();
});

test('should become visible by adjusting its CSS "top" property when the user scrolls down more than 300 pixels', () => {
const stickyNav = $('.sticky-top');

// ARRANGE: Verify the initial hidden state.
// The script's logic should have set the 'top' property to '-100px' because scrollY is 0.
expect(stickyNav.css('top')).toBe('-100px');

// ACT: Simulate the user scrolling down past the 300px threshold.
// We programmatically set the scroll position...
$(window).scrollTop(301);
// ...and then fire the 'scroll' event that our script is listening for.
$(window).trigger('scroll');

// ASSERT: The 'top' property should now be '0px', making the navbar visible.
expect(stickyNav.css('top')).toBe('0px');
});
});
```
Comment on lines +1 to +78
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

Remove Markdown fences from source file.

The test file is wrapped in Markdown code fences (```javascript```), so the emitted file is not valid JavaScript and fails to parse (Biome flags cascading syntax errors). Drop the fence lines so the file starts directly with the JSDOM pragma.

🧰 Tools
🪛 Biome (2.1.2)

[error] 13-13: Expected a semicolon or an implicit semicolon after a statement, but found none

An explicit or implicit semicolon is expected here...

...Which is required to end this statement

(parse)


[error] 25-25: Expected a semicolon or an implicit semicolon after a statement, but found none

An explicit or implicit semicolon is expected here...

...Which is required to end this statement

(parse)


[error] 26-26: Expected a semicolon or an implicit semicolon after a statement, but found none

An explicit or implicit semicolon is expected here...

...Which is required to end this statement

(parse)


[error] 26-26: Expected a semicolon or an implicit semicolon after a statement, but found none

An explicit or implicit semicolon is expected here...

...Which is required to end this statement

(parse)


[error] 35-35: Expected a semicolon or an implicit semicolon after a statement, but found none

An explicit or implicit semicolon is expected here...

...Which is required to end this statement

(parse)


[error] 35-35: Expected a semicolon or an implicit semicolon after a statement, but found none

An explicit or implicit semicolon is expected here...

...Which is required to end this statement

(parse)


[error] 35-35: expected { but instead found =

Remove =

(parse)


[error] 35-35: expected a semicolon to end the class property, but found none

(parse)


[error] 35-35: Expected an identifier, a string literal, a number literal, a private field name, or a computed name but instead found '>'.

Expected an identifier, a string literal, a number literal, a private field name, or a computed name here.

(parse)


[error] 36-36: expected a semicolon to end the class property, but found none

(parse)


[error] 36-36: expected a semicolon to end the class property, but found none

(parse)


[error] 36-36: Expected an expression but instead found '<'.

Expected an expression here.

(parse)


[error] 36-36: expected a semicolon to end the class property, but found none

(parse)


[error] 36-36: Expected an identifier, a string literal, a number literal, a private field name, or a computed name but instead found '<'.

Expected an identifier, a string literal, a number literal, a private field name, or a computed name here.

(parse)


[error] 37-37: Expected a class parameters but instead found '<'.

Expected a class parameters here.

(parse)


[error] 37-37: Expected a class parameters but instead found '<'.

Expected a class parameters here.

(parse)


[error] 37-37: Expected a class parameters but instead found '<'.

Expected a class parameters here.

(parse)


[error] 38-38: Expected a class parameters but instead found '`'.

Expected a class parameters here.

(parse)


[error] 41-41: expected a semicolon to end the class property, but found none

(parse)


[error] 41-41: Expected an identifier, a string literal, a number literal, a private field name, or a computed name but instead found '.'.

Expected an identifier, a string literal, a number literal, a private field name, or a computed name here.

(parse)


[error] 45-45: expected a semicolon to end the class property, but found none

(parse)


[error] 46-46: expected a semicolon to end the class property, but found none

(parse)


[error] 46-46: Expected an identifier, a string literal, a number literal, a private field name, or a computed name but instead found '.'.

Expected an identifier, a string literal, a number literal, a private field name, or a computed name here.

(parse)


[error] 47-47: expected a semicolon to end the class property, but found none

(parse)


[error] 47-47: Expected an identifier, a string literal, a number literal, a private field name, or a computed name but instead found '.'.

Expected an identifier, a string literal, a number literal, a private field name, or a computed name here.

(parse)


[error] 47-47: expected a semicolon to end the class property, but found none

(parse)


[error] 47-47: Expected an identifier, a string literal, a number literal, a private field name, or a computed name but instead found '.'.

Expected an identifier, a string literal, a number literal, a private field name, or a computed name here.

(parse)


[error] 47-47: Expected a class method body but instead found ';'.

Expected a class method body here.

(parse)


[error] 51-51: Expected a class method body but instead found '.'.

Expected a class method body here.

(parse)


[error] 51-51: Expected a parameter but instead found '0'.

Expected a parameter here.

(parse)


[error] 51-51: Expected a class method body but instead found ';'.

Expected a class method body here.

(parse)


[error] 52-52: Expected a class method body but instead found '.'.

Expected a class method body here.

(parse)


[error] 52-52: Expected a parameter but instead found ''scroll''.

Expected a parameter here.

(parse)


[error] 52-52: Expected a class method body but instead found ';'.

Expected a class method body here.

(parse)


[error] 53-53: Expected a statement but instead found ')'.

Expected a statement here.

(parse)


[error] 76-77: Expected a statement but instead found '})'.

Expected a statement here.

(parse)


[error] 46-46: Duplicate class member name "script"

(lint/suspicious/noDuplicateClassMembers)


[error] 51-51: Duplicate class member name "$"

(lint/suspicious/noDuplicateClassMembers)


[error] 52-52: Duplicate class member name "$"

(lint/suspicious/noDuplicateClassMembers)

🤖 Prompt for AI Agents
In generated.test.js around lines 1 to 78, the file is wrapped in Markdown code
fences (```javascript ... ```), which makes it invalid JS; remove the opening
```javascript line and the closing ``` line so the file begins with the JSDOM
pragma comment and contains only plain JavaScript; ensure there are no leftover
fence characters or blank lines before the pragma.