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

e2e: make tests green again. #2383

Merged
merged 13 commits into from
May 11, 2021
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
"test": "react-app-rewired test --env=jsdom",
"up": "docker-compose up --abort-on-container-exit --exit-code-from e2e",
"cy:run": "cd teste2e && npm install && cypress run",
"cy:open": "cd teste2e && cypress open",
"cy:open": "cd teste2e && npm install && cypress open",
"test:e2e:run": "START_SERVER_AND_TEST_INSECURE=1 start-server-and-test start https-get://localhost:3000 cy:run",
"test:e2e:browser": "START_SERVER_AND_TEST_INSECURE=1 start-server-and-test start https-get://localhost:3000 cy:open",
"eject": "react-app-rewired eject",
Expand Down
4 changes: 1 addition & 3 deletions src/actions/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -838,9 +838,7 @@ export const onSubmitProposal = (
return Promise.resolve(
api.makeProposal(name, description, rfpDeadline, type, rfpLink, files)
)
.then((proposal) => {
return api.signRegister(userid, proposal);
})
.then((proposal) => api.signRegister(userid, proposal))
.then((proposal) => api.newProposal(csrf, proposal))
.then(({ record }) => {
dispatch(
Expand Down
4 changes: 2 additions & 2 deletions src/components/ModalConfirm.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,10 @@ const ModalConfirm = ({
onClose={success && onCloseSuccess ? onCloseSuccess : onClose}
iconComponent={
!success ? (
<Icon type={"info"} size={26} />
<Icon type="info" size={26} />
) : (
<Icon
type={"checkmark"}
type="checkmark"
iconColor={iconCheckmarkColor}
backgroundColor={successIconBgColor}
size={26}
Expand Down
9 changes: 6 additions & 3 deletions src/components/ModalConfirmWithReason.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ const ModalConfirmWithReason = ({
title,
reasonLabel,
successMessage,
successTitle
successTitle,
onCloseSuccess
}) => {
const [success, setSuccess] = useState(false);

Expand Down Expand Up @@ -58,7 +59,7 @@ const ModalConfirmWithReason = ({
style={{ width: "600px" }}
title={(success && successTitle) || title}
show={show}
onClose={onClose}
onClose={success && onCloseSuccess ? onCloseSuccess : onClose}
iconComponent={
!success ? (
<Icon type={"info"} size={26} />
Expand Down Expand Up @@ -128,7 +129,9 @@ const ModalConfirmWithReason = ({
<>
{successMessage}
<div className="justify-right margin-top-m">
<Button data-testid="reason-confirm-success" onClick={onClose}>
<Button
data-testid="reason-confirm-success"
onClick={onCloseSuccess || onClose}>
Ok
</Button>
</div>
Expand Down
19 changes: 12 additions & 7 deletions src/containers/Proposal/Actions/PublicActionsProvider.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React, { useCallback } from "react";
import { withRouter } from "react-router-dom";
import { Text } from "pi-ui";
import Link from "src/components/Link";
import { PublicProposalsActionsContext, usePublicActions } from "./hooks";
Expand All @@ -17,7 +18,7 @@ import {
PROPOSAL_STATE_VETTED
} from "src/constants";

const PublicActionsProvider = ({ children }) => {
const PublicActionsProvider = ({ children, history }) => {
const {
onCensorProposal,
onAbandonProposal,
Expand All @@ -31,6 +32,10 @@ const PublicActionsProvider = ({ children }) => {

const handleOpenAbandonModal = useCallback(
(proposal) => {
const handleCloseSuccess = () => {
handleCloseModal();
history.push(`/record/${proposal.censorshiprecord.token}`);
};
handleOpenModal(ModalConfirmWithReason, {
title: `Abandon - ${proposal.name}`,
reasonLabel: "Abandon reason",
Expand All @@ -43,10 +48,11 @@ const PublicActionsProvider = ({ children }) => {
under the <Link to="/?tab=abandoned">Abandoned</Link> tab.
</Text>
),
onClose: handleCloseModal
onClose: handleCloseModal,
onCloseSuccess: handleCloseSuccess
});
},
[handleCloseModal, handleOpenModal, onAbandonProposal]
[handleCloseModal, handleOpenModal, onAbandonProposal, history]
);

const handleOpenAuthorizeVoteModal = useCallback(
Expand Down Expand Up @@ -166,9 +172,8 @@ const PublicActionsProvider = ({ children }) => {
successMessage: (
<Text>
The proposal has been successfully censored! Now it will appear under
under{" "}
<Link to={"/admin/records?tab=unvetted censored"}>Censored</Link> tab
among Admin Proposals.
under <Link to="/admin/records?tab=unvetted censored">Censored</Link>{" "}
tab among Admin Proposals.
</Text>
),
onClose: handleCloseModal
Expand All @@ -190,4 +195,4 @@ const PublicActionsProvider = ({ children }) => {
);
};

export default PublicActionsProvider;
export default withRouter(PublicActionsProvider);
20 changes: 9 additions & 11 deletions src/containers/Proposal/Actions/UnvettedActionsProvider.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ const UnvettedActionsProvider = ({ children, history }) => {
const [handleOpenModal, handleCloseModal] = useModalContext();

const handleOpenCensorModal = (proposal) => {
const handleClose = () => {
const handleCloseSuccess = () => {
handleCloseModal();
history.push(`/record/${proposal.censorshiprecord.token}`);
};
handleOpenModal(ModalConfirmWithReason, {
title: `Censor proposal - ${proposal.name}`,
Expand All @@ -25,19 +26,16 @@ const UnvettedActionsProvider = ({ children, history }) => {
successMessage: (
<Text>
The proposal has been successfully censored! Now it will appear under
under{" "}
<Link to={"/admin/records?tab=unvetted censored"}>Censored</Link> tab
among Admin Proposals.
under <Link to="/admin/records?tab=unvetted censored">Censored</Link>{" "}
tab among Admin Proposals.
</Text>
),
onClose: handleClose
onClose: handleCloseModal,
onCloseSuccess: handleCloseSuccess
});
};

const handleOpenApproveModal = (proposal) => {
const handleClose = () => {
handleCloseModal();
};
const handleCloseSuccess = () => {
handleCloseModal();
history.push(`/record/${proposal.censorshiprecord.token}`);
Expand All @@ -50,11 +48,11 @@ const UnvettedActionsProvider = ({ children, history }) => {
successMessage: (
<Text>
The proposal has been successfully approved! Now it will appear under{" "}
<Link to={"/?tab=in%20discussion"}>In discussion</Link> tab among
Public Proposals.
<Link to="/?tab=in%20discussion">In discussion</Link> tab among Public
Proposals.
</Text>
),
onClose: handleClose,
onClose: handleCloseModal,
onCloseSuccess: handleCloseSuccess
});
};
Expand Down
58 changes: 28 additions & 30 deletions src/lib/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,36 +86,34 @@ export const makeProposal = (
type,
linkto = 0,
attachments = []
) => {
return {
files: [
convertMarkdownToFile(markdown),
{
//proposal metadata file
name: PROPOSAL_METADATA_FILENAME,
mime: "text/plain; charset=utf-8",
digest: objectToSHA256({ name }),
payload: bufferToBase64String(objectToBuffer({ name }))
},
...(linkby || linkto
? [
{
name: VOTE_METADATA_FILENAME,
mime: "text/plain; charset=utf-8",
digest: objectToSHA256({ linkto, linkby }),
payload: bufferToBase64String(objectToBuffer({ linkto, linkby }))
}
]
: []),
...(attachments || [])
].map(({ name, mime, payload, digest }) => ({
name,
mime,
payload,
digest: digest ? digest : digestPayload(payload)
}))
};
};
) => ({
files: [
convertMarkdownToFile(markdown),
{
// Proposal metadata file
name: PROPOSAL_METADATA_FILENAME,
mime: "text/plain; charset=utf-8",
digest: objectToSHA256({ name }),
payload: bufferToBase64String(objectToBuffer({ name }))
},
...(linkby || linkto
? [
{
name: VOTE_METADATA_FILENAME,
mime: "text/plain; charset=utf-8",
digest: objectToSHA256({ linkto, linkby }),
payload: bufferToBase64String(objectToBuffer({ linkto, linkby }))
}
]
: []),
...(attachments || [])
].map(({ name, mime, payload, digest }) => ({
name,
mime,
payload,
digest: digest ? digest : digestPayload(payload)
}))
});

export const makeInvoice = (
month,
Expand Down
2 changes: 1 addition & 1 deletion src/reducers/models/credits.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const credits = (state = DEFAULT_STATE, action) =>
})(state),
[act.RECEIVE_RESCAN_USER_PAYMENTS]: () => {
const userid = action.payload.userid;
const newcredits = action.payload.newcredits;
const newcredits = action.payload.newcredits || [];
const unspent = state.byUserID[userid]
? [...state.byUserID[userid].unspent, ...newcredits]
: [...newcredits];
Expand Down
10 changes: 5 additions & 5 deletions teste2e/cypress/e2e/adminComments.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,18 @@ describe("User admin comments", () => {
const proposal = buildProposal();
cy.login(user);
cy.identity();
cy.createProposal(proposal).then((res) => {
cy.approveProposal(res.body.censorshiprecord);
cy.visit(`proposals/${res.body.censorshiprecord.token.substring(0, 7)}`);
cy.createProposal(proposal).then(({ body: { record } }) => {
cy.approveProposal(record.censorshiprecord);
cy.visit(`record/${record.censorshiprecord.token.substring(0, 7)}`);
cy.findByText(/waiting for author/i).should("exist");
const { text } = buildComment();
cy.findByTestId(/text-area/i).type(text);
cy.route("POST", "/api/v1/comments/new").as("newComment");
cy.route("POST", "/api/comments/v1/new").as("newComment");
cy.findByText(/add comment/i).click();
cy.wait("@newComment");
cy.findByText(/censor/i).click();
cy.findByLabelText(/censor reason/i).type("censor");
cy.route("POST", "/api/v1/comments/censor").as("confirm");
cy.route("POST", "/api/comments/v1/del").as("confirm");
cy.findByText(/confirm/i).click();
cy.wait("@confirm");
cy.findByText(/ok/i).click();
Expand Down
Loading