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

Feature/885 relevant users events portals #886

Merged
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
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
4 changes: 4 additions & 0 deletions instances/events-committee.near/bos.config.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
{
"account": "events-committee.near",
"accounts": {
"deploy": "events-committee.near",
"signer": "events-committee.near"
},
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need this?

"aliasPrefix": "REPL",
"aliasesContainsPrefix": true,
"aliases": ["./aliases.mainnet.json"]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ const Compose = ({
showProposalIdAutoComplete,
onChangeKeyup,
handler,
sortedRelevantUsers,
}) => {
State.init({
data: data,
Expand Down Expand Up @@ -97,6 +98,7 @@ const Compose = ({
showProposalIdAutoComplete: showProposalIdAutoComplete,
autoFocus: state.autoFocus,
onChangeKeyup: onChangeKeyup,
sortedRelevantUsers,
}}
/>
</>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,16 @@ const onChangeKeyup = props.onChangeKeyup ?? (() => {}); // in case where we wan
const height = props.height ?? "390";
const className = props.className ?? "w-100";
const embeddCSS = props.embeddCSS;
const sortedRelevantUsers = props.sortedRelevantUsers || [];

State.init({
iframeHeight: height,
message: props.data,
});

const profilesData = Social.get("*/profile/name", "final");
const followingData = Social.get(
`${context.accountId}/graph/follow/**`,
"final"
);
const profilesData = Social.get("*/profile/name", "final") ?? {};
const followingData =
Social.get(`${context.accountId}/graph/follow/**`, "final") ?? {};

// SIMPLEMDE CONFIG //
const fontFamily = props.fontFamily ?? "sans-serif";
Expand Down Expand Up @@ -139,7 +138,13 @@ function getSuggestedAccounts(term) {
let results = [];

term = (term || "").replace(/\W/g, "").toLowerCase();
const limit = 5;
let limit = 5;
if (term.length < 2) {
results = [${sortedRelevantUsers
.map((u) => "{accountId:'" + u + "', score: 60}")
.join(",")}];
limit = ${5 + sortedRelevantUsers.length};
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't we use reuse SimpleMDE from the devhub instance?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes defenitly, we can do it in the next iteration of improvements.


const profiles = Object.entries(profilesData);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ const parseProposalKeyAndValue = (key, modifiedValue, originalValue) => {
<span>
accepted
<Widget
src={"${REPL_EVENTS}/widget/devhub.entity.proposal.AcceptedTerms"}
src={"${REPL_DEVHUB}/widget/devhub.entity.proposal.AcceptedTerms"}
props={{ proposalId: proposalId }}
/>
</span>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,12 @@ const item = {
path: `${REPL_EVENTS_CONTRACT}/post/main`,
blockHeight,
};
const comments = Social.index("comment", item, { subscribe: true }) ?? [];

const commentAuthors = [
...new Set(comments.map((comment) => comment.accountId)),
];

const proposalURL = getLinkUsingCurrentGateway(
`${REPL_EVENTS}/widget/app?page=proposal&id=${proposal.id}&timestamp=${snapshot.timestamp}`
);
Expand Down Expand Up @@ -451,6 +457,7 @@ const CheckBox = ({ value, isChecked, label, disabled, onClick }) => {
return (
<div className="d-flex gap-2 align-items-center">
<input
data-testid={label}
class="form-check-input"
type="checkbox"
value={value}
Expand Down Expand Up @@ -916,6 +923,12 @@ return (
item: item,
notifyAccountId: authorId,
id: proposal.id,
sortedRelevantUsers: [
authorId,
snapshot.supervisor,
snapshot.requested_sponsor,
...commentAuthors,
].filter((user) => user !== accountId),
}}
/>
</div>
Expand Down
126 changes: 32 additions & 94 deletions playwright-tests/tests/events/proposals.spec.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
import { test as base, expect } from "@playwright/test";
import { modifySocialNearGetRPCResponsesInsteadOfGettingWidgetsFromBOSLoader } from "../../util/bos-loader.js";
import {
pauseIfVideoRecording,
waitForSelectorToBeVisible,
} from "../../testUtils.js";
import { pauseIfVideoRecording } from "../../testUtils.js";
import {
setCommitWritePermissionDontAskAgainCacheValues,
setDontAskAgainCacheValues,
Expand All @@ -14,7 +11,6 @@ import {
encodeResultJSON,
} from "../../util/transaction.js";
import { mockRpcRequest } from "../../util/rpcmock.js";
import { mockSocialIndexResponses } from "../../util/socialapi.js";

const test = base.extend({
// Define an option and provide a default value.
Expand All @@ -27,7 +23,27 @@ test.afterEach(
async ({ page }) => await page.unrouteAll({ behavior: "ignoreErrors" })
);

test.describe("Wallet is connected, but not KYC verified", () => {
let acceptedTermsVersion = 122927956;
async function getCurrentBlockHeight(page) {
// set current block height for accepted terms and conditions
await page.route(`http://localhost:20000/`, async (route) => {
const request = route.request();
const requestPostData = request.postDataJSON();
if (
requestPostData?.method === "block" &&
requestPostData?.params?.finality === "optimistic"
) {
const response = await route.fetch();
const json = await response.json();
json.result.header.height = acceptedTermsVersion;
await route.fulfill({ response, json });
} else {
await route.continue();
}
});
}

test.describe.skip("Wallet is connected, but not KYC verified", () => {
test.use({
storageState:
"playwright-tests/storage-states/wallet-connected-not-kyc-verified-account.json",
Expand Down Expand Up @@ -170,85 +186,6 @@ test.describe("Don't ask again enabled", () => {
await page.waitForTimeout(1000);
await pauseIfVideoRecording(page);
});
test("should add comment on a proposal", async ({ page, account }) => {
await page.goto(`/${account}/widget/app?page=proposal&id=5`);
const widgetSrc = `${account}/widget/devhub.entity.proposal.ComposeComment`;

const delay_milliseconds_between_keypress_when_typing = 0;
const commentArea = await page
.frameLocator("iframe")
.locator(".CodeMirror textarea");
await commentArea.focus();
const text = "Comment testing";
await commentArea.pressSequentially(text, {
delay: delay_milliseconds_between_keypress_when_typing,
});
await commentArea.blur();
await pauseIfVideoRecording(page);

const accountId = "petersalomonsen.near";
await setCommitWritePermissionDontAskAgainCacheValues({
page,
widgetSrc,
accountId: accountId,
});

await mockTransactionSubmitRPCResponses(
page,
async ({ route, request, transaction_completed, last_receiver_id }) => {
const postData = request.postDataJSON();
const args_base64 = postData.params?.args_base64;
if (transaction_completed && args_base64) {
const args = atob(args_base64);
if (
postData.params.account_id === "social.near" &&
postData.params.method_name === "get" &&
args === `{"keys":["${accountId}/post/**"]}`
) {
const response = await route.fetch();
const json = await response.json();
const resultObj = decodeResultJSON(json.result.result);
resultObj[accountId].post.main = JSON.stringify({
text: text,
});
json.result.result = encodeResultJSON(resultObj);
await route.fulfill({ response, json });
return;
} else {
await route.continue();
}
} else {
await route.continue();
}
}
);
const commentButton = await page.getByRole("button", { name: "Comment" });
await expect(commentButton).toBeAttached();
await commentButton.scrollIntoViewIfNeeded();
await commentButton.click();
await expect(
await page.frameLocator("iframe").locator(".CodeMirror")
).toContainText(text);

const loadingIndicator = await page.locator(".comment-btn-spinner");
await expect(loadingIndicator).toBeAttached();
await loadingIndicator.waitFor({ state: "detached", timeout: 30000 });
await expect(loadingIndicator).not.toBeVisible();
const transaction_successful_toast = await page.getByText(
"Comment Submitted Successfully",
{ exact: true }
);
await expect(transaction_successful_toast).toBeVisible();

await expect(transaction_successful_toast).not.toBeAttached();
await expect(
await page.frameLocator("iframe").locator(".CodeMirror")
).not.toContainText(text);
await expect(
await page.frameLocator("iframe").locator(".CodeMirror")
).toContainText("Add your comment here...");
await pauseIfVideoRecording(page);
});
});

test.describe.skip('Moderator with "Don\'t ask again" enabled', () => {
Expand Down Expand Up @@ -401,6 +338,7 @@ test.describe("Wallet is connected", () => {
account,
}) => {
test.setTimeout(120000);
await getCurrentBlockHeight(page);
await page.goto(`/${account}/widget/app?page=create-proposal`);

const delay_milliseconds_between_keypress_when_typing = 0;
Expand Down Expand Up @@ -510,21 +448,21 @@ test.describe("Wallet is connected", () => {
await pauseIfVideoRecording(page);
});

test.skip("should show relevant users in mention autocomplete", async ({
test("should show relevant users in mention autocomplete", async ({
page,
account,
}) => {
await page.goto(`/${account}/widget/app?page=proposal&id=112`);
await page.goto(`/${account}/widget/app?page=proposal&id=2`);

await page.waitForSelector(`iframe`, {
state: "visible",
});

const comment = page.getByRole("link", { name: "geforcy.near" });
const comment = page.getByRole("link", { name: "toronto-sc.near" }).first();
await comment.waitFor();
await comment.scrollIntoViewIfNeeded();

const heading = page.getByRole("heading", { name: "Relevant Mentions" });
const heading = page.getByText("Add a comment");
await heading.waitFor();
await heading.scrollIntoViewIfNeeded();

Expand All @@ -549,10 +487,10 @@ test.describe("Wallet is connected", () => {
);
const liLocators = await liFrameLocators.owner().all();
const expected = [
"thomasguntenaar.near", // author,
"theori.near", // supervisor,
"neardevdao.near", // requested_sponsor,
"geforcy.near", // comment author,
"toronto-sc.near",
"yarotska.near",
"events-committee.near",
"nneoma.near",
];
let mentionSuggestions = [];
for (let i = 0; i < liLocators.length; i++) {
Expand Down Expand Up @@ -598,6 +536,7 @@ test.describe("Wallet is connected", () => {
account,
}) => {
test.setTimeout(120000);
await getCurrentBlockHeight(page);
await page.goto(`/${account}/widget/app?page=create-proposal`);
await page.route(
"https://near-queryapi.api.pagoda.co/v1/graphql",
Expand Down Expand Up @@ -707,7 +646,6 @@ test.describe("Wallet is connected", () => {
delay: delay_milliseconds_between_keypress_when_typing,
}
);

await pauseIfVideoRecording(page);

await page
Expand Down
4 changes: 3 additions & 1 deletion playwright-tests/tests/proposal/proposals.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ test.describe("Don't ask again enabled", () => {
await modifySocialNearGetRPCResponsesInsteadOfGettingWidgetsFromBOSLoader(
page
);
console.log({ account });
await page.goto(`/${account}/widget/app?page=proposals`);

const widgetSrc = `${account}/widget/devhub.entity.proposal.Editor`;
Expand Down Expand Up @@ -211,6 +210,7 @@ test.describe('Moderator with "Don\'t ask again" enabled', () => {
},
modifyOriginalResultFunction: (originalResult) => {
originalResult.snapshot.timeline.status = "REVIEW";

if (isTransactionCompleted) {
const lastSnapshot =
originalResult.snapshot_history[
Expand Down Expand Up @@ -246,6 +246,7 @@ test.describe('Moderator with "Don\'t ask again" enabled', () => {
);

await page.goto(`/${account}/widget/app?page=proposal&id=17`);

await setDontAskAgainCacheValues({
page,
contractId: account,
Expand Down Expand Up @@ -340,6 +341,7 @@ test.describe("Wallet is connected", () => {
test.setTimeout(120000);
await getCurrentBlockHeight(page);
await page.goto(`/${account}/widget/app?page=create-proposal`);

const delay_milliseconds_between_keypress_when_typing = 0;
const titleArea = await page.getByRole("textbox").first();
await expect(titleArea).toBeEditable();
Expand Down
2 changes: 1 addition & 1 deletion playwright.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export default defineConfig({
},
{
name: "devhub",
testMatch: /(blog|community|other|proposal|sunset)\/.*.spec.js/, // (proposal|events)
testMatch: /(blog|community|other|proposal|sunset)\/.*.spec.js/,
use: {
...devices["Desktop Chrome"],
baseURL: "http://localhost:8080",
Expand Down
Loading