Skip to content

Commit

Permalink
Merge branch 'stakwork:master' into admin-page
Browse files Browse the repository at this point in the history
  • Loading branch information
gouravmpk authored Feb 22, 2024
2 parents df7a9fc + 4894e47 commit 0f445c7
Show file tree
Hide file tree
Showing 91 changed files with 2,798 additions and 363 deletions.
1 change: 1 addition & 0 deletions .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ A clear and concise description of what you expected to happen.
- [ ] I have tested on Chrome desktop
- [ ] I have posted a screenshot or video in my PR
- [ ] I have rebased and tested locally before submitting my PR
- [ ] I can submit a PR within 2 days of taking the bounty

Here is an [example unit test](https://github.com/stakwork/sphinx-tribes/blob/master/frontend/app/src/helpers/__test__/helpers.spec.ts)
Here is an [example component test](https://github.com/stakwork/sphinx-tribes/blob/9310f49b3b17a51992dada932f4298eb9eba15ff/frontend/app/src/people/widgetViews/__tests__/AboutView.spec.tsx)
3 changes: 2 additions & 1 deletion .github/ISSUE_TEMPLATE/feature.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ assignees: ''
### Acceptance Criteria
- [ ] I've tested on Chrome
- [ ] I've submitted a screenshot or recording in my pr
- [ ] I've created a test that
- [ ] I've created a test that...
- [ ] I have rebased and tested locally before submitting my PR
- [ ] I can submit a pr within 2 days of taking the bounty

Here is an [example unit test](https://github.com/stakwork/sphinx-tribes/blob/master/frontend/app/src/helpers/__test__/helpers.spec.ts)

Expand Down
1 change: 1 addition & 0 deletions .github/ISSUE_TEMPLATE/test-tickets.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ assignees: ''

### Acceptance Criteria
- [ ] I have rebased and tested locally before submitting my PR
- [ ] I can submit a pr within 2 days of taking the bounty

### References
- Watch this [Jest Youtube playlist](https://www.youtube.com/watch?v=T2sv8jXoP4s&list=PLC3y8-rFHvwirqe1KHFCHJ0RqNuN61SJd) if you are new to testing
Expand Down
5 changes: 5 additions & 0 deletions cypress/support/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,12 @@ Cypress.Commands.add('create_bounty', (bounty) => {

if (bounty.estimate_session_length) {
cy.get('button[data-testid="Estimate Session Length"]').click({ force: true });
cy.get('.euiSuperSelect__listbox').should('be.visible');
cy.get('.euiSuperSelect__listbox').contains(bounty.estimate_session_length).click();
cy.get('button[data-testid="Estimate Session Length"]').should(
'contain',
bounty.estimate_session_length
);
}

if (bounty.estimate_completion_date) {
Expand Down
87 changes: 87 additions & 0 deletions src/__test__/__mockData__/bounty.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
export const mockBountyRoles = [
{ name: 'ADD BOUNTY' },
{ name: 'UPDATE BOUNTY' },
{ name: 'DELETE BOUNTY' },
{ name: 'PAY BOUNTY' },
{ name: 'VIEW REPORT' }
];
export const bountyResponse = [
{
bounty: {
id: 1384,
owner_id: 'dummy_owner_id',
paid: false,
show: true,
type: 'freelance_job_request',
award: '',
assigned_hours: 0,
bounty_expires: '',
commitment_fee: 0,
price: 250000,
title: 'Lambda Function: Extract files from a zip folder in an s3 bucket',
tribe: 'None',
assignee: 'dummy_assignee_id',
ticket_url: 'https://github.com/stakwork/stak-bounties/issues/9',
org_uuid: 'dummy_org_uuid',
description: 'dummy_description',
wanted_type: 'Web development',
deliverables: '',
github_description: true,
one_sentence_summary: '',
estimated_session_length: 'Less than 3 hours',
estimated_completion_date: '',
created: 1706907671,
updated: '2024-02-02T23:50:20.567929Z',
coding_languages: []
},
assignee: {
id: 258,
uuid: 'dummy_assignee_uuid',
owner_pubkey: 'dummy_owner_pubkey',
owner_alias: 'dummy_owner_alias',
unique_name: 'dummy_unique_name',
description: 'dummy_description',
tags: [],
img: 'https://dummy-image-url.com',
created: '2023-12-15T16:35:01.893063Z',
updated: '2024-01-31T14:32:16.852539Z',
unlisted: false,
deleted: false,
last_login: 1706562455,
owner_route_hint: 'dummy_owner_route_hint',
owner_contact_key: 'dummy_owner_contact_key',
price_to_meet: 0,
new_ticket_time: 0,
twitter_confirmed: false,
extras: null,
github_issues: null
},
owner: {
id: 190,
uuid: 'dummy_owner_uuid',
owner_pubkey: 'dummy_owner_pubkey',
owner_alias: 'dummy_owner_alias',
unique_name: 'dummy_unique_name',
description: 'dummy_description',
tags: [],
img: 'https://dummy-image-url.com',
created: '2023-09-21T22:56:59.255469Z',
updated: '2023-09-21T22:56:59.255469Z',
unlisted: false,
deleted: false,
last_login: 1706730967,
owner_route_hint: 'dummy_owner_route_hint',
owner_contact_key: 'dummy_owner_contact_key',
price_to_meet: 0,
new_ticket_time: 0,
twitter_confirmed: false,
extras: null,
github_issues: null
},
organization: {
uuid: 'dummy_org_uuid',
name: 'Dummy Organization',
img: 'https://dummy-image-url.com'
}
}
];
28 changes: 28 additions & 0 deletions src/__test__/__mockData__/organization.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { Organization } from 'store/main';

export const mockOrganizations: Organization[] = [
{
bounty_count: 0,
created: '2024-01-03T20:34:09.585609Z',
deleted: false,
id: '51',
img: '',
name: 'TEST_NEW',
owner_pubkey: '03cbb9c01cdcf91a3ac3b543a556fbec9c4c3c2a6ed753e19f2706012a26367ae3',
show: false,
updated: '2024-01-03T20:34:09.585609Z',
uuid: 'cmas9gatu2rvqiev4ur0'
},
{
bounty_count: 0,
created: '2024-01-03T20:34:09.585609Z',
deleted: false,
id: '52',
img: '',
name: 'TEST_SECOND',
owner_pubkey: '03cbb9c01cdcf91a3ac3b543a556fbec9c4c3c2a6ed753e19f2706012a26367ae3',
show: false,
updated: '2024-01-03T20:34:09.585609Z',
uuid: 'cmas9gatu2rvqiev4ur0'
}
];
2 changes: 2 additions & 0 deletions src/__test__/__mockData__/persons.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export const people: Person[] = [
},
owner_alias: 'Vladimir',
owner_pubkey: 'test_pub_key',
uuid: '23334444',
unique_name: 'vladimir',
tags: [],
img: '',
Expand All @@ -42,6 +43,7 @@ export const people: Person[] = [
},
owner_alias: 'Raphael',
owner_pubkey: 'test_pub_key_2',
uuid: '23334434',
unique_name: 'raphael',
tags: [],
img: '',
Expand Down
42 changes: 42 additions & 0 deletions src/__test__/__mockStore__/MockStoreEnvironment.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import React from 'react';
import { ThemeProvider, createTheme } from '@mui/system';
import { Router } from 'react-router-dom';
import history from '../../config/history';
import { withProviders } from '../../providers';
import { MOCK_ENVIRONMENT_HOOKS } from './constants';
import { useMockBountyData } from './useMockBountyData';
import { useMockBountyRoleData } from './useMockBountyRoleData';
import { useMockDropdownOrganizationData } from './useMockDropdownOrganizationData';
import { useMockOrganizationsData } from './useMockOrganizationsData';
import { useMockUsdToSatExchangeRate } from './useMockUsdToSatExchangeRate';
import { useMockSelfProfileStore } from './useMockSelfProfileStore';

export function MockStoreEnvironment({
children,
hooks = []
}: {
children: React.ReactNode;
hooks: MOCK_ENVIRONMENT_HOOKS[];
}) {
const theme = createTheme({
spacing: 8
});
useMockBountyData({ enabled: hooks.includes(MOCK_ENVIRONMENT_HOOKS.BOUNTY_DATA) });
useMockBountyRoleData({ enabled: hooks.includes(MOCK_ENVIRONMENT_HOOKS.BOUNTY_ROES) });
useMockDropdownOrganizationData({
enabled: hooks.includes(MOCK_ENVIRONMENT_HOOKS.DROPDOWN_ORGANIZATION_DATA)
});
useMockOrganizationsData({ enabled: hooks.includes(MOCK_ENVIRONMENT_HOOKS.ORGANIZATION_DATA) });
useMockUsdToSatExchangeRate({
enabled: hooks.includes(MOCK_ENVIRONMENT_HOOKS.USD_TO_SAT_EXCHANGE_RATE)
});
useMockSelfProfileStore({ enabled: hooks.includes(MOCK_ENVIRONMENT_HOOKS.SELF_PROFILE_STORE) });

return (
<ThemeProvider theme={theme}>
<Router history={history}>{children}</Router>
</ThemeProvider>
);
}

export default withProviders(MockStoreEnvironment);
9 changes: 9 additions & 0 deletions src/__test__/__mockStore__/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/* eslint-disable no-unused-vars */
export enum MOCK_ENVIRONMENT_HOOKS {
BOUNTY_DATA = 'BOUNTY_DATA',
BOUNTY_ROES = 'BOUNTY_ROES',
DROPDOWN_ORGANIZATION_DATA = 'DROPDOWN_ORGANIZATION_DATA',
ORGANIZATION_DATA = 'ORGANIZATION_DATA',
SELF_PROFILE_STORE = 'SELF_PROFILE_STORE',
USD_TO_SAT_EXCHANGE_RATE = 'USD_TO_SAT_EXCHANGE_RATE'
}
14 changes: 14 additions & 0 deletions src/__test__/__mockStore__/useMockBountyData.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { bountyResponse } from '__test__/__mockData__/bounty';
import { useEffect } from 'react';
import { useStores } from 'store';
import { transformBountyWithPeopleBounty } from 'store/__test__/util';

export const useMockBountyData = ({ enabled }: { enabled: boolean }) => {
const { main } = useStores();
useEffect(() => {
if (enabled) {
// TODO: should write proper types once its when proper are written or people bounty
main.setPeopleBounties([transformBountyWithPeopleBounty(bountyResponse[0])] as any);
}
}, [main, enabled]);
};
12 changes: 12 additions & 0 deletions src/__test__/__mockStore__/useMockBountyRoleData.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { mockBountyRoles } from '__test__/__mockData__/bounty';
import { useEffect } from 'react';
import { useStores } from 'store';

export const useMockBountyRoleData = ({ enabled }: { enabled: boolean }) => {
const { main } = useStores();
useEffect(() => {
if (enabled) {
main.setBountyRoles(mockBountyRoles);
}
}, [main, enabled]);
};
19 changes: 19 additions & 0 deletions src/__test__/__mockStore__/useMockDropdownOrganizationData.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { mockOrganizations } from '__test__/__mockData__/organization';
import { useEffect } from 'react';
import { useStores } from 'store';

// This hook will populate the store with mock data for the dropdownOrganizations slice
export const useMockDropdownOrganizationData = ({
personId,
enabled
}: {
personId?: string;
enabled: boolean;
}) => {
const { main } = useStores();
useEffect(() => {
if (enabled) {
main.setDropdownOrganizations(mockOrganizations);
}
}, [main, personId, enabled]);
};
13 changes: 13 additions & 0 deletions src/__test__/__mockStore__/useMockOrganizationsData.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { mockOrganizations } from '__test__/__mockData__/organization';
import { useEffect } from 'react';
import { useStores } from 'store';

// This hook will populate the store with mock data for the organization slice
export const useMockOrganizationsData = ({ enabled }: { enabled: boolean }) => {
const { main } = useStores();
useEffect(() => {
if (enabled) {
main.setOrganizations(mockOrganizations);
}
}, [main, enabled]);
};
21 changes: 21 additions & 0 deletions src/__test__/__mockStore__/useMockSelfProfileStore.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { user } from '__test__/__mockData__/user';
import { useEffect } from 'react';
import { useStores } from 'store';
import { Person } from 'store/main';

export const useMockSelfProfileStore = ({ enabled }: { enabled: boolean }) => {
const { ui, main } = useStores();

useEffect(() => {
if (enabled) {
ui.setMeInfo(user);
ui.setSelectedPerson(user.id);
const person = {
...user,
unique_name: Math.random().toString(36).substring(7),
tags: []
} as Person;
main.setActivePerson(person);
}
}, [main, ui, enabled]);
};
34 changes: 34 additions & 0 deletions src/__test__/__mockStore__/useMockUsdToSatExchangeRate.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { useEffect } from 'react';
import { useStores } from 'store';

export const useMockUsdToSatExchangeRate = ({
time = 100000,
enabled
}: {
time?: number;
enabled: boolean;
}) => {
const { ui } = useStores();

useEffect(() => {
if (enabled) {
const getUsdToSatsExchangeRate = () => {
// random rate for 1 usd
const rate = Math.random() || 1;

// 1 bitcoin is 1 million satoshis
const satoshisInABitcoin = 0.00000001;
ui.setUsdToSatsExchangeRate(rate / satoshisInABitcoin);
};

getUsdToSatsExchangeRate();
const timer = setInterval(() => {
getUsdToSatsExchangeRate();
}, time);

return () => {
clearInterval(timer);
};
}
}, [time, ui, enabled]);
};
10 changes: 5 additions & 5 deletions src/bounties/BountyProfileView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ const BountyProfileView = (props: BountiesProfileProps) => {
width={'100%'}
height={'100%'}
style={{ objectFit: 'cover' }}
src={props.assignee.img || main.getUserAvatarPlaceholder(props.assignee.owner_pubkey)}
src={props.assignee?.img || main.getUserAvatarPlaceholder(props.assignee?.owner_pubkey)}
alt={'assigned_person'}
/>
</UserImage>
Expand Down Expand Up @@ -166,8 +166,8 @@ const BountyProfileView = (props: BountiesProfileProps) => {
`/p/${
{
...props.assignee
}.owner_pubkey
}?widget=wanted`,
}.uuid
}?widget=bounties`,
'_blank'
);
}
Expand All @@ -188,8 +188,8 @@ const BountyProfileView = (props: BountiesProfileProps) => {
`/p/${
{
...props.assignee
}.owner_pubkey
}?widget=wanted`,
}.uuid
}?widget=bounties`,
'_blank'
);
}
Expand Down
Loading

0 comments on commit 0f445c7

Please sign in to comment.