This is a plain text paragraph.
' - }, - { - type: 'paragraph', - data: 'Another paragraph with code in it.
Introduction paragraph.
' - }, - { - type: 'interactiveEditor', - data: [ - { - contents: 'console.log("Toggle test");', - ext: 'js', - name: 'script-1', - contentsHtml: - 'console.log("Toggle test");'
- },
- {
- contents: '<div>HTML content</div>'
- }
- ]
- },
- {
- type: 'paragraph',
- data: 'Final paragraph.
' - } - ]; - - await route.fulfill({ - contentType: 'application/json', - body: JSON.stringify(pageData) - }); - } - ); - - await page.goto(challengePath); + await page.goto(html.challengePath); await expect( - page.getByRole('heading', { name: challengeTitle }) + page.getByRole('heading', { name: html.challengeTitle }) ).toBeVisible(); - await expect(page.getByText('Introduction paragraph.')).toBeVisible(); - await expect(page.getByText('Final paragraph.')).toBeVisible(); + await expect(page.getByText(html.paragraphOneText)).toBeVisible(); // Initially, interactive editor should be hidden, static code view should be visible await expect(page.getByTestId('sp-interactive-editor')).not.toBeVisible(); await expect( - page - .locator('pre code') - .filter({ hasText: 'console.log("Toggle test");' }) + page.locator('pre code').filter({ hasText: html.codeSnippet }) ).toHaveCount(1); - await expect( - page.locator('pre code').filter({ hasText: 'This challenge has only JavaScript code.
' - }, - { - type: 'interactiveEditor', - data: [ - { - contents: 'console.log("Hello from JS-only editor");', - ext: 'js', - name: 'script-1', - contentsHtml: - 'console.log("Hello from JS-only editor");'
- }
- ]
- }
- ];
+ // Initially, the interactive editor should be hidden
+ await expect(page.getByTestId('sp-interactive-editor')).not.toBeVisible();
- await route.fulfill({
- contentType: 'application/json',
- body: JSON.stringify(pageData)
- });
- }
- );
-
- await page.goto(challengePath);
+ await page
+ .getByRole('button', {
+ name: /interactive editor/i
+ })
+ .click();
await expect(
- page.getByRole('heading', { name: challengeTitle })
- ).toBeVisible();
- await expect(
- page.getByText('This challenge has only JavaScript code.')
+ page.getByTestId('sp-interactive-editor').first()
).toBeVisible();
+ // Reload the page and check that the interactive editor is still shown
+ await page.reload();
await expect(
- page
- .locator('pre code')
- .filter({ hasText: 'console.log("Hello from JS-only editor");' })
+ page.getByTestId('sp-interactive-editor').first()
).toBeVisible();
+ });
+
+ test('should hide the preview panel in JS-only interactive editors and just show the console', async ({
+ page
+ }) => {
+ await page.goto(js.challengePath);
// Click the toggle button to show interactive editor
await page
@@ -238,8 +107,15 @@ test.describe('Interactive Editor', () => {
})
.click();
- // Check that the console is visible and the console wrapper is hidden
- await expect(page.locator('.sp-console')).toBeVisible();
- await expect(page.locator('.sp-console-wrapper')).not.toBeVisible();
+ // Check that the consoles are visible
+ const consoles = page.getByTestId('sp-console');
+ await expect(consoles).toHaveCount(4);
+ for (const console of await consoles.all()) {
+ await expect(console).toBeVisible();
+ }
+
+ // Check that the preview is not visible
+ const previews = page.getByTestId('sp-preview');
+ await expect(previews).not.toBeVisible();
});
});
diff --git a/tools/challenge-parser/parser/plugins/add-interactive-elements.js b/tools/challenge-parser/parser/plugins/add-interactive-elements.js
index 21ab46d4bbb..60a0e022f85 100644
--- a/tools/challenge-parser/parser/plugins/add-interactive-elements.js
+++ b/tools/challenge-parser/parser/plugins/add-interactive-elements.js
@@ -27,13 +27,13 @@ function plugin() {
) {
return {
type: 'interactiveEditor',
- data: getFiles(node.children)
+ files: getFiles(node.children)
};
} else {
const paragraph = mdastToHTML([node]);
return {
type: 'paragraph',
- data: paragraph
+ contents: paragraph
};
}
}) ?? [];
diff --git a/tools/challenge-parser/parser/plugins/add-interactive-elements.test.js b/tools/challenge-parser/parser/plugins/add-interactive-elements.test.js
index 1bdc7167a1d..3194318ea4a 100644
--- a/tools/challenge-parser/parser/plugins/add-interactive-elements.test.js
+++ b/tools/challenge-parser/parser/plugins/add-interactive-elements.test.js
@@ -21,6 +21,23 @@ describe('add-interactive-editor plugin', () => {
expect(Array.isArray(file.data.nodules)).toBe(true);
});
+ it('converts paragraphs to paragraph nodes', async () => {
+ const mockAST = await parseFixture('with-interactive.md');
+ plugin(mockAST, file);
+
+ expect(file.data.nodules.slice(0, 2)).toEqual([
+ {
+ type: 'paragraph',
+ contents: 'Normal markdown
' + }, + { + type: 'paragraph', + contents: + '<div>This is NOT an interactive element</div>\n'
+ }
+ ]);
+ });
+
it('populates `nodules` with editor objects', async () => {
const mockAST = await parseFixture('with-interactive.md');
plugin(mockAST, file);
@@ -31,7 +48,7 @@ describe('add-interactive-editor plugin', () => {
expect(editorElements).toEqual([
{
type: 'interactiveEditor',
- data: [
+ files: [
{
contents: "console.log('Interactive JS');",
ext: 'js',
@@ -43,7 +60,7 @@ describe('add-interactive-editor plugin', () => {
},
{
type: 'interactiveEditor',
- data: [
+ files: [
{
contents: '