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

Refactor: move capture page to /captures #1804

Merged
merged 7 commits into from
Nov 11, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added cypress/fixtures/images/capture.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
32 changes: 32 additions & 0 deletions cypress/tests/integration/captures/[captureid].cy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import capture from '../../../fixtures/capture.json';

beforeEach(() => {
if (Cypress.env('nock')) {
cy.task('clearNock');
}
});

it('getStaticProps returns mock data for capture', () => {
const path = `/captures/${capture.id}`;

if (Cypress.env('nock')) {
cy.task('nock', {
hostname: Cypress.env('NEXT_PUBLIC_API'),
method: 'GET',
path: `/query/v2/captures/${capture.id}`,
statusCode: 200,
body: capture,
});
}

cy.visit(path);

// Assertions
cy.contains(`Capture #${capture.id}`);
cy.contains(capture.species_name || 'Unknown Species');
cy.contains(
`Captured on ${new Date(capture.created_at).toLocaleDateString()}`,
);
cy.contains(capture.token_id ? 'Token issued' : 'Token not issued');
cy.contains(capture.wallet_name || 'No wallet owns it');
});
2 changes: 1 addition & 1 deletion src/components/FeaturedTreesSlider/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ function FeaturedTreesSlider({ trees, size = null, isMobile, link }) {
>
{trees.map((tree) => (
<Link
href={link ? link(tree) : `/v2/captures/${tree.id}`}
href={link ? link(tree) : `/captures/${tree.id}`}
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dadiorchen this is what you're looking for?
cypress integration test is not added yet. just checking if i'm on the right path.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@yunchipang yes, and to finish this, we also need a integration test for this: /capture page

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add it?

key={`featured-tree-${tree.id}`}
>
<Card
Expand Down
14 changes: 8 additions & 6 deletions src/components/TreeInfoDialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -274,14 +274,16 @@ export default function TreeInfoDialog(props) {
<List>
<ListItem sx={{ pl: 0 }}>
<CustomListAvatar
src={grower.image_url}
alt={getGrowerName(grower.first_name, grower.last_name)}
src={grower?.image_url || imagePlaceholder} // provide a fallback image if image_url is missing
alt={getGrowerName(
grower?.first_name || 'Unknown',
grower?.last_name || '',
)}
/>
<CustomListText
primary="Grower"
secondary={getGrowerName(
grower.first_name,
grower.last_name,
primary={getGrowerName(
grower?.first_name || 'Unknown',
grower?.last_name || '',
)}
/>
</ListItem>
Expand Down
1 change: 1 addition & 0 deletions src/models/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ export async function getTreeById(id) {
throw err;
}
}

export async function getCapturesById(id) {
try {
const url = apiPaths.captures(id);
Expand Down
18 changes: 9 additions & 9 deletions src/models/pathResolver.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,27 +104,27 @@ function getContext(router, options = {}) {
const matchV2 = pathname.match(MAP_URL_PATTERNV2);

if (match) {
const context = {
return {
name: match[2],
id: match[3],
};
return context;
}

if (matchV2) {
const context = {
return {
name: matchV2[2],
id: matchV2[3],
};
return context;
}

const match2 = pathname.match(/^\/wallets\/([a-z0-9-]+)\/tokens\?.*$/);
const context = {
name: 'wallets',
id: match2[1],
};
return context;
if (match2) {
// check if match2 is not null before accessing it
return {
name: 'wallets',
id: match2[1],
};
}

return null;
}
Expand Down
Loading
Loading