Skip to content

Commit

Permalink
Fix proposals build (#5080) skip-tests
Browse files Browse the repository at this point in the history
* Fix types

* Fix types

* Fix unit and e2e tests

* Fix E2E
  • Loading branch information
motechFR authored Nov 27, 2024
1 parent c32fc58 commit 75448e1
Show file tree
Hide file tree
Showing 14 changed files with 263 additions and 101 deletions.
64 changes: 41 additions & 23 deletions __e2e__/proposals/freeFormProposalTemplate.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import type { ProposalWorkflowTyped } from '@charmverse/core/proposals';
import { testUtilsMembers, testUtilsUser } from '@charmverse/core/test';
import { expect, test } from '__e2e__/testWithFixtures';
import { generateUserAndSpace, loginBrowserUser } from '__e2e__/utils/mocks';
import { sleep } from 'zksync-web3/build/src/utils';

import { generateProposalWorkflowWithEvaluations } from 'testing/utils/proposals';

Expand Down Expand Up @@ -112,18 +113,10 @@ test.describe.serial('Create and use Proposal Template', async () => {
// Configure reviewers for rubric evaluation
await proposalPage.selectEvaluationReviewer('rubric', role.id);

await page.pause();

// Configure first rubric criteria added by default
await Promise.all([
proposalPage.page.waitForResponse('**/api/proposals/**/rubric-criteria'), // let api update before continuing
proposalPage.editRubricCriteriaLabel.fill(firstRubricConfig.title)
proposalPage.page.waitForResponse('**/api/proposals/**'), // let api update before continuing
proposalPage.editRubricCriteriaMaxScore.fill(firstRubricConfig.maxScore.toString())
]);
await proposalPage.editRubricCriteriaDescription.fill(firstRubricConfig.description);
await proposalPage.editRubricCriteriaMinScore.fill(firstRubricConfig.minScore.toString());
const updateProposalResponse = proposalPage.page.waitForResponse('**/api/proposals/**');
await proposalPage.editRubricCriteriaMaxScore.fill(firstRubricConfig.maxScore.toString());
await updateProposalResponse;

// Configure vote settings
await proposalPage.selectEvaluationReviewer('vote', 'space_member');
Expand Down Expand Up @@ -151,6 +144,22 @@ test.describe.serial('Create and use Proposal Template', async () => {
// Edit the proposal content
await documentPage.typeText(templatePageContent.description);

// await proposalPage.page.reload();

// await Promise.all([proposalPage.page.waitForResponse('**/api/proposals/**/rubric-criteria')]);

await proposalPage.editRubricCriteriaDescription.fill(firstRubricConfig.description);

await sleep(500);

await proposalPage.editRubricCriteriaLabel.fill(firstRubricConfig.title);

await sleep(500);

await proposalPage.editRubricCriteriaMinScore.fill(firstRubricConfig.minScore.toString());

await proposalPage.page.reload();

await proposalPage.publishNewProposalButton.isEnabled();
await Promise.all([page.waitForResponse('**/publish'), proposalPage.publishNewProposalButton.click()]);

Expand Down Expand Up @@ -202,29 +211,29 @@ test.describe.serial('Create and use Proposal Template', async () => {
...savedProposalTemplate.proposal?.evaluations[0],
// permissions: [] as any,
reviewers: [
{
expect.objectContaining({
evaluationId: savedProposalTemplate.proposal?.evaluations[0].id,
id: savedProposalTemplate.proposal?.evaluations[0].reviewers[0].id,
proposalId: savedProposalTemplate.proposal?.id,
roleId: null,
systemRole: 'author',
userId: null
}
})
]
}),

expect.objectContaining({
...savedProposalTemplate.proposal?.evaluations[1],
// permissions: [] as any,
reviewers: [
{
expect.objectContaining({
evaluationId: savedProposalTemplate.proposal?.evaluations[1].id,
id: savedProposalTemplate.proposal?.evaluations[1].reviewers[0].id,
proposalId: savedProposalTemplate.proposal?.id,
roleId: role.id,
systemRole: null,
userId: null
}
})
]
}),
expect.objectContaining({
Expand All @@ -244,14 +253,14 @@ test.describe.serial('Create and use Proposal Template', async () => {
// We just want to save settings, but not create an actual vote
vote: null,
reviewers: [
{
expect.objectContaining({
evaluationId: savedProposalTemplate.proposal?.evaluations[2].id,
id: savedProposalTemplate.proposal?.evaluations[2].reviewers[0].id,
proposalId: savedProposalTemplate.proposal?.id,
roleId: null,
systemRole: 'space_member',
userId: null
}
})
]
})
],
Expand All @@ -278,7 +287,14 @@ test.describe.serial('Create and use Proposal Template', async () => {

// We only need to use to title. The content should come through from the template
await expect(proposalPage.documentTitleInput).toBeVisible();
await proposalPage.documentTitleInput.fill(userProposalConfig.title);

await Promise.all([
proposalPage.page.waitForResponse('**/**'),
proposalPage.documentTitleInput.fill(userProposalConfig.title)
]);

// In test env, needed to reload to get the latest data
await proposalPage.page.reload();

await proposalPage.page.getByRole('button', { name: 'Rubric' }).click();

Expand All @@ -293,6 +309,8 @@ test.describe.serial('Create and use Proposal Template', async () => {

await expect(proposalPage.charmEditor).toHaveText(templatePageContent.description);

await expect(proposalPage.publishNewProposalButton).toBeEnabled();

await Promise.all([page.waitForResponse('**/publish'), proposalPage.publishNewProposalButton.click()]);

const savedUserProposalFromTemplate = await prisma.page.findFirstOrThrow({
Expand Down Expand Up @@ -351,27 +369,27 @@ test.describe.serial('Create and use Proposal Template', async () => {
{
...userProposalEvaluations?.[0],
reviewers: [
{
expect.objectContaining({
evaluationId: userProposalEvaluations?.[0].id,
id: userProposalEvaluations?.[0].reviewers[0].id,
proposalId: savedUserProposalFromTemplate.proposal?.id,
roleId: null,
systemRole: 'author',
userId: null
}
})
]
},
{
...userProposalEvaluations?.[1],
reviewers: [
{
expect.objectContaining({
evaluationId: userProposalEvaluations?.[1].id,
id: userProposalEvaluations?.[1].reviewers[0].id,
proposalId: savedUserProposalFromTemplate.proposal?.id,
roleId: role.id,
systemRole: null,
userId: null
}
})
]
},
{
Expand All @@ -390,14 +408,14 @@ test.describe.serial('Create and use Proposal Template', async () => {
// We just want to save settings, but not create an actual vote
vote: null,
reviewers: [
{
expect.objectContaining({
evaluationId: savedUserProposalFromTemplate.proposal?.evaluations[2].id,
id: savedUserProposalFromTemplate.proposal?.evaluations[2].reviewers[0].id,
proposalId: savedUserProposalFromTemplate.proposal?.id,
roleId: null,
systemRole: 'space_member',
userId: null
}
})
]
}
],
Expand Down
17 changes: 11 additions & 6 deletions __e2e__/proposals/proposalEvaluations.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,13 @@ test.describe.serial('Proposal Evaluations', () => {

await proposalPage.evaluationVoteDurationInput.fill(settingsToTest.voteDuration.toString());
await proposalPage.evaluationVotePassThresholdInput.fill(settingsToTest.votePassThreshold.toString());

await proposalPage.page.waitForResponse('**/evaluation');

await proposalPage.page.reload();

await expect(proposalPage.publishNewProposalButton).toBeEnabled();

await Promise.all([
proposalPage.page.waitForResponse('**/api/proposals/**/publish'),
proposalPage.publishNewProposalButton.click()
Expand Down Expand Up @@ -191,14 +196,14 @@ test.describe.serial('Proposal Evaluations', () => {
proposalId: proposal.id,
title: settingsToTest.evaluationFeedbackTitle,
reviewers: [
{
expect.objectContaining({
evaluationId: expect.any(String),
id: expect.any(String),
proposalId: proposal.id,
roleId: null,
userId: null,
systemRole: 'author'
}
})
],
permissions: expect.arrayContaining(
proposalEvaluationPermissions[0].permissions.map((p) => expect.objectContaining(p))
Expand Down Expand Up @@ -241,14 +246,14 @@ test.describe.serial('Proposal Evaluations', () => {

expect(proposal.evaluations[2]).toMatchObject({
reviewers: [
{
expect.objectContaining({
evaluationId: expect.any(String),
id: expect.any(String),
proposalId: proposal.id,
roleId: role.id,
userId: null,
systemRole: null
}
})
],
permissions: expect.arrayContaining(
proposalEvaluationPermissions[2].permissions.map((p) => expect.objectContaining(p))
Expand All @@ -264,14 +269,14 @@ test.describe.serial('Proposal Evaluations', () => {

expect(proposal.evaluations[3]).toMatchObject({
reviewers: [
{
expect.objectContaining({
evaluationId: expect.any(String),
id: expect.any(String),
proposalId: proposal.id,
roleId: null,
userId: null,
systemRole: 'space_member'
}
})
],
permissions: expect.arrayContaining(
proposalEvaluationPermissions[3].permissions.map((p) => expect.objectContaining(p))
Expand Down
30 changes: 23 additions & 7 deletions __e2e__/proposals/voteOnProposal.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,10 @@ test.describe.serial('Proposal Evaluation Votes', () => {
// Configure proposal settings
await documentPage.documentTitle.click();

await documentPage.documentTitleInput.fill(settingsToTest.proposalTemplateTitle);
await Promise.all([
documentPage.page.waitForResponse('**/api/pages/**'),
documentPage.documentTitleInput.fill(settingsToTest.proposalTemplateTitle)
]);

await documentPage.charmEditor.fill('This is a test proposal');

Expand All @@ -107,7 +110,13 @@ test.describe.serial('Proposal Evaluation Votes', () => {
await proposalPage.evaluationVoteSettings.click();

await proposalPage.evaluationVoteDurationInput.fill(settingsToTest.voteDuration.toString());
await proposalPage.evaluationVotePassThresholdInput.fill(settingsToTest.votePassThreshold.toString());

await Promise.all([
proposalPage.page.waitForResponse('**/evaluation'),
proposalPage.evaluationVotePassThresholdInput.fill(settingsToTest.votePassThreshold.toString())
]);

await proposalPage.page.reload();

await expect(proposalPage.publishNewProposalButton).toBeEnabled();
await Promise.all([proposalPage.page.waitForResponse('**/publish'), proposalPage.publishNewProposalButton.click()]);
Expand Down Expand Up @@ -147,14 +156,14 @@ test.describe.serial('Proposal Evaluation Votes', () => {
proposalId: proposalTemplate.id,
title: settingsToTest.voteStepTitle,
reviewers: [
{
expect.objectContaining({
evaluationId: proposalTemplate.evaluations[0].id,
id: proposalTemplate.evaluations[0].reviewers[0].id,
proposalId: proposalTemplate.id,
roleId: role.id,
userId: null,
systemRole: null
}
})
],
// Empty permissions since this is a template
permissions: []
Expand Down Expand Up @@ -190,13 +199,20 @@ test.describe.serial('Proposal Evaluation Votes', () => {

await documentPage.documentTitle.click();

await documentPage.documentTitleInput.fill(settingsToTest.memberProposalTitle);
await Promise.all([
documentPage.page.waitForResponse('**/api/pages/**'),
documentPage.documentTitleInput.fill(settingsToTest.memberProposalTitle)
]);

await documentPage.charmEditor.fill('This is a test proposal');

// Workflow auto-selected when loading the proposal
await expect(proposalPage.workflowSelect).toHaveText(workflow.title);

await proposalPage.page.reload();

await expect(proposalPage.publishNewProposalButton).toBeEnabled();

await Promise.all([proposalPage.page.waitForResponse('**/publish'), proposalPage.publishNewProposalButton.click()]);

// Test proposal data at the database level to ensure correct persistence
Expand Down Expand Up @@ -235,14 +251,14 @@ test.describe.serial('Proposal Evaluation Votes', () => {
proposalId: proposal.id,
title: settingsToTest.voteStepTitle,
reviewers: [
{
expect.objectContaining({
evaluationId: proposal.evaluations[0].id,
id: proposal.evaluations[0].reviewers[0].id,
proposalId: proposal.id,
roleId: role.id,
userId: null,
systemRole: null
}
})
],
// Empty permissions since this is a template
permissions: proposal.evaluations[0].permissions
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import type { ProposalRubricCriteria, ProposalRubricCriteriaAnswer } from '@charmverse/core/prisma-client';
import type {
DraftProposalRubricCriteriaAnswer,
ProposalRubricCriteria,
ProposalRubricCriteriaAnswer
} from '@charmverse/core/prisma-client';
import styled from '@emotion/styled';
import { DeleteOutlined } from '@mui/icons-material';
import {
Expand Down Expand Up @@ -36,7 +40,7 @@ type Props = {
evaluationId: string;
disabled: boolean; // for non-reviewers
answers?: ProposalRubricCriteriaAnswer[];
draftAnswers?: ProposalRubricCriteriaAnswer[];
draftAnswers?: DraftProposalRubricCriteriaAnswer[];
criteriaList: ProposalRubricCriteria[];
onSubmit: (props: { isDraft: boolean }) => Promise<void>;
archived?: boolean;
Expand Down Expand Up @@ -220,7 +224,7 @@ export function RubricAnswersForm({
setShowDraftAnswers(false);
}

function mapAnswersToFormValues(_answers?: ProposalRubricCriteriaAnswer[]) {
function mapAnswersToFormValues(_answers?: (DraftProposalRubricCriteriaAnswer | ProposalRubricCriteriaAnswer)[]) {
return criteriaList.map(
(criteria) =>
_answers?.find((a) => a.rubricCriteriaId === criteria.id) || {
Expand Down
Loading

0 comments on commit 75448e1

Please sign in to comment.