-
Notifications
You must be signed in to change notification settings - Fork 82
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Melisa Anabella Rossi
authored
May 20, 2024
1 parent
47bc85e
commit f1266d7
Showing
45 changed files
with
1,359 additions
and
176 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,20 @@ | ||
import { connect } from 'react-redux' | ||
import { push } from 'connected-react-router' | ||
import { getIsWorldContributorEnabled } from 'modules/features/selectors' | ||
import { RootState } from 'modules/common/types' | ||
import NameTabs from './NameTabs' | ||
import { MapDispatch, MapDispatchProps } from './NameTabs.types' | ||
|
||
const mapState = (state: RootState) => { | ||
return { | ||
isWorldContributorEnabled: getIsWorldContributorEnabled(state) | ||
} | ||
} | ||
|
||
const mapDispatch = (dispatch: MapDispatch): MapDispatchProps => { | ||
return { | ||
onNavigate: to => dispatch(push(to)) | ||
} | ||
} | ||
|
||
export default connect(null, mapDispatch)(NameTabs) | ||
export default connect(mapState, mapDispatch)(NameTabs) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
109 changes: 109 additions & 0 deletions
109
src/components/WorldListPage/PublishSceneButton/PublishSceneButton.spec.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
import { render } from '@testing-library/react' | ||
import userEvent from '@testing-library/user-event' | ||
import { t } from 'decentraland-dapps/dist/modules/translation' | ||
import { ENS } from 'modules/ens/types' | ||
import { Deployment } from 'modules/deployment/types' | ||
import { Project } from 'modules/project/types' | ||
import { Props } from './PublishSceneButton.types' | ||
import PublishSceneButton from './PublishSceneButton' | ||
|
||
const ens = { | ||
name: 'test', | ||
subdomain: 'test', | ||
content: '', | ||
ensOwnerAddress: '0xtest1', | ||
nftOwnerAddress: '0xtest1', | ||
resolver: '0xtest3', | ||
tokenId: '', | ||
ensAddressRecord: '', | ||
worldStatus: { | ||
healthy: true | ||
} | ||
} as ENS | ||
|
||
let deploymentsByWorlds: Record<string, Deployment> | ||
let projects: Project[] | ||
|
||
function renderPublishSceneButton(props: Partial<Props>) { | ||
return render( | ||
<PublishSceneButton | ||
deploymentsByWorlds={{}} | ||
ens={ens} | ||
projects={[]} | ||
onEditScene={jest.fn()} | ||
onPublishScene={jest.fn()} | ||
onUnpublishScene={jest.fn()} | ||
{...props} | ||
/> | ||
) | ||
} | ||
|
||
describe('when the world has a scene deployed', () => { | ||
beforeEach(() => { | ||
deploymentsByWorlds = { | ||
[ens.subdomain]: { | ||
projectId: '1', | ||
name: 'Deployment' | ||
} as Deployment | ||
} | ||
}) | ||
|
||
describe('and the user has access to the deployed project', () => { | ||
beforeEach(() => { | ||
projects = [{ id: '1' } as Project] | ||
}) | ||
|
||
it('should show the edit scene button', () => { | ||
const screen = renderPublishSceneButton({ projects, deploymentsByWorlds }) | ||
expect(screen.getByRole('button', { name: t('worlds_list_page.table.edit_scene') })).toBeInTheDocument() | ||
}) | ||
|
||
describe('when the editScene button is clicked', () => { | ||
it('should trigger onEditScene callback action', () => { | ||
const onEditScene = jest.fn() | ||
const screen = renderPublishSceneButton({ onEditScene, projects, deploymentsByWorlds }) | ||
const editSceneButton = screen.getByRole('button', { name: t('worlds_list_page.table.edit_scene') }) | ||
userEvent.click(editSceneButton) | ||
expect(onEditScene).toHaveBeenCalled() | ||
}) | ||
}) | ||
}) | ||
|
||
describe("and the user doesn't have access to the deployed project", () => { | ||
beforeEach(() => { | ||
projects = [] | ||
}) | ||
|
||
it('should show the unpublish scene button', () => { | ||
const screen = renderPublishSceneButton({ projects, deploymentsByWorlds }) | ||
expect(screen.getByRole('button', { name: t('worlds_list_page.table.unpublish_scene') })).toBeInTheDocument() | ||
}) | ||
|
||
describe('when the unpublish button is clicked', () => { | ||
it('should trigger onUnpublish callback action', () => { | ||
const onUnpublishScene = jest.fn() | ||
const screen = renderPublishSceneButton({ onUnpublishScene, projects, deploymentsByWorlds }) | ||
const unpublishSceneButton = screen.getByRole('button', { name: t('worlds_list_page.table.unpublish_scene') }) | ||
userEvent.click(unpublishSceneButton) | ||
expect(onUnpublishScene).toHaveBeenCalled() | ||
}) | ||
}) | ||
}) | ||
}) | ||
|
||
describe('when the world has no scene deployed', () => { | ||
it('should show the publish scene button', () => { | ||
const screen = renderPublishSceneButton({}) | ||
expect(screen.getByRole('button', { name: t('worlds_list_page.table.publish_scene') })).toBeInTheDocument() | ||
}) | ||
|
||
describe('when the publish button is clicked', () => { | ||
it('should trigger onPublish callback action', () => { | ||
const onPublishScene = jest.fn() | ||
const screen = renderPublishSceneButton({ onPublishScene }) | ||
const publishButton = screen.getByRole('button', { name: t('worlds_list_page.table.publish_scene') }) | ||
userEvent.click(publishButton) | ||
expect(onPublishScene).toHaveBeenCalled() | ||
}) | ||
}) | ||
}) |
47 changes: 47 additions & 0 deletions
47
src/components/WorldListPage/PublishSceneButton/PublishSceneButton.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import { Button, Popup } from 'decentraland-ui' | ||
import { Props } from './PublishSceneButton.types' | ||
import { isWorldDeployed } from '../utils' | ||
import { t } from 'decentraland-dapps/dist/modules/translation' | ||
|
||
export default function PublishSceneButton({ | ||
deploymentsByWorlds, | ||
ens, | ||
projects, | ||
onEditScene, | ||
onUnpublishScene, | ||
onPublishScene | ||
}: Props): JSX.Element { | ||
const deployment = deploymentsByWorlds[ens.subdomain] | ||
return isWorldDeployed(deploymentsByWorlds, ens) ? ( | ||
<div className="publish-scene"> | ||
<Popup content={deployment?.name} on="hover" trigger={<span>{deployment?.name}</span>} /> | ||
{projects.find(project => project.id === deployment?.projectId) | ||
? onEditScene && ( | ||
<Button inverted size="small" onClick={() => onEditScene(ens)}> | ||
{t('worlds_list_page.table.edit_scene')} | ||
</Button> | ||
) | ||
: onUnpublishScene && ( | ||
<Popup | ||
content={t('worlds_list_page.table.scene_published_outside_builder')} | ||
on="hover" | ||
position="top center" | ||
trigger={ | ||
<Button inverted size="small" onClick={() => onUnpublishScene(ens)}> | ||
{t('worlds_list_page.table.unpublish_scene')} | ||
</Button> | ||
} | ||
/> | ||
)} | ||
</div> | ||
) : ( | ||
<div className="publish-scene"> | ||
<span>-</span> | ||
{onPublishScene && ( | ||
<Button primary size="small" onClick={onPublishScene}> | ||
{t('worlds_list_page.table.publish_scene')} | ||
</Button> | ||
)} | ||
</div> | ||
) | ||
} |
Oops, something went wrong.