-
Notifications
You must be signed in to change notification settings - Fork 392
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(sanity): add components API test
- Loading branch information
1 parent
9294ada
commit 889e8c1
Showing
3 changed files
with
167 additions
and
17 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
describe('Config: studio.components', () => { | ||
beforeEach(() => { | ||
cy.visit('custom-components/content') | ||
}) | ||
|
||
describe('createConfig', () => { | ||
it('default layout is displayed inside renderLayout component', () => { | ||
cy.get('[data-testid="test-layout-config"]') | ||
.find('[data-testid="studio-layout"]') | ||
.should('be.visible') | ||
}) | ||
|
||
it('logo is displayed with context value from renderLayout', () => { | ||
cy.get('[data-testid="logo"]').contains('Context value') | ||
}) | ||
|
||
it('default navbar is displayed with banner from renderNavbar', () => { | ||
cy.get('[data-testid="test-navbar-config"]') | ||
.find('[data-testid="test-navbar-banner-config"]') | ||
.should('be.visible') | ||
cy.get('[data-testid="test-navbar-config"]') | ||
.find('[data-testid="navbar"]') | ||
.should('be.visible') | ||
}) | ||
|
||
it('default tool menu is displayed inside renderToolMenu component', () => { | ||
cy.get('[data-testid="test-tool-menu-config"]') | ||
.find('[data-testid="tool-collapse-menu"]') | ||
.should('be.visible') | ||
}) | ||
}) | ||
|
||
describe('createPlugin', () => { | ||
it('custom layout in createConfig is displayed inside renderLayout component', () => { | ||
cy.get('[data-testid="test-layout-plugin"]') | ||
.find('[data-testid="test-layout-config"]') | ||
.find('[data-testid="studio-layout"]') | ||
.should('be.visible') | ||
}) | ||
|
||
it('custom navbar in createConfig is displayed inside renderNavbar component', () => { | ||
cy.get('[data-testid="test-navbar-plugin"]') | ||
.find('[data-testid="test-navbar-config"]') | ||
.find('[data-testid="navbar"]') | ||
.should('be.visible') | ||
}) | ||
|
||
it('custom tool menu in createConfig is displayed inside renderToolMenu component', () => { | ||
cy.get('[data-testid="test-tool-menu-plugin"]') | ||
.find('[data-testid="test-tool-menu-config"]') | ||
.find('[data-testid="tool-collapse-menu"]') | ||
.should('be.visible') | ||
}) | ||
}) | ||
}) |
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,79 @@ | ||
import React, {createContext, useContext} from 'react' | ||
import {Box, Card, Flex, Stack, Text} from '@sanity/ui' | ||
import {LogoProps, NavbarProps, LayoutProps, createPlugin, ToolMenuProps} from 'sanity' | ||
|
||
export const componentsPlugin = createPlugin({ | ||
name: 'components-plugin', | ||
studio: { | ||
components: { | ||
Layout: (props) => ( | ||
<Box height="fill" data-testid="test-layout-plugin"> | ||
{props.renderLayout(props)} | ||
</Box> | ||
), | ||
Logo: (props) => <Box data-testid="test-logo-plugin">{props.renderLogo(props)}</Box>, | ||
Navbar: (props) => <Box data-testid="test-navbar-plugin">{props.renderNavbar(props)}</Box>, | ||
ToolMenu: (props) => ( | ||
<Box data-testid="test-tool-menu-plugin">{props.renderToolMenu(props)}</Box> | ||
), | ||
}, | ||
}, | ||
}) | ||
|
||
// Layout | ||
const TitleContext = createContext<string>('') | ||
const useTitleContext = () => useContext(TitleContext) | ||
|
||
export function CustomLayout(props: LayoutProps) { | ||
const {renderLayout} = props | ||
|
||
return ( | ||
<TitleContext.Provider value="Context value"> | ||
<Box height="fill" data-testid="test-layout-config"> | ||
{renderLayout(props)} | ||
</Box> | ||
</TitleContext.Provider> | ||
) | ||
} | ||
|
||
// Logo | ||
export function CustomLogo(props: LogoProps) { | ||
const title = useTitleContext() | ||
|
||
return props.renderLogo({...props, title}) | ||
} | ||
|
||
// Navbar | ||
export function CustomNavbar(props: NavbarProps) { | ||
return ( | ||
<Stack data-testid="test-navbar-config"> | ||
<Card padding={4} tone="primary" data-testid="test-navbar-banner-config"> | ||
<Flex align="center" gap={4}> | ||
<Text weight="semibold" size={1}> | ||
This banner is rendered with <code>{`components.Navbar`}</code> in{' '} | ||
<code>{`createConfig`}</code> | ||
</Text> | ||
</Flex> | ||
</Card> | ||
|
||
{props.renderNavbar(props)} | ||
</Stack> | ||
) | ||
} | ||
|
||
// ToolMenu | ||
export function CustomToolMenu(props: ToolMenuProps) { | ||
return ( | ||
<Card | ||
data-testid="test-tool-menu-config" | ||
paddingX={1} | ||
paddingY={props.context === 'sidebar' ? 1 : undefined} | ||
radius={2} | ||
shadow={1} | ||
sizing="border" | ||
tone="primary" | ||
> | ||
{props.renderToolMenu(props)} | ||
</Card> | ||
) | ||
} |
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