diff --git a/config/webpack.development.js b/config/webpack.development.js index 64db178..01307e5 100644 --- a/config/webpack.development.js +++ b/config/webpack.development.js @@ -2,7 +2,7 @@ const path = require("path"); const { HotModuleReplacementPlugin } = require("webpack"); module.exports = () => ({ - devtool: false, + devtool: 'inline-source-map', module: { rules: [ { diff --git a/package.json b/package.json index 5ec67cd..a3d44fe 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "near-bos-webcomponent", - "version": "0.0.6", + "version": "0.0.7", "homepage": "https://github.com/petersalomonsen/near-bos-webcomponent", "repository": { "type": "git", diff --git a/playwright-tests/tests/rpc.spec.js b/playwright-tests/tests/rpc.spec.js new file mode 100644 index 0000000..48f60de --- /dev/null +++ b/playwright-tests/tests/rpc.spec.js @@ -0,0 +1,85 @@ +import { expect, test } from "@playwright/test"; +import { waitForSelectorToBeVisible } from "../testUtils"; + +const DEFAULT_RPC_URL = "https://rpc.mainnet.near.org/"; +const CUSTOM_RPC_URL = "https://custom-rpc-url.com/"; + +test("Verify default RPC is called when value not provided", async ({ + page, +}) => { + // Set up a listener for the default rpc request + const defaultRpcRequestPromise = page.waitForRequest(DEFAULT_RPC_URL); + + // Navigate to the default route + await page.goto("/"); + + // Verify the viewer is visible + await waitForSelectorToBeVisible(page, "near-social-viewer"); + + // Get the value of the rpc attribute + const rpc = await page.evaluate(() => { + const viewer = document.querySelector("near-social-viewer"); + return viewer.getAttribute("rpc"); + }); + + // expect value to be undefined (aka use default value) + expect(rpc, undefined); + + // Wait for the widget to render + await waitForSelectorToBeVisible( + page, + 'div[data-component="devs.near/widget/default"]' + ); + + // Assert that the default RPC request has been made + const defaultRpcRequest = await defaultRpcRequestPromise; + expect(defaultRpcRequest).toBeTruthy(); +}); + +test("Verify custom RPC is called when provided", async ({ page }) => { + // Navigate to the default route + await page.goto("/"); + + // Verify the viewer is visible + await waitForSelectorToBeVisible(page, "near-social-viewer"); + + // Mock the custom rpc call so that the request doesn't hang + await page.route(CUSTOM_RPC_URL, (route) => { + route.fulfill({ + status: 200, + contentType: "application/json", + body: JSON.stringify({ result: "some valid response" }), + }); + }); + + // Set the rpc attribute to a custom rpc value + await page.evaluate((url) => { + const viewer = document.querySelector("near-social-viewer"); + viewer.setAttribute("rpc", url); + }, CUSTOM_RPC_URL); + + // Get the value of the rpc attribute + const actualRpc = await page.evaluate(() => { + const viewer = document.querySelector("near-social-viewer"); + return viewer.getAttribute("rpc"); + }); + + // Assert it equals custom value + expect(actualRpc).toBe(CUSTOM_RPC_URL); + + // Wait for the widget to render + await waitForSelectorToBeVisible( + page, + 'div[data-component="devs.near/widget/default"]' + ); + + // Set the src to new value (which should trigger the custom rpc call) + await page.evaluate(() => { + const viewer = document.querySelector("near-social-viewer"); + viewer.setAttribute("src", "efiz.near/widget/Tree"); + }); + + // Expect that the custom RPC is called + const customRpcRequest = await page.waitForRequest(CUSTOM_RPC_URL); + expect(customRpcRequest).toBeTruthy(); +}); diff --git a/public/index.html b/public/index.html index 02d9882..e0e4f21 100644 --- a/public/index.html +++ b/public/index.html @@ -1,107 +1,117 @@ +
+ + +