diff --git a/astro_2.0/components/AppHeader/components/SearchBar/components/DropdownResults/DropdownResults.tsx b/astro_2.0/components/AppHeader/components/SearchBar/components/DropdownResults/DropdownResults.tsx index 61ced3aaf..376e096a0 100644 --- a/astro_2.0/components/AppHeader/components/SearchBar/components/DropdownResults/DropdownResults.tsx +++ b/astro_2.0/components/AppHeader/components/SearchBar/components/DropdownResults/DropdownResults.tsx @@ -7,7 +7,7 @@ import { useAuthContext } from 'context/AuthContext'; import { SEARCH_PAGE_URL } from 'constants/routing'; import { useSearchResults } from 'features/search/search-results'; -import { NoSearchResultsView } from 'features/search/search-results/components/no-search-results-view'; +import { NoSearchResultsView } from 'features/search/search-results/components/NoSearchResultsView'; import { ResultSection, diff --git a/astro_2.0/components/AppHeader/components/SearchBar/components/DropdownResults/tests/__snapshots__/DropdownResults.spec.tsx.snap b/astro_2.0/components/AppHeader/components/SearchBar/components/DropdownResults/tests/__snapshots__/DropdownResults.spec.tsx.snap index 46d7658bd..825d4a424 100644 --- a/astro_2.0/components/AppHeader/components/SearchBar/components/DropdownResults/tests/__snapshots__/DropdownResults.spec.tsx.snap +++ b/astro_2.0/components/AppHeader/components/SearchBar/components/DropdownResults/tests/__snapshots__/DropdownResults.spec.tsx.snap @@ -12,7 +12,7 @@ exports[`search results dropdown Should render component 1`] = ` class="" />
- No results + No results for asd
We couldn't find anything matching your search. Try again with a different term. diff --git a/features/proposal/components/voter-details-card/voter-details-card.module.scss b/features/proposal/components/VoterDetailsCard/VoterDetailsCard.module.scss similarity index 100% rename from features/proposal/components/voter-details-card/voter-details-card.module.scss rename to features/proposal/components/VoterDetailsCard/VoterDetailsCard.module.scss diff --git a/features/proposal/components/voter-details-card/VoterDetailsCard.tsx b/features/proposal/components/VoterDetailsCard/VoterDetailsCard.tsx similarity index 97% rename from features/proposal/components/voter-details-card/VoterDetailsCard.tsx rename to features/proposal/components/VoterDetailsCard/VoterDetailsCard.tsx index 955184a34..56c01c23e 100644 --- a/features/proposal/components/voter-details-card/VoterDetailsCard.tsx +++ b/features/proposal/components/VoterDetailsCard/VoterDetailsCard.tsx @@ -8,7 +8,7 @@ import { ExplorerLink } from 'components/ExplorerLink'; import { Vote } from 'features/types'; import { formatTimestampAsDate } from 'utils/format'; -import styles from './voter-details-card.module.scss'; +import styles from './VoterDetailsCard.module.scss'; const GroupsRenderer = dynamic( import('components/cards/member-card/GroupsRenderer'), diff --git a/features/proposal/components/voter-details-card/index.ts b/features/proposal/components/VoterDetailsCard/index.ts similarity index 100% rename from features/proposal/components/voter-details-card/index.ts rename to features/proposal/components/VoterDetailsCard/index.ts diff --git a/features/proposal/components/VoterDetailsCard/tests/VoterDetailsCard.spec.tsx b/features/proposal/components/VoterDetailsCard/tests/VoterDetailsCard.spec.tsx new file mode 100644 index 000000000..4143dfcc3 --- /dev/null +++ b/features/proposal/components/VoterDetailsCard/tests/VoterDetailsCard.spec.tsx @@ -0,0 +1,47 @@ +import { render } from 'jest/testUtils'; + +import { VoterDetailsCard } from 'features/proposal/components/VoterDetailsCard'; + +jest.mock('components/Icon', () => { + return { + Icon: ({ name }: { name: string }) =>
{name}
, + }; +}); + +describe('VoterDetailsCard', () => { + // it('Should render component', () => { + // const name = 'Hello World!'; + // + // const { getByText } = render( + // + // ); + // + // expect(getByText(name)).toBeInTheDocument(); + // }); + + it.each` + vote | icon + ${'Yes'} | ${'votingYes'} + ${'No'} | ${'votingNo'} + ${'Dismiss'} | ${'votingDismissAlt'} + ${'Other'} | ${'notVoted'} + `('Should render proper icon for $vote vote', ({ vote, icon }) => { + const { getByText } = render( + + ); + + expect(getByText(icon)).toBeInTheDocument(); + }); +}); diff --git a/features/proposal/components/voters-list/voters-list.module.scss b/features/proposal/components/VotersList/VotersList.module.scss similarity index 100% rename from features/proposal/components/voters-list/voters-list.module.scss rename to features/proposal/components/VotersList/VotersList.module.scss diff --git a/features/proposal/components/voters-list/VotersList.tsx b/features/proposal/components/VotersList/VotersList.tsx similarity index 84% rename from features/proposal/components/voters-list/VotersList.tsx rename to features/proposal/components/VotersList/VotersList.tsx index 511e7ed54..89cc7e4e6 100644 --- a/features/proposal/components/voters-list/VotersList.tsx +++ b/features/proposal/components/VotersList/VotersList.tsx @@ -1,9 +1,9 @@ import React, { FC } from 'react'; import { VoterDetail } from 'features/types'; -import { VoterDetailsCard } from 'features/proposal/components/voter-details-card'; +import { VoterDetailsCard } from 'features/proposal/components/VoterDetailsCard'; import { NoResultsView } from 'astro_2.0/components/NoResultsView'; -import styles from './voters-list.module.scss'; +import styles from './VotersList.module.scss'; interface VotersListProps { data: VoterDetail[]; diff --git a/features/proposal/components/voters-list/index.ts b/features/proposal/components/VotersList/index.ts similarity index 100% rename from features/proposal/components/voters-list/index.ts rename to features/proposal/components/VotersList/index.ts diff --git a/features/proposal/components/VotersList/tests/VotersList.spec.tsx b/features/proposal/components/VotersList/tests/VotersList.spec.tsx new file mode 100644 index 000000000..e8be5f4d1 --- /dev/null +++ b/features/proposal/components/VotersList/tests/VotersList.spec.tsx @@ -0,0 +1,31 @@ +import { render } from 'jest/testUtils'; + +import { VoterDetail } from 'features/types'; + +import { VotersList } from 'features/proposal/components/VotersList'; + +describe('VotersList', () => { + it('Should render "No data" state', () => { + const { getByText } = render(); + + expect(getByText('No votes here')).toBeInTheDocument(); + }); + + it('Should render component', () => { + const data = [ + { + name: 'N1', + vote: 'Yes', + }, + { + name: 'N2', + vote: 'No', + }, + ] as VoterDetail[]; + + const { getByText } = render(); + + expect(getByText('N1')).toBeInTheDocument(); + expect(getByText('N2')).toBeInTheDocument(); + }); +}); diff --git a/features/search/search-results/components/members-tab-view/members-tab-view.module.scss b/features/search/search-results/components/MembersTabView/MembersTabView.module.scss similarity index 100% rename from features/search/search-results/components/members-tab-view/members-tab-view.module.scss rename to features/search/search-results/components/MembersTabView/MembersTabView.module.scss diff --git a/features/search/search-results/components/members-tab-view/MembersTabView.tsx b/features/search/search-results/components/MembersTabView/MembersTabView.tsx similarity index 93% rename from features/search/search-results/components/members-tab-view/MembersTabView.tsx rename to features/search/search-results/components/MembersTabView/MembersTabView.tsx index c57f7cf34..7e3782a37 100644 --- a/features/search/search-results/components/members-tab-view/MembersTabView.tsx +++ b/features/search/search-results/components/MembersTabView/MembersTabView.tsx @@ -1,3 +1,4 @@ +import isEmpty from 'lodash/isEmpty'; import React, { FC, useCallback } from 'react'; import { NoResultsView } from 'astro_2.0/components/NoResultsView'; @@ -11,7 +12,7 @@ import { useModal } from 'components/modal'; import { GROUP_COLOR } from './constants'; -import styles from './members-tab-view.module.scss'; +import styles from './MembersTabView.module.scss'; export const MembersTabView: FC = () => { const { searchResults } = useSearchResults(); @@ -24,7 +25,7 @@ export const MembersTabView: FC = () => { [showCardModal] ); - if ((searchResults?.members || []).length === 0) { + if (isEmpty(searchResults?.members)) { return ( { + return ({ text }: { text: string }) =>
{text}
; +}); + +jest.mock('components/modal', () => { + return { + useModal: jest.fn(() => []), + }; +}); + +jest.mock('features/search/search-results/SearchResults', () => { + return { + useSearchResults: jest.fn(() => ({})), + }; +}); + +describe('MembersTabView', () => { + it('Should "No Data" state', () => { + const { getByText } = render(); + + expect( + getByText("We couldn't find anything matching your search.", { + exact: false, + }) + ).toBeInTheDocument(); + }); + + it('Should render component', () => { + const name = 'My Name Is'; + + // @ts-ignore + useSearchResults.mockImplementation(() => ({ + searchResults: { + members: [ + { + id: 'N1', + name, + groups: ['MEW holders'], + votes: 0, + }, + ], + }, + })); + + const { getByText } = render(); + + expect(getByText(name)).toBeInTheDocument(); + }); + + it('Should show modal', () => { + const showModal = jest.fn(); + + // @ts-ignore + useModal.mockImplementation(() => [showModal]); + + // @ts-ignore + useSearchResults.mockImplementation(() => ({ + searchResults: { + members: [ + { + id: 'N1', + name: 'N1', + groups: ['MEW holders'], + votes: 0, + }, + ], + }, + })); + + const { getAllByRole } = render(); + + fireEvent.click(getAllByRole('button')[0]); + + expect(showModal).toBeCalled(); + }); +}); diff --git a/features/search/search-results/components/no-search-results-view/NoSearchResultsView.module.scss b/features/search/search-results/components/NoSearchResultsView/NoSearchResultsView.module.scss similarity index 100% rename from features/search/search-results/components/no-search-results-view/NoSearchResultsView.module.scss rename to features/search/search-results/components/NoSearchResultsView/NoSearchResultsView.module.scss diff --git a/features/search/search-results/components/no-search-results-view/NoSearchResultsView.tsx b/features/search/search-results/components/NoSearchResultsView/NoSearchResultsView.tsx similarity index 89% rename from features/search/search-results/components/no-search-results-view/NoSearchResultsView.tsx rename to features/search/search-results/components/NoSearchResultsView/NoSearchResultsView.tsx index 2de0eea7b..221f4d1c6 100644 --- a/features/search/search-results/components/no-search-results-view/NoSearchResultsView.tsx +++ b/features/search/search-results/components/NoSearchResultsView/NoSearchResultsView.tsx @@ -11,7 +11,7 @@ interface NoSearchResultsViewProps { export const NoSearchResultsView: FC = ({ query, }) => { - const title = query ? 'No results' : `No results for ${query}`; + const title = query ? `No results for ${query}` : 'No results'; return ( { + it('Should render "No results"', () => { + const { getByText } = render(); + + expect(getByText('No results')).toBeInTheDocument(); + }); + + it('Should render "No results" with query', () => { + const query = 'Hello World!'; + + const { getByText } = render(); + + expect(getByText(`No results for ${query}`)).toBeInTheDocument(); + }); +}); diff --git a/features/search/search-results/components/search-results-renderer/SearchResultsRenderer.tsx b/features/search/search-results/components/search-results-renderer/SearchResultsRenderer.tsx index 2649cd5ed..457a33d6c 100644 --- a/features/search/search-results/components/search-results-renderer/SearchResultsRenderer.tsx +++ b/features/search/search-results/components/search-results-renderer/SearchResultsRenderer.tsx @@ -4,7 +4,7 @@ import { Tabs } from 'components/Tabs'; import { useSearchResults } from 'features/search/search-results/SearchResults'; import { DaosTabView } from 'features/search/search-results/components/daos-tab-view'; import { ProposalsTabView } from 'features/search/search-results/components/proposals-tab-view'; -import { MembersTabView } from 'features/search/search-results/components/members-tab-view'; +import { MembersTabView } from 'features/search/search-results/components/MembersTabView'; import styles from './search-results-renderer.module.scss'; diff --git a/pages/dao/[dao]/proposals/[proposal]/ProposalPage.tsx b/pages/dao/[dao]/proposals/[proposal]/ProposalPage.tsx index 7982e601a..021935c3f 100644 --- a/pages/dao/[dao]/proposals/[proposal]/ProposalPage.tsx +++ b/pages/dao/[dao]/proposals/[proposal]/ProposalPage.tsx @@ -15,7 +15,7 @@ import { getProposalScope } from 'utils/getProposalScope'; import { getVoteDetails } from 'features/vote-policy/helpers'; import { NestedDaoPageWrapper } from 'astro_2.0/features/pages/nestedDaoPagesContent/NestedDaoPageWrapper'; -import { VotersList } from 'features/proposal/components/voters-list'; +import { VotersList } from 'features/proposal/components/VotersList'; import { useGetBreadcrumbsConfig } from 'hooks/useGetBreadcrumbsConfig'; import { useDaoCustomTokens } from 'hooks/useCustomTokens';