Skip to content

Commit 8f4ce64

Browse files
Rik Rootsfrederickobrien
authored andcommitted
Fix failing playwright test
1 parent dd1649f commit 8f4ce64

File tree

3 files changed

+23
-7
lines changed

3 files changed

+23
-7
lines changed

dotcom-rendering/playwright/lib/iframe.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,16 @@ const getIframeBody = async (
1010
return iframeBodyLocator;
1111
};
1212

13-
export { getIframeBody };
13+
const getIframePart = async (
14+
page: Page,
15+
iframeSelector: string,
16+
partSelector: string,
17+
): Promise<Locator> => {
18+
const iframePartLocator = page
19+
.frameLocator(iframeSelector)
20+
.locator(partSelector);
21+
await expect(iframePartLocator).toBeAttached({ timeout: 10_000 });
22+
return iframePartLocator;
23+
};
24+
25+
export { getIframeBody, getIframePart };

dotcom-rendering/playwright/tests/article.embeds.e2e.spec.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { expect, test } from '@playwright/test';
22
import { cmpAcceptAll } from '../lib/cmp';
3-
import { getIframeBody } from '../lib/iframe';
3+
import { getIframeBody, getIframePart } from '../lib/iframe';
44
import { waitForIsland } from '../lib/islands';
55
import { loadPage } from '../lib/load-page';
66
import { expectToBeVisible } from '../lib/locators';
@@ -43,9 +43,10 @@ test.describe('Embeds', () => {
4343

4444
await waitForIsland(page, 'InteractiveBlockComponent');
4545
await expect(
46-
await getIframeBody(
46+
await getIframePart(
4747
page,
4848
'[data-testid="interactive-element-LA%20Rams%20dead%20cap%20numbers"] > iframe',
49+
'.title',
4950
),
5051
).toContainText('The Rams’ dead cap numbers for 2020');
5152
});

dotcom-rendering/src/components/InteractiveBlockComponent.importable.tsx

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,6 @@ export const InteractiveBlockComponent = ({
365365
if (url && scriptUrlIsBoot && placeholderLinkRef.current) {
366366
// Prepare for graphic url dynamic updates
367367
const graphicUrl = new URL(url);
368-
const graphicUrlParams = new URLSearchParams(graphicUrl.search);
369368

370369
// Begin creating new iframe element
371370
const iframe = document.createElement('iframe');
@@ -383,19 +382,22 @@ export const InteractiveBlockComponent = ({
383382
if (isRunningInWebEnvironment && !requiresDarkMode) {
384383
if (isDatawrapperGraphic || isUploaderEmbedPath) {
385384
// Add the 'dark=false' search param
386-
graphicUrlParams.set('dark', 'false');
385+
if (graphicUrl.search.length) {
386+
graphicUrl.search += '&dark=false';
387+
} else {
388+
graphicUrl.search += '?dark=false';
389+
}
387390
}
388391
}
389392

390393
// Always serve graphic over https, not http
391394
graphicUrl.protocol = 'https:';
392395

393-
graphicUrl.search = graphicUrlParams.toString();
394-
395396
// Finalise new iframe element
396397
iframe.src = graphicUrl.href;
397398

398399
setupWindowListeners(iframe);
400+
399401
wrapperRef.current?.prepend(iframe);
400402

401403
setLoaded(true);
@@ -420,6 +422,7 @@ export const InteractiveBlockComponent = ({
420422
}
421423
},
422424
);
425+
423426
setLoaded(true);
424427
}
425428
}, [loaded]);

0 commit comments

Comments
 (0)