-
Notifications
You must be signed in to change notification settings - Fork 79
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
Showing
21 changed files
with
720 additions
and
125 deletions.
There are no files selected for viewing
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 edit scene button', () => { | ||
const screen = renderPublishSceneButton({ projects, deploymentsByWorlds }) | ||
expect(screen.getByRole('button', { name: t('worlds_list_page.table.edit_scene') })).toBeInTheDocument() | ||
}) | ||
|
||
describe('when 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 unpublish scene button', () => { | ||
const screen = renderPublishSceneButton({ projects, deploymentsByWorlds }) | ||
expect(screen.getByRole('button', { name: t('worlds_list_page.table.unpublish_scene') })).toBeInTheDocument() | ||
}) | ||
|
||
describe('when 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 publish scene button', () => { | ||
const screen = renderPublishSceneButton({}) | ||
expect(screen.getByRole('button', { name: t('worlds_list_page.table.publish_scene') })).toBeInTheDocument() | ||
}) | ||
|
||
describe('when 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> | ||
) | ||
} |
12 changes: 12 additions & 0 deletions
12
src/components/WorldListPage/PublishSceneButton/PublishSceneButton.types.ts
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,12 @@ | ||
import { Deployment } from 'modules/deployment/types' | ||
import { ENS } from 'modules/ens/types' | ||
import { Project } from 'modules/project/types' | ||
|
||
export type Props = { | ||
deploymentsByWorlds: Record<string, Deployment> | ||
ens: ENS | ||
projects: Project[] | ||
onEditScene?: (ens: ENS) => void | ||
onUnpublishScene?: (ens: ENS) => void | ||
onPublishScene?: () => void | ||
} |
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,3 @@ | ||
import PublishSceneButton from './PublishSceneButton' | ||
|
||
export default PublishSceneButton |
178 changes: 178 additions & 0 deletions
178
src/components/WorldListPage/WorldContributorTab/WorldContributorTab.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,178 @@ | ||
import { t } from 'decentraland-dapps/dist/modules/translation' | ||
import { renderWithProviders } from 'specs/utils' | ||
import { Deployment } from 'modules/deployment/types' | ||
import { ENS } from 'modules/ens/types' | ||
import { fromBytesToMegabytes, getExplorerUrl } from '../utils' | ||
import WorldContributorTab from './WorldContributorTab' | ||
import { Props } from './WorldContributorTab.types' | ||
import userEvent from '@testing-library/user-event' | ||
|
||
export function renderWorldContributorTab(props: Partial<Props>) { | ||
return renderWithProviders( | ||
<WorldContributorTab | ||
items={[]} | ||
deploymentsByWorlds={{}} | ||
error={null} | ||
loading={false} | ||
onNavigate={jest.fn()} | ||
onUnpublishWorld={jest.fn()} | ||
projects={[]} | ||
{...props} | ||
/> | ||
) | ||
} | ||
|
||
describe('when loading the items', () => { | ||
it('should show spinner', () => { | ||
const screen = renderWorldContributorTab({ loading: true }) | ||
expect(screen.container.getElementsByClassName('loader').length).toBe(1) | ||
}) | ||
}) | ||
|
||
describe('when rendering contributable names table', () => { | ||
let deploymentsByWorlds: Record<string, Deployment> | ||
let items: ENS[] | ||
|
||
describe('when the user has no contributable names', () => { | ||
beforeEach(() => { | ||
items = [] | ||
}) | ||
|
||
it('should show empty placeholder', () => { | ||
const screen = renderWorldContributorTab({ items }) | ||
expect(screen.getByText(t('worlds_list_page.empty_contributor_list.title'))) | ||
}) | ||
}) | ||
|
||
describe('when the user has contributable names', () => { | ||
beforeEach(() => { | ||
items = [ | ||
{ | ||
name: 'test.dcl.eth', | ||
subdomain: 'test.dcl.eth', | ||
content: '', | ||
ensOwnerAddress: '0xtest1', | ||
nftOwnerAddress: '0xtest1', | ||
resolver: '0xtest3', | ||
tokenId: '', | ||
ensAddressRecord: '', | ||
size: '1048576', | ||
userPermissions: ['deployment'], | ||
worldStatus: { | ||
healthy: true, | ||
scene: { urn: 'urn', entityId: 'entityId' } | ||
} | ||
} | ||
] | ||
}) | ||
|
||
it("should show item's name", () => { | ||
const screen = renderWorldContributorTab({ items }) | ||
expect(screen.getByText(items[0].name)).toBeInTheDocument() | ||
}) | ||
|
||
it("should show item's size", () => { | ||
const screen = renderWorldContributorTab({ items }) | ||
expect(screen.getByText(fromBytesToMegabytes(Number(items[0].size!)))).toBeInTheDocument() | ||
}) | ||
|
||
it("should show item's permissions", () => { | ||
const screen = renderWorldContributorTab({ items }) | ||
expect(screen.getByText(t(`worlds_list_page.table.user_permissions.${items[0].userPermissions![0]}`))).toBeInTheDocument() | ||
}) | ||
|
||
describe('when the world has a scene deployed', () => { | ||
beforeEach(() => { | ||
deploymentsByWorlds = { | ||
['test.dcl.eth']: { | ||
projectId: '1', | ||
id: '1' | ||
} as Deployment | ||
} | ||
}) | ||
|
||
it("should show world's url", () => { | ||
const screen = renderWorldContributorTab({ items, deploymentsByWorlds }) | ||
expect(screen.getByText(getExplorerUrl(items[0].subdomain))) | ||
}) | ||
|
||
describe('and the user has deployment permissions', () => { | ||
beforeEach(() => { | ||
items = [ | ||
{ | ||
...items[0], | ||
userPermissions: ['deployment'] | ||
} | ||
] | ||
}) | ||
|
||
it('should show unpublish scene button', () => { | ||
const screen = renderWorldContributorTab({ items, deploymentsByWorlds }) | ||
expect(screen.getByRole('button', { name: t('worlds_list_page.table.unpublish_scene') })).toBeInTheDocument() | ||
}) | ||
|
||
it('should trigger onUnpublishWorld action when unpublish button is clicked', () => { | ||
const onUnpublishWorld = jest.fn() | ||
const screen = renderWorldContributorTab({ items, deploymentsByWorlds, onUnpublishWorld }) | ||
const unpublishBtn = screen.getByRole('button', { name: t('worlds_list_page.table.unpublish_scene') }) | ||
userEvent.click(unpublishBtn) | ||
expect(onUnpublishWorld).toHaveBeenCalled() | ||
}) | ||
}) | ||
|
||
describe("and the user doesn't have deployment permissions", () => { | ||
beforeEach(() => { | ||
items = [ | ||
{ | ||
...items[0], | ||
userPermissions: ['streaming'] | ||
} | ||
] | ||
}) | ||
|
||
it('should not show unpublish scene button', () => { | ||
const screen = renderWorldContributorTab({ items, deploymentsByWorlds }) | ||
expect(screen.queryByRole('button', { name: t('worlds_list_page.table.unpublish_scene') })).not.toBeInTheDocument() | ||
}) | ||
}) | ||
}) | ||
|
||
describe('when the world has no scene deployed', () => { | ||
beforeEach(() => { | ||
deploymentsByWorlds = {} | ||
}) | ||
|
||
describe('and the user has deployment permissions', () => { | ||
beforeEach(() => { | ||
items = [ | ||
{ | ||
...items[0], | ||
userPermissions: ['deployment'] | ||
} | ||
] | ||
}) | ||
|
||
it('should show publish scene button', () => { | ||
const screen = renderWorldContributorTab({ items, deploymentsByWorlds }) | ||
expect(screen.getByRole('button', { name: t('worlds_list_page.table.publish_scene') })).toBeInTheDocument() | ||
}) | ||
}) | ||
|
||
describe("and the user doesn't have deployment permissions", () => { | ||
beforeEach(() => { | ||
items = [ | ||
{ | ||
...items[0], | ||
userPermissions: ['streaming'] | ||
} | ||
] | ||
}) | ||
|
||
it('should not show publish scene button', () => { | ||
const screen = renderWorldContributorTab({ items, deploymentsByWorlds }) | ||
expect(screen.queryByRole('button', { name: t('worlds_list_page.table.publish_scene') })).not.toBeInTheDocument() | ||
}) | ||
}) | ||
}) | ||
}) | ||
}) |
Oops, something went wrong.