diff --git a/test/blocks/modals/mocks/body.html b/test/blocks/modals/mocks/body.html
index cc0d9f3aab..1ea4239f0b 100644
--- a/test/blocks/modals/mocks/body.html
+++ b/test/blocks/modals/mocks/body.html
@@ -21,3 +21,7 @@
FaaS
+
+FaaS
diff --git a/test/blocks/modals/mocks/federal/geo.plain.html b/test/blocks/modals/mocks/federal/geo.plain.html
new file mode 100644
index 0000000000..2ba4c5be2a
--- /dev/null
+++ b/test/blocks/modals/mocks/federal/geo.plain.html
@@ -0,0 +1,5 @@
+
+
Federated modal
+
+
+
diff --git a/test/blocks/modals/modals.test.js b/test/blocks/modals/modals.test.js
index 40105077d7..d4cb3abaa1 100644
--- a/test/blocks/modals/modals.test.js
+++ b/test/blocks/modals/modals.test.js
@@ -3,8 +3,10 @@ import { readFile, sendKeys } from '@web/test-runner-commands';
import { expect } from '@esm-bundle/chai';
import sinon from 'sinon';
import { delay, waitForElement, waitForRemoval } from '../../helpers/waitfor.js';
+import { mockFetch } from '../../helpers/generalHelpers.js';
document.body.innerHTML = await readFile({ path: './mocks/body.html' });
+
const {
default: init,
getModal,
@@ -14,6 +16,8 @@ const {
} = await import('../../../libs/blocks/modal/modal.js');
const satellite = { track: sinon.spy() };
+const ogFetch = window.fetch;
+
describe('Modals', () => {
beforeEach(() => {
window._satellite = satellite;
@@ -22,6 +26,7 @@ describe('Modals', () => {
afterEach(() => {
sinon.restore();
+ window.fetch = ogFetch;
});
it('Doesnt load modals on page load with no hash', async () => {
@@ -265,4 +270,14 @@ describe('sendAnalytics', () => {
sendAnalytics({});
expect(window._satellite.track.called).to.be.true;
});
+
+ it('Loads a federated modal on load with hash and closes when removed from hash', async () => {
+ window.fetch = mockFetch({ payload: { data: '' } });
+ window.location.hash = '#geo';
+ await waitForElement('#geo');
+ expect(document.getElementById('geo')).to.exist;
+ window.location.hash = '';
+ await waitForRemoval('#geo');
+ expect(document.getElementById('geo')).to.be.null;
+ });
});