Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
cba7375
Install playwright to scrollspy
sarah-richards-stormid Mar 12, 2025
b62edb6
temp commit
sarah-richards-stormid Mar 12, 2025
1cb7fee
Merge branch 'bug/scrollspy-example' into feature/310-scrollspy-playw…
sarah-richards-stormid Mar 12, 2025
c5899d5
remove debugging code
sarah-richards-stormid Mar 12, 2025
0718d03
WIP
sarah-richards-stormid Mar 12, 2025
7cf61b9
remove debug
sarah-richards-stormid Mar 12, 2025
9f176eb
introduce scroll direction
sarah-richards-stormid Mar 17, 2025
84d1935
WIP
sarah-richards-stormid Mar 17, 2025
5479781
Neaten up code
sarah-richards-stormid Mar 17, 2025
1f10b90
Updating tests
sarah-richards-stormid Mar 17, 2025
4c44985
First on page load
sarah-richards-stormid Mar 17, 2025
7791e15
Test updates
sarah-richards-stormid Mar 17, 2025
3987200
New version with document top being trigger
sarah-richards-stormid Mar 18, 2025
cb447ca
Fix tests
sarah-richards-stormid Mar 18, 2025
9627a12
Example update
sarah-richards-stormid Mar 18, 2025
d410608
rename
sarah-richards-stormid Mar 18, 2025
d876bf0
Adding commentary
sarah-richards-stormid Mar 18, 2025
01a9cbc
Convert to event listener and throttle
sarah-richards-stormid Mar 19, 2025
5569ac1
Merge branch 'bug/racing-observers' into feature/310-scrollspy-playwr…
sarah-richards-stormid Mar 19, 2025
ff6a8ba
Adding playwright tests
sarah-richards-stormid Mar 19, 2025
e3055de
Adding click test
sarah-richards-stormid Mar 19, 2025
bb8a9f6
Change IP address to localhost for cookie based tests
sarah-richards-stormid Mar 26, 2025
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
4 changes: 2 additions & 2 deletions packages/boilerplate/playwright.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ module.exports = defineConfig({
...baseConfig,
use: {
...baseConfig.use,
baseURL: `http://127.0.0.1:${server.devServer.port}/`,
baseURL: `http://localhost:${server.devServer.port}/`,
},
webServer: {
...baseConfig.webServer,
url: `http://127.0.0.1:${server.devServer.port}/`,
url: `http://localhost:${server.devServer.port}/`,
},
});
4 changes: 2 additions & 2 deletions packages/outliner/playwright.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ module.exports = defineConfig({
...baseConfig,
use: {
...baseConfig.use,
baseURL: `http://127.0.0.1:${server.devServer.port}/`,
baseURL: `http://localhost:${server.devServer.port}/`,
},
webServer: {
...baseConfig.webServer,
url: `http://127.0.0.1:${server.devServer.port}/`,
url: `http://localhost:${server.devServer.port}/`,
},
});
Original file line number Diff line number Diff line change
@@ -1,114 +1,114 @@
import scrollSpy from '../src';
import { getSelection } from '../src/lib/utils';
let basic, withCallback;
const init = () => {
window.IntersectionObserver = jest.fn(function(cb) {
this.observe = () => {};
this.entries = [{ isIntersecting: true }];
});
// Set up our document body
document.body.innerHTML = `<header>
<nav>
<a class="js-scroll-spy" href="#section1">Section 1</a>
<a class="js-scroll-spy" href="#section2">Section 2</a>
<a class="js-scroll-spy" href="#section3">Section 3</a>
<a class="js-scroll-spy" href="no-hash">No hash</a>
<a class="js-scroll-spy-two" href="#section4">Section 3</a>
</nav>
</header>
<div class="container">
<h1>Scroll Spy</h1>
<h2>Example</h2>
<p>Scroll down to see the menu to highlight the current section and to see example code.</p>
<section id="section1">
Section 1
</section>
<section id="section2" style="height:1500px">
Section 2
</section>
<section id="section3" style="height:500px">
Section 3
</section>
<section id="section4" style="height:500px">
Section 4
</section></div>`;
basic = scrollSpy('.js-scroll-spy');
withCallback = scrollSpy('.js-scroll-spy-two', {
callback(){
// this.node.classList.toggle('callback-test');
}
});
};
describe(`Scroll Spy > Initialisation`, () => {
beforeAll(init);
it('should return undefined if no nodes match the init selector', async () => {
expect(scrollSpy('.not-found')).toEqual(undefined);
});
it('should return an object with the expected properties', () => {
expect(basic).not.toBeNull();
expect(basic.getState().spies).not.toBeNull();
expect(basic.getState().settings).not.toBeNull();
expect(basic.getState()).not.toBeNull();
});
it('should initialisation with different settings if different options are passed', () => {
expect(basic.getState().settings.callback).not.toEqual(withCallback.getState().settings.callback);
});
});
describe('Scroll spy > Initialisation > Get Selection', () => {
const setupDOM = () => {
// Set up our document body
document.body.innerHTML = `<header>
<nav>
<a class="js-scroll-spy" href="#section1">Section 1</a>
</nav>
</header>
<div class="container">
<h1>Scroll Spy</h1>
<h2>Example</h2>
<p>Scroll down to see the menu to highlight the current section and to see example code.</p>
<section id="section1">
Section 1
</section>`;
}
beforeAll(setupDOM);
it('should return an array when passed a DOM element', async () => {
const scroll = document.querySelector('.js-scroll-spy');
const els = getSelection(scroll);
expect(els instanceof Array).toBe(true);
expect(els.length).toEqual(1);
});
it('should return an array when passed a NodeList element', async () => {
const scroll = document.querySelectorAll('.js-scroll-spy');
const els = getSelection(scroll);
expect(els instanceof Array).toBe(true);
expect(els.length).toEqual(1);
});
it('should return an array when passed an array of DOM elements', async () => {
const scroll = document.querySelector('.js-scroll-spy');
const els = getSelection([scroll]);
expect(els instanceof Array).toBe(true);
expect(els.length).toEqual(1);
});
it('should return an array when passed a string', async () => {
const els = getSelection('.js-scroll-spy');
expect(els instanceof Array).toBe(true);
expect(els.length).toEqual(1);
});
import scrollSpy from '../../src';
import { getSelection } from '../../src/lib/utils';

let basic, withCallback;
const init = () => {
window.IntersectionObserver = jest.fn(function(cb) {
this.observe = () => {};
this.entries = [{ isIntersecting: true }];
});

// Set up our document body
document.body.innerHTML = `<header>
<nav>
<a class="js-scroll-spy" href="#section1">Section 1</a>
<a class="js-scroll-spy" href="#section2">Section 2</a>
<a class="js-scroll-spy" href="#section3">Section 3</a>
<a class="js-scroll-spy" href="no-hash">No hash</a>
<a class="js-scroll-spy-two" href="#section4">Section 3</a>
</nav>
</header>
<div class="container">
<h1>Scroll Spy</h1>
<h2>Example</h2>
<p>Scroll down to see the menu to highlight the current section and to see example code.</p>
<section id="section1">
Section 1
</section>
<section id="section2" style="height:1500px">
Section 2
</section>
<section id="section3" style="height:500px">
Section 3
</section>
<section id="section4" style="height:500px">
Section 4
</section>`;

basic = scrollSpy('.js-scroll-spy');
withCallback = scrollSpy('.js-scroll-spy-two', {
callback(){
// this.node.classList.toggle('callback-test');
}
});
};

describe(`Scroll Spy > Initialisation`, () => {

beforeAll(init);

it('should return undefined if no nodes match the init selector', async () => {
expect(scrollSpy('.not-found')).toEqual(undefined);
});

it('should return an object with the expected properties', () => {
expect(basic).not.toBeNull();
expect(basic.getState().spies).not.toBeNull();
expect(basic.getState().settings).not.toBeNull();
expect(basic.getState()).not.toBeNull();
});

it('should initialisation with different settings if different options are passed', () => {
expect(basic.getState().settings.callback).not.toEqual(withCallback.getState().settings.callback);
});

});

describe('Scroll spy > Initialisation > Get Selection', () => {

const setupDOM = () => {
// Set up our document body
document.body.innerHTML = `<header>
<nav>
<a class="js-scroll-spy" href="#section1">Section 1</a>
</nav>
</header>
<div class="container">
<h1>Scroll Spy</h1>
<h2>Example</h2>
<p>Scroll down to see the menu to highlight the current section and to see example code.</p>
<section id="section1">
Section 1
</section>`;
}

beforeAll(setupDOM);

it('should return an array when passed a DOM element', async () => {
const scroll = document.querySelector('.js-scroll-spy');
const els = getSelection(scroll);
expect(els instanceof Array).toBe(true);
expect(els.length).toEqual(1);
});

it('should return an array when passed a NodeList element', async () => {
const scroll = document.querySelectorAll('.js-scroll-spy');
const els = getSelection(scroll);
expect(els instanceof Array).toBe(true);
expect(els.length).toEqual(1);
});

it('should return an array when passed an array of DOM elements', async () => {
const scroll = document.querySelector('.js-scroll-spy');
const els = getSelection([scroll]);
expect(els instanceof Array).toBe(true);
expect(els.length).toEqual(1);
});

it('should return an array when passed a string', async () => {
const els = getSelection('.js-scroll-spy');
expect(els instanceof Array).toBe(true);
expect(els.length).toEqual(1);
});

});
Loading