Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce VM feature "enableComponentSrcDataKey" as a config option #38

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
2a91549
Add hot reload
bb-face Jun 20, 2024
b76650b
Fix enableHotReload test
bb-face Jun 20, 2024
30c9c1b
Fix tests
bb-face Jun 20, 2024
63cda36
Fix tests
bb-face Jun 20, 2024
4eff901
Refactor
bb-face Jun 22, 2024
68b09a8
Revert style changes
bb-face Jun 22, 2024
d1a2839
Fix socket address
bb-face Jun 24, 2024
bcd6727
Fix ws address
bb-face Jun 24, 2024
8136a21
update docs
elliotBraem Jun 27, 2024
f098c73
adds tests
elliotBraem Jun 27, 2024
0f99176
adds component
elliotBraem Jun 27, 2024
007f6f5
Merge branch 'main' into add-hot-reload
elliotBraem Jun 28, 2024
f0371ee
WIP: working test on port 3001
bb-face Jul 4, 2024
d2ba5fa
Fix test, not time dependend now
bb-face Jul 7, 2024
356578e
Move hotReload to config
bb-face Jul 9, 2024
81c8561
Single param for hotReload
bb-face Jul 9, 2024
caa55d0
adds config object
elliotBraem Jul 9, 2024
e149502
Merge branch 'main' of https://github.com/nearbuilders/near-bos-webco…
elliotBraem Jul 9, 2024
4eb2a27
clean up
elliotBraem Jul 9, 2024
84a6ad1
fix readme
elliotBraem Jul 9, 2024
425b02c
formatting
elliotBraem Jul 9, 2024
1790cc0
Merge branch 'main' of https://github.com/nearbuilders/near-bos-webco…
elliotBraem Jul 9, 2024
062c5d9
formatting
elliotBraem Jul 9, 2024
f3c1c39
Failing test
bb-face Jul 10, 2024
61822a3
Working test
bb-face Jul 10, 2024
bc08d5c
Fixing tests
bb-face Jul 10, 2024
571af00
Merge branch 'main' into 37-introduce-vm-feature-enablecomponentsrcda…
elliotBraem Jul 10, 2024
2f27f66
Fix test
bb-face Jul 12, 2024
2573239
Update readme
bb-face Jul 12, 2024
8471322
Merge branch '37-introduce-vm-feature-enablecomponentsrcdatakey-as-a-…
bb-face Jul 12, 2024
2bd71d4
Merge branch 'main' into 37-introduce-vm-feature-enablecomponentsrcda…
elliotBraem Jul 12, 2024
46ed43c
Merge branch 'main' into 37-introduce-vm-feature-enablecomponentsrcda…
elliotBraem Jul 13, 2024
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
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,13 @@ To support specific features of the VM or an accompanying development server, pr
"enabled": boolean, // Determines if hot reload is enabled (e.g., true)
"wss": string // WebSocket server URL to connect to. Optional. Defaults to `ws://${window.location.host}` (e.g., "ws://localhost:3001")
}
}
},
// Configuration options for the VM
"vm": {
"features": {
"enableComponentSrcDataKey": boolean, // adds the "data-component" attribute specifying the rendered component's "src"
}
}
}
```

Expand Down
47 changes: 47 additions & 0 deletions playwright-tests/tests/config.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import { describe, expect, test } from "@playwright/test";
import { waitForSelectorToBeVisible } from "../testUtils";

async function setupNearSocialViewer(page, src, config) {
await page.evaluate(
({ src, config }) => {
document.body.innerHTML = `<near-social-viewer src="${src}" config='${JSON.stringify(config)}'></near-social-viewer>`;
},
{ src, config }
);
}

describe("test data-component attribute", () => {
test.beforeEach(async ({ page }) => {
await page.goto("/");
});

test("by default there will be no data-component attribute", async ({
page,
}) => {
await page.evaluate(() => {
const src = "zavodil.near/widget/Lido";

document.body.innerHTML = `<near-social-viewer src="${src}"></near-social-viewer>`;
});

const dataComponentElements = page.locator("div[data-component]");
await expect(dataComponentElements).toHaveCount(0);
});

test("with the correct configuration there will be a data-component property in the components", async ({
page,
}) => {
const src = "zavodil.near/widget/Lido";
const config = { "vm": { "features": {"enableComponentSrcDataKey": true }}}

await setupNearSocialViewer(page, src, config);

await waitForSelectorToBeVisible(page, "div[data-component]");
const dataComponentValue = await page.getAttribute(
"div[data-component]",
"data-component"
);

expect(dataComponentValue).toBe(src);
});
});
8 changes: 6 additions & 2 deletions playwright-tests/tests/network.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@ test("should use default network (mainnet) when network value not provided", asy
await page.goto("/");

await page.evaluate(() => {
const config = JSON.stringify({ "vm": { "features": {"enableComponentSrcDataKey": true }}})

document.body.innerHTML = `
<near-social-viewer src="devs.near/widget/default"></near-social-viewer>
<near-social-viewer src="devs.near/widget/default" config='${config}'></near-social-viewer>
`;
});

Expand Down Expand Up @@ -53,8 +55,10 @@ test("should use testnet network when network attribute is provided", async ({

// Set the netork attribute to testnet
await page.evaluate(() => {
const config = JSON.stringify({ "vm": { "features": {"enableComponentSrcDataKey": true }}})

document.body.innerHTML = `
<near-social-viewer src="neardevs.testnet/widget/default" network="testnet"></near-social-viewer>
<near-social-viewer src="neardevs.testnet/widget/default" network="testnet" config='${config}'></near-social-viewer>
`;
});

Expand Down
12 changes: 8 additions & 4 deletions playwright-tests/tests/router.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@ test("Verify default route loads successfully and displays expected content", as
await page.goto("/");

await page.evaluate(() => {
const config = JSON.stringify({ "vm": { "features": {"enableComponentSrcDataKey": true }}})

document.body.innerHTML = `
<near-social-viewer src="devs.near/widget/default" initialprops='{"message": "hello world!"}'></near-social-viewer>
<near-social-viewer src="devs.near/widget/default" initialprops='{"message": "hello world!"}' config='${config}'></near-social-viewer>
`;
});

Expand Down Expand Up @@ -53,8 +55,8 @@ test("should load the other routes with params when provided", async ({

// Verify route loads
await waitForSelectorToBeVisible(
page,
'div[data-component="efiz.near/widget/Node"]'
page,
'body > near-social-viewer > div > div > div > div'
);

// Verify provided props are active
Expand All @@ -68,8 +70,10 @@ test("should be possible to set initialProps and src widget for the root path",
}) => {
await page.goto("/");
await page.evaluate(() => {
const config = JSON.stringify({ "vm": { "features": {"enableComponentSrcDataKey": true }}})

document.body.innerHTML = `
<near-social-viewer src="devhub.near/widget/app" initialProps='{"page": "community", "handle": "webassemblymusic"}'></near-social-viewer>
<near-social-viewer src="devhub.near/widget/app" initialProps='{"page": "community", "handle": "webassemblymusic"}' config='${config}'></near-social-viewer>
`;
});
await expect(
Expand Down
9 changes: 7 additions & 2 deletions playwright-tests/tests/rpc.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,11 @@ test("Verify default RPC is called when value not provided", async ({
await page.goto("/");

await page.evaluate(() => {
const config = JSON.stringify({ "vm": { "features": {"enableComponentSrcDataKey": true }}})


document.body.innerHTML = `
<near-social-viewer src="devs.near/widget/default"></near-social-viewer>
<near-social-viewer src="devs.near/widget/default" config='${config}'></near-social-viewer>
`;
});

Expand Down Expand Up @@ -62,8 +65,10 @@ test("Verify custom RPC is called when provided", async ({ page }) => {

// Set the rpc attribute to a custom rpc value
await page.evaluate((url) => {
const config = JSON.stringify({ "vm": { "features": {"enableComponentSrcDataKey": true }}})

document.body.innerHTML = `
<near-social-viewer src="devs.near/widget/default" rpc="${url}"></near-social-viewer>
<near-social-viewer src="devs.near/widget/default" rpc="${url}" config='${config}'></near-social-viewer>
`;
}, CUSTOM_RPC_URL);

Expand Down
2 changes: 1 addition & 1 deletion src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ function App(props) {
},
},
features: {
enableComponentSrcDataKey: true,
enableComponentSrcDataKey: config?.vm?.features?.enableComponentSrcDataKey,
},
config: {
defaultFinality: undefined,
Expand Down
Loading