Skip to content

Commit

Permalink
Fix linked rfp on proposal feed page (#934)
Browse files Browse the repository at this point in the history
* fix linked rfp on proposal feed page

* add test
  • Loading branch information
Megha-Dev-19 authored Sep 23, 2024
1 parent 347a322 commit ea53bde
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 7 deletions.
32 changes: 25 additions & 7 deletions instances/devhub.near/widget/devhub/entity/proposal/Feed.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,13 @@ const FeedItem = ({ proposal, index }) => {
)}
</div>
{isLinked && rfpData && (
<div className="text-sm text-muted d-flex gap-1 align-items-center">
<div
className="text-sm text-muted d-flex gap-1 align-items-center"
data-testid={
`proposalId_${proposal.proposal_id}` +
`_rfpId_${rfpData.rfp_id}`
}
>
<i class="bi bi-link-45deg"></i>
In response to RFP :
<a
Expand Down Expand Up @@ -310,6 +316,18 @@ const FeedPage = () => {
}
}`;

const rfpQuery = `query GetLatestSnapshot($offset: Int = 0, $limit: Int = 10, $where: ${rfpFeedIndexerQueryName}_bool_exp = {}) {
${rfpFeedIndexerQueryName}(
offset: $offset
limit: $limit
order_by: {rfp_id: desc}
where: $where
) {
name
rfp_id
}
}`;

function fetchGraphQL(operationsDoc, operationName, variables) {
return asyncFetch(QUERYAPI_ENDPOINT, {
method: "POST",
Expand Down Expand Up @@ -401,12 +419,12 @@ const FeedPage = () => {
result.body.data[`${proposalFeedIndexerQueryName}_aggregate`];
const promises = data.map((item) => {
if (isNumber(item.linked_rfp)) {
return fetchGraphQL(rfpQuery, "GetLatestSnapshot", {}).then(
(result) => {
const rfpData = result.body.data?.[rfpQueryName];
return { ...item, rfpData: rfpData[0] };
}
);
return fetchGraphQL(rfpQuery, "GetLatestSnapshot", {
where: { rfp_id: { _eq: item.linked_rfp } },
}).then((result) => {
const rfpData = result.body.data?.[rfpFeedIndexerQueryName];
return { ...item, rfpData: rfpData[0] };
});
} else {
return Promise.resolve(item);
}
Expand Down
45 changes: 45 additions & 0 deletions playwright-tests/tests/infrastructure/proposal.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,51 @@ test.describe("Wallet is connected as admin", () => {
timeout: 10000,
});
});

test("should show correct linked RFP to a proposal in feed page", async ({
page,
}) => {
test.setTimeout(120000);
await page.goto("/infrastructure-committee.near/widget/app?page=proposals");
let proposalId;
const linkedRfpId = 0;
// add linked RFP to latest proposal
await page.route(
"https://near-queryapi.api.pagoda.co/v1/graphql",
async (route) => {
const response = await route.fetch();
const json = await response.json();
if (
json?.data?.[
"polyprogrammist_near_devhub_ic_v1_proposals_with_latest_snapshot"
]
) {
json.data[
"polyprogrammist_near_devhub_ic_v1_proposals_with_latest_snapshot"
] = json.data[
"polyprogrammist_near_devhub_ic_v1_proposals_with_latest_snapshot"
].map((i, index) => {
if (index === 0) {
proposalId = i.proposal_id;
return {
...i,
linked_rfp: linkedRfpId,
};
}
return i;
});
}
await route.fulfill({ response, json });
}
);
await page.waitForTimeout(10_000);
await expect(
page.getByTestId(`proposalId_${proposalId}_rfpId_${linkedRfpId}`)
).toBeVisible({
timeout: 10000,
});
});

test("should create proposal", async ({ page }) => {
await page.goto("/infrastructure-committee.near/widget/app?page=proposals");

Expand Down

0 comments on commit ea53bde

Please sign in to comment.