Skip to content

Commit cae3c89

Browse files
authored
OCT-1345: Disable heart button for patrons (#17)
2 parents 86a7fba + 4049200 commit cae3c89

File tree

5 files changed

+101
-20
lines changed

5 files changed

+101
-20
lines changed

client/cypress/e2e/patronMode.cy.ts

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,8 @@
1-
import { mockCoinPricesServer, visitWithLoader } from 'cypress/utils/e2e';
1+
import { connectWallet, mockCoinPricesServer, visitWithLoader } from 'cypress/utils/e2e';
22
import viewports from 'cypress/utils/viewports';
33
import { IS_ONBOARDING_ALWAYS_VISIBLE, IS_ONBOARDING_DONE } from 'src/constants/localStorageKeys';
44
import { ROOT_ROUTES } from 'src/routes/RootRoutes/routes';
55

6-
import Chainable = Cypress.Chainable;
7-
8-
const connectWallet = (isTOSAccepted: boolean, isPatronModeEnabled: boolean): Chainable<any> => {
9-
cy.intercept('GET', '/user/*/tos', { body: { accepted: isTOSAccepted } });
10-
cy.intercept('GET', '/user/*/patron-mode', { body: { status: isPatronModeEnabled } });
11-
cy.intercept('PATCH', '/user/*/patron-mode', { body: { status: !isPatronModeEnabled } });
12-
cy.disconnectMetamaskWalletFromAllDapps();
13-
cy.get('[data-test=MainLayout__Button--connect]').click();
14-
cy.get('[data-test=ConnectWallet__BoxRounded--browserWallet]').click();
15-
cy.switchToMetamaskNotification();
16-
return cy.acceptMetamaskAccess();
17-
};
18-
196
Object.values(viewports).forEach(({ device, viewportWidth, viewportHeight, isDesktop }) => {
207
describe(`patron mode (disabled): ${device}`, { viewportHeight, viewportWidth }, () => {
218
before(() => {

client/cypress/e2e/proposal.cy.ts

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { mockCoinPricesServer, visitWithLoader } from 'cypress/utils/e2e';
1+
import { connectWallet, mockCoinPricesServer, visitWithLoader } from 'cypress/utils/e2e';
22
import { getNamesOfProposals } from 'cypress/utils/proposals';
33
import viewports from 'cypress/utils/viewports';
44
import { IS_ONBOARDING_DONE } from 'src/constants/localStorageKeys';
@@ -122,4 +122,41 @@ Object.values(viewports).forEach(({ device, viewportWidth, viewportHeight }) =>
122122
}
123123
});
124124
});
125+
126+
describe(`proposal (patron mode): ${device}`, { viewportHeight, viewportWidth }, () => {
127+
let proposalNames: string[] = [];
128+
129+
before(() => {
130+
/**
131+
* Global Metamask setup done by Synpress is not always done.
132+
* Since Synpress needs to have valid provider to fetch the data from contracts,
133+
* setupMetamask is required in each test suite.
134+
*/
135+
cy.setupMetamask();
136+
});
137+
138+
beforeEach(() => {
139+
mockCoinPricesServer();
140+
localStorage.setItem(IS_ONBOARDING_DONE, 'true');
141+
visitWithLoader(ROOT_ROUTES.proposals.absolute);
142+
connectWallet(true, true);
143+
cy.get('[data-test^=ProposalItemSkeleton').should('not.exist');
144+
145+
/**
146+
* This could be done in before hook, but CY wipes the state after each test
147+
* (could be disabled, but creates other problems)
148+
*/
149+
if (proposalNames.length === 0) {
150+
proposalNames = getNamesOfProposals();
151+
}
152+
});
153+
154+
it('button "add to allocate" is disabled', () => {
155+
for (let i = 0; i < proposalNames.length; i++) {
156+
cy.get('[data-test^=ProposalsView__ProposalsListItem]').eq(i).click();
157+
getButtonAddToAllocate().should('be.visible').should('be.disabled');
158+
cy.go('back');
159+
}
160+
});
161+
});
125162
});

client/cypress/e2e/proposals.cy.ts

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// eslint-disable-next-line import/no-extraneous-dependencies
22
import chaiColors from 'chai-colors';
33

4-
import { mockCoinPricesServer, visitWithLoader } from 'cypress/utils/e2e';
4+
import { connectWallet, mockCoinPricesServer, visitWithLoader } from 'cypress/utils/e2e';
55
import { getNamesOfProposals } from 'cypress/utils/proposals';
66
import viewports from 'cypress/utils/viewports';
77
import { IS_ONBOARDING_DONE } from 'src/constants/localStorageKeys';
@@ -11,7 +11,7 @@ import Chainable = Cypress.Chainable;
1111

1212
chai.use(chaiColors);
1313

14-
function checkProposalItemElements(index, name): Chainable<any> {
14+
function checkProposalItemElements(index, name, isPatronMode = false): Chainable<any> {
1515
cy.get('[data-test^=ProposalsView__ProposalsListItem')
1616
.eq(index)
1717
.find('[data-test=ProposalsListItem__imageProfile]')
@@ -31,6 +31,13 @@ function checkProposalItemElements(index, name): Chainable<any> {
3131
.find('[data-test=ProposalsListItem__ButtonAddToAllocate]')
3232
.should('be.visible');
3333

34+
if (isPatronMode) {
35+
cy.get('[data-test^=ProposalsView__ProposalsListItem')
36+
.eq(index)
37+
.find('[data-test=ProposalsListItem__ButtonAddToAllocate]')
38+
.should('be.disabled');
39+
}
40+
3441
return cy
3542
.get('[data-test^=ProposalsView__ProposalsListItem')
3643
.eq(index)
@@ -133,4 +140,39 @@ Object.values(viewports).forEach(({ device, viewportWidth, viewportHeight }) =>
133140
removeProposalFromAllocate(proposalNames.length, 1, proposalNames.length - 1);
134141
});
135142
});
143+
144+
describe(`proposals (patron mode): ${device}`, { viewportHeight, viewportWidth }, () => {
145+
let proposalNames: string[] = [];
146+
147+
before(() => {
148+
/**
149+
* Global Metamask setup done by Synpress is not always done.
150+
* Since Synpress needs to have valid provider to fetch the data from contracts,
151+
* setupMetamask is required in each test suite.
152+
*/
153+
cy.setupMetamask();
154+
});
155+
156+
beforeEach(() => {
157+
mockCoinPricesServer();
158+
localStorage.setItem(IS_ONBOARDING_DONE, 'true');
159+
visitWithLoader(ROOT_ROUTES.proposals.absolute);
160+
connectWallet(true, true);
161+
cy.get('[data-test^=ProposalItemSkeleton').should('not.exist');
162+
/**
163+
* This could be done in before hook, but CY wipes the state after each test
164+
* (could be disabled, but creates other problems)
165+
*/
166+
if (proposalNames.length === 0) {
167+
proposalNames = getNamesOfProposals();
168+
}
169+
});
170+
171+
it('button "add to allocate" is disabled', () => {
172+
for (let i = 0; i < proposalNames.length; i++) {
173+
cy.get('[data-test^=ProposalsView__ProposalsListItem]').eq(i).scrollIntoView();
174+
checkProposalItemElements(i, proposalNames[i], true);
175+
}
176+
});
177+
});
136178
});

client/cypress/utils/e2e.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,3 +98,17 @@ export const moveToNextEpoch = () =>
9898
// isEpochChanged
9999
resolve(Number(currentEpoch) + 1 === Number(currentEpochAfter));
100100
});
101+
102+
export const connectWallet = (
103+
isTOSAccepted: boolean,
104+
isPatronModeEnabled: boolean,
105+
): Chainable<any> => {
106+
cy.intercept('GET', '/user/*/tos', { body: { accepted: isTOSAccepted } });
107+
cy.intercept('GET', '/user/*/patron-mode', { body: { status: isPatronModeEnabled } });
108+
cy.intercept('PATCH', '/user/*/patron-mode', { body: { status: !isPatronModeEnabled } });
109+
cy.disconnectMetamaskWalletFromAllDapps();
110+
cy.get('[data-test=MainLayout__Button--connect]').click();
111+
cy.get('[data-test=ConnectWallet__BoxRounded--browserWallet]').click();
112+
cy.switchToMetamaskNotification();
113+
return cy.acceptMetamaskAccess();
114+
};

client/src/components/shared/ButtonAddToAllocate/ButtonAddToAllocate.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { useTranslation } from 'react-i18next';
66
import Button from 'components/ui/Button';
77
import Svg from 'components/ui/Svg';
88
import Tooltip from 'components/ui/Tooltip';
9+
import useIsPatronMode from 'hooks/queries/useIsPatronMode';
910
import { checkMark, heart } from 'svg/misc';
1011

1112
import styles from './ButtonAddToAllocate.module.scss';
@@ -23,9 +24,9 @@ const ButtonAddToAllocate: FC<ButtonAddToAllocateProps> = ({
2324
keyPrefix: 'components.dedicated.buttonAddToAllocate',
2425
});
2526
const [scope, animate] = useAnimate();
27+
const { data: isPatronMode } = useIsPatronMode();
2628
const [isTooltipClicked, setIsTooltipClicked] = useState(false);
2729
const [isTooltipVisible, setIsTooltipVisible] = useState(false);
28-
2930
const tooltipText = useMemo(() => {
3031
if (isAddedToAllocate && isTooltipClicked) {
3132
return t('saved');
@@ -60,7 +61,7 @@ const ButtonAddToAllocate: FC<ButtonAddToAllocateProps> = ({
6061
Icon={
6162
<Tooltip
6263
hideAfterClick
63-
isDisabled={isArchivedProposal}
64+
isDisabled={isArchivedProposal || isPatronMode}
6465
onClickCallback={() => {
6566
if (isTooltipVisible) {
6667
setIsTooltipClicked(true);
@@ -78,7 +79,7 @@ const ButtonAddToAllocate: FC<ButtonAddToAllocateProps> = ({
7879
</div>
7980
</Tooltip>
8081
}
81-
isDisabled={isArchivedProposal}
82+
isDisabled={isArchivedProposal || isPatronMode}
8283
onClick={onClick}
8384
variant="iconOnly"
8485
/>

0 commit comments

Comments
 (0)