Skip to content

Commit

Permalink
Merge pull request #66 from cardano-foundation/feat/add-tests-placeho…
Browse files Browse the repository at this point in the history
…lders

feat(cip-1694): add tests placeholders
  • Loading branch information
kickloop authored Aug 21, 2023
2 parents d949023 + b69fc5d commit 246fdf5
Show file tree
Hide file tree
Showing 34 changed files with 117 additions and 412 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,10 @@ e.g.
SERVER_PORT=8888 ./gradlew bootRun
```

use `setupProxy.js` to proxy services urls

```shell
npm i
npm run start
```

Expand Down
9 changes: 0 additions & 9 deletions ui/cip-1694/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion ui/cip-1694/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
"history": "^5.3.0",
"json-canonicalize": "^1.0.6",
"moment": "^2.29.4",
"qr-code-styling": "^1.6.0-rc.1",
"react": "^18.2.0",
"react-copy-to-clipboard": "^5.1.0",
"react-dom": "^18.2.0",
Expand Down Expand Up @@ -79,6 +78,7 @@
"start": "react-scripts start",
"build": "REACT_APP_SERVER_URL= REACT_APP_TARGET_NETWORK= REACT_APP_EVENT_ID= REACT_APP_CATEGORY_ID= REACT_APP_SUPPORTED_WALLETS= npx react-inject-env build react-scripts build",
"jest-test": "jest --config ./jest.config.js",
"jest-test:coverage": "jest --config ./jest.config.js --collect-coverage",
"eject": "react-scripts eject",
"cypress:open": "cypress open",
"cypress:run": "cypress run",
Expand Down
4 changes: 4 additions & 0 deletions ui/cip-1694/src/App.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
describe('App:', () => {
test.todo('should render proper state');
test.todo('should fetch an event');
});
4 changes: 3 additions & 1 deletion ui/cip-1694/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ export const App = () => {
const event = await referenceDataService.getEvent(env.EVENT_ID);
dispatch(setEventData({ event }));
} catch (error) {
console.log(`Failed to fetch event, ${error?.info || error?.message || error?.toString()}`);
if (process.env.NODE_ENV === 'development') {
console.log(`Failed to fetch event, ${error?.info || error?.message || error?.toString()}`);
}
toast(
<Toast
message="Failed to fetch event"
Expand Down
6 changes: 6 additions & 0 deletions ui/cip-1694/src/common/api/__tests__/api.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
describe('Testing services:', () => {
test.todo('Leaderboard service');
test.todo('Reference service');
test.todo('Verification service');
test.todo('Vote service');
});
3 changes: 0 additions & 3 deletions ui/cip-1694/src/common/constants/localConstants.ts

This file was deleted.

6 changes: 6 additions & 0 deletions ui/cip-1694/src/common/handlers/__tests__/httpHandler.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
describe('Testing handlers:', () => {
test.todo('get');
test.todo('put');
test.todo('post');
test.todo('delete');
});
3 changes: 3 additions & 0 deletions ui/cip-1694/src/common/hooks/__tests__/useToggle.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
describe('useToggle:', () => {
test.todo('should toggle');
});
3 changes: 3 additions & 0 deletions ui/cip-1694/src/common/routes/__tests__/routes.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
describe('routes: ', () => {
test.todo('should render all routes');
});
6 changes: 3 additions & 3 deletions ui/cip-1694/src/common/routes/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import { Leaderboard } from 'pages/Leaderboard/Leaderboard';
export const PAGE_PATH = '/';

export const ROUTES = {
INTRO: `${PAGE_PATH}`,
VOTE: '/vote',
LEADERBOARD: '/leaderboard',
INTRO: PAGE_PATH,
VOTE: `${PAGE_PATH}vote`,
LEADERBOARD: `${PAGE_PATH}leaderboard`,
};

export const PageRoutes = () => (
Expand Down
3 changes: 3 additions & 0 deletions ui/cip-1694/src/common/store/__tests__/userSlice.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
describe('userSlice: ', () => {
test.todo('should render all routes');
});
1 change: 0 additions & 1 deletion ui/cip-1694/src/common/store/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { VoteReceipt, EventReference } from 'types/backend-services-types';
export interface UserState {
isConnectWalletModalVisible: boolean;
isVoteSubmittedModalVisible: boolean;
isVerifyVoteModalVisible: boolean;
connectedWallet: string;
isReceiptFetched: boolean;
receipt: VoteReceipt | null;
Expand Down
5 changes: 0 additions & 5 deletions ui/cip-1694/src/common/store/userSlice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { UserState } from './types';
const initialState: UserState = {
isConnectWalletModalVisible: false,
isVoteSubmittedModalVisible: false,
isVerifyVoteModalVisible: false,
connectedWallet: '',
isReceiptFetched: false,
receipt: null,
Expand All @@ -33,9 +32,6 @@ export const userSlice = createSlice({
setIsReceiptFetched: (state, action: PayloadAction<{ isFetched: boolean }>) => {
state.isReceiptFetched = action.payload.isFetched;
},
setIsVerifyVoteModalVisible: (state, action: PayloadAction<{ isVisible: boolean }>) => {
state.isVerifyVoteModalVisible = action.payload.isVisible;
},
setSelectedProposal: (state, action: PayloadAction<{ proposal: VoteReceipt['proposal'] }>) => {
state.proposal = action.payload.proposal;
},
Expand All @@ -51,7 +47,6 @@ export const {
setConnectedWallet,
setVoteReceipt,
setIsReceiptFetched,
setIsVerifyVoteModalVisible,
setSelectedProposal,
setEventData,
} = userSlice.actions;
Expand Down
5 changes: 5 additions & 0 deletions ui/cip-1694/src/common/utils/__tests__/voteUtils.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
describe('voteUtils: ', () => {
test.todo('should test buildCanonicalVoteInputJson');
test.todo('should test buildCanonicalVoteReceiptInputJson');
test.todo('should test getSignedMessagePromise');
});
14 changes: 0 additions & 14 deletions ui/cip-1694/src/common/utils/sessionUtils.ts

This file was deleted.

3 changes: 2 additions & 1 deletion ui/cip-1694/src/common/utils/voteUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export const buildCanonicalVoteInputJson = ({
const startOfCurrentDay = new Date();
startOfCurrentDay.setUTCMinutes(0, 0, 0);
return canonicalize({
// TOOD: move to const/env file/ config file, also the link seems to be broken
// TODO: should this one be hardcoded?
uri: 'https://evoting.cardano.org/voltaire',
action: 'CAST_VOTE',
actionText: 'Cast Vote',
Expand Down Expand Up @@ -49,6 +49,7 @@ export const buildCanonicalVoteReceiptInputJson = ({
slotNumber,
}: votereceiptInput): ReturnType<typeof canonicalize> =>
canonicalize({
// TODO: should this one be hardcoded?
uri: 'https://evoting.cardano.org/voltaire',
action: 'VIEW_VOTE_RECEIPT',
actionText: 'View Vote Receipt',
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
describe('VoteSubmittedModal:', () => {
test.todo('should render proper state');
});
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ describe('ConnectWalletModal', () => {
cleanup();
});

test.todo('PageRoutes');

test('should display proper state for connect wallet modal, properly react to wallet on connect error scenario', async () => {
mockConnectWalletList.mockImplementation(() => {
return <span data-testid="connect-wallet-list" />;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
describe('MobileModal:', () => {
test.todo('should render proper state');
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
describe('SidePage:', () => {
test.todo('should render side drawer');
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
describe('Toast:', () => {
test.todo('should render proper state');
});
7 changes: 0 additions & 7 deletions ui/cip-1694/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { createRoot } from 'react-dom/client';
import { BrowserRouter as Router } from 'react-router-dom';
import { Provider } from 'react-redux';
import { ThemeProvider } from '@mui/material/styles';
import reportWebVitals from './reportWebVitals';
import { App } from './App';
import theme from './common/styles/theme';
import { setupStore } from './common/store/index';
Expand All @@ -21,9 +20,3 @@ root.render(
</ThemeProvider>
</Provider>
);

// If you want to start measuring performance in your app, pass a function
// to log results (for example: reportWebVitals(console.log))
// or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals
// TODO: do wee need this in production build
reportWebVitals();
5 changes: 4 additions & 1 deletion ui/cip-1694/src/pages/Leaderboard/Leaderboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export const Leaderboard = () => {
const eventHasntStarted = !event?.active && !event?.finished;
const [stats, setStats] = useState<ByCategory['proposals']>();

// page should not be accessible in case the wallet is not connected, or the event is not finished yet
useEffect(() => {
if (!isConnected || eventHasntStarted || !event?.finished) navigate(ROUTES.INTRO);
}, [event?.finished, eventHasntStarted, isConnected, navigate]);
Expand All @@ -34,7 +35,9 @@ export const Leaderboard = () => {
setStats((await leaderboardService.getStats())?.proposals);
} catch (error) {
const message = `Failed to fecth stats: ${error?.message || error?.toString()}`;
console.log(message);
if (process.env.NODE_ENV === 'development') {
console.log(message);
}
toast(
<Toast
message="Failed to fecth stats"
Expand Down
40 changes: 19 additions & 21 deletions ui/cip-1694/src/pages/Vote/Vote.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import { EventTime } from 'components/EventTime/EventTime';
import {
setIsConnectWalletModalVisible,
setIsReceiptFetched,
setIsVerifyVoteModalVisible,
setIsVoteSubmittedModalVisible,
setSelectedProposal,
setVoteReceipt,
Expand All @@ -39,7 +38,6 @@ import * as voteService from 'common/api/voteService';
import { useToggle } from 'common/hooks/useToggle';
import { HttpError } from 'common/handlers/httpHandler';
import { env } from '../../env';
import { VerifyVoteModal } from './components/VerifyVote/VerifyVote';
import styles from './Vote.module.scss';

const errorsMap = {
Expand All @@ -61,7 +59,6 @@ export const VotePage = () => {
const eventHasntStarted = !event?.active && !event?.finished;
const isReceiptFetched = useSelector((state: RootState) => state.user.isReceiptFetched);
const isVoteSubmittedModalVisible = useSelector((state: RootState) => state.user.isVoteSubmittedModalVisible);
const isVerifyVoteModalVisible = useSelector((state: RootState) => state.user.isVerifyVoteModalVisible);
const [absoluteSlot, setAbsoluteSlot] = useState<number>();
const savedProposal = useSelector((state: RootState) => state.user.proposal);
const [optionId, setOptionId] = useState(savedProposal || '');
Expand Down Expand Up @@ -97,7 +94,9 @@ export const VotePage = () => {
dispatch(setSelectedProposal({ proposal: receiptResponse.proposal }));
} else {
const message = `${errorPrefix}', ${receiptResponse?.title}, ${receiptResponse?.detail}`;
console.log(message);
if (process.env.NODE_ENV === 'development') {
console.log(message);
}
toast(
<Toast
message={errorPrefix}
Expand All @@ -122,7 +121,9 @@ export const VotePage = () => {
icon={<BlockIcon style={{ fontSize: '19px', color: '#F5F9FF' }} />}
/>
);
console.log(message);
if (process.env.NODE_ENV === 'development') {
console.log(message);
}
}
},
[absoluteSlot, dispatch, signMessagePromisified, stakeAddress]
Expand All @@ -137,7 +138,9 @@ export const VotePage = () => {
setAbsoluteSlot((await voteService.getSlotNumber())?.absoluteSlot);
} catch (error) {
const message = `Failed to fecth slot number: ${error?.message}`;
console.log(message);
if (process.env.NODE_ENV === 'development') {
console.log(message);
}
toast(
<Toast
message="Failed to fecth slot number"
Expand All @@ -154,6 +157,7 @@ export const VotePage = () => {
}
}, [init, isConnected]);

// fetch vote receipt if there is no saved selection and event is active or finished
useEffect(() => {
if (absoluteSlot && !savedProposal && !eventHasntStarted) {
fetchReceipt({});
Expand All @@ -167,10 +171,6 @@ export const VotePage = () => {

const handleSubmit = async () => {
if (!isConnected) return;
if (!env.EVENT_ID) {
console.log('EVENT_ID is not provided');
return;
}

let votingPower: Account['votingPower'];
try {
Expand All @@ -180,7 +180,9 @@ export const VotePage = () => {
error instanceof Error || error instanceof HttpError ? error?.message : error
}`;

console.log(message);
if (process.env.NODE_ENV === 'development') {
console.log(message);
}
toast(
<Toast
error
Expand Down Expand Up @@ -214,7 +216,9 @@ export const VotePage = () => {
/>
);
setOptionId('');
console.log('Failed to cast e vote', errorsMap[error?.message as keyof typeof errorsMap] || error?.message);
if (process.env.NODE_ENV === 'development') {
console.log('Failed to cast e vote', errorsMap[error?.message as keyof typeof errorsMap] || error?.message);
}
} else if (error instanceof Error) {
toast(
<Toast
Expand All @@ -223,7 +227,9 @@ export const VotePage = () => {
icon={<BlockIcon style={{ fontSize: '19px', color: '#F5F9FF' }} />}
/>
);
console.log('Failed to cast e vote', error?.message || error.toString());
if (process.env.NODE_ENV === 'development') {
console.log('Failed to cast e vote', error?.message || error.toString());
}
}
}
};
Expand Down Expand Up @@ -399,14 +405,6 @@ export const VotePage = () => {
</>
}
/>
<VerifyVoteModal
openStatus={isVerifyVoteModalVisible}
onCloseFn={() => {
dispatch(setIsVerifyVoteModalVisible({ isVisible: false }));
}}
name="vote-verify-modal"
id="vote-verify-modal"
/>
</>
);
};

This file was deleted.

Loading

0 comments on commit 246fdf5

Please sign in to comment.