-
Notifications
You must be signed in to change notification settings - Fork 301
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Resolve merge conflict by incorporating both suggestions
- Loading branch information
Showing
22 changed files
with
299 additions
and
79 deletions.
There are no files selected for viewing
12 changes: 12 additions & 0 deletions
12
packages/react-storage/src/components/StorageBrowser/composables/Title.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,12 @@ | ||
import React from 'react'; | ||
|
||
import { HeadingElement } from '../context/elements'; | ||
import { CLASS_BASE } from '../views/constants'; | ||
|
||
export interface TitleProps { | ||
title?: string; | ||
} | ||
|
||
export const Title = ({ title }: TitleProps): React.JSX.Element => ( | ||
<HeadingElement className={`${CLASS_BASE}__title`}>{title}</HeadingElement> | ||
); |
18 changes: 18 additions & 0 deletions
18
packages/react-storage/src/components/StorageBrowser/composables/__tests__/Title.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,18 @@ | ||
import React from 'react'; | ||
import { render, screen } from '@testing-library/react'; | ||
import { Title } from '../Title'; | ||
import { CLASS_BASE } from '../../views/constants'; | ||
|
||
describe('Title', () => { | ||
it('renders and has the given classname', () => { | ||
const expectedTitle = 'StorageBrowser'; | ||
const BLOCK_NAME = `${CLASS_BASE}__title`; | ||
|
||
render(<Title title={expectedTitle} />); | ||
|
||
const [renderedTitle] = screen.getAllByRole('heading'); | ||
|
||
expect(renderedTitle).toHaveTextContent('StorageBrowser'); | ||
expect(renderedTitle).toHaveClass(BLOCK_NAME); | ||
}); | ||
}); |
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
20 changes: 20 additions & 0 deletions
20
packages/react-storage/src/components/StorageBrowser/controls/TitleControl.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,20 @@ | ||
import React from 'react'; | ||
|
||
import { Title } from '../composables/Title'; | ||
import { ViewElement } from '../context/elements'; | ||
import { ControlProps } from './types'; | ||
import { useResolvedComposable } from './hooks/useResolvedComposable'; | ||
import { useTitle } from './hooks/useTitle'; | ||
|
||
export const TitleControl = ({ | ||
className, | ||
}: ControlProps): React.JSX.Element => { | ||
const props = useTitle(); | ||
const ResolvedTitle = useResolvedComposable(Title, 'Title'); | ||
|
||
return ( | ||
<ViewElement className={className}> | ||
<ResolvedTitle {...props} /> | ||
</ViewElement> | ||
); | ||
}; |
28 changes: 28 additions & 0 deletions
28
...ages/react-storage/src/components/StorageBrowser/controls/__tests__/TitleControl.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,28 @@ | ||
import React from 'react'; | ||
import { render, screen } from '@testing-library/react'; | ||
import { TitleControl } from '../TitleControl'; | ||
import { CLASS_BASE } from '../../views/constants'; | ||
import * as useTitleModule from '../hooks/useTitle'; | ||
|
||
const BLOCK_NAME = `${CLASS_BASE}__title`; | ||
|
||
describe('TitleControl', () => { | ||
const useTitleSpy = jest.spyOn(useTitleModule, 'useTitle'); | ||
|
||
afterEach(() => { | ||
useTitleSpy.mockReset(); | ||
}); | ||
|
||
it('renders', () => { | ||
useTitleSpy.mockReturnValue({ | ||
title: 'Amplify', | ||
}); | ||
|
||
render(<TitleControl />); | ||
|
||
const [renderedTitle] = screen.getAllByRole('heading'); | ||
|
||
expect(renderedTitle).toHaveTextContent('Amplify'); | ||
expect(renderedTitle).toHaveClass(BLOCK_NAME); | ||
}); | ||
}); |
32 changes: 32 additions & 0 deletions
32
...es/react-storage/src/components/StorageBrowser/controls/hooks/__tests__/useTitle.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,32 @@ | ||
import { useControlsContext } from '../../../controls/context'; | ||
import { useTitle } from '../useTitle'; | ||
|
||
jest.mock('../../../controls/context'); | ||
|
||
describe('useTitle', () => { | ||
const data = { | ||
title: 'ShinyNewTitle', | ||
}; | ||
|
||
const mockUseControlsContext = jest.mocked(useControlsContext); | ||
|
||
afterEach(() => { | ||
mockUseControlsContext.mockReset(); | ||
}); | ||
|
||
it('returns Title data', () => { | ||
mockUseControlsContext.mockReturnValue({ data }); | ||
|
||
expect(useTitle()).toStrictEqual({ | ||
title: 'ShinyNewTitle', | ||
}); | ||
}); | ||
|
||
it('returns empty string for children if title is missing from data', () => { | ||
mockUseControlsContext.mockReturnValue({ data: {} }); | ||
|
||
expect(useTitle()).toStrictEqual({ | ||
title: undefined, | ||
}); | ||
}); | ||
}); |
10 changes: 10 additions & 0 deletions
10
packages/react-storage/src/components/StorageBrowser/controls/hooks/useTitle.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,10 @@ | ||
import { TitleProps } from '../../composables/Title'; | ||
import { useControlsContext } from '../../controls/context'; | ||
|
||
export const useTitle = (): TitleProps => { | ||
const { data } = useControlsContext(); | ||
|
||
return { | ||
title: data?.title, | ||
}; | ||
}; |
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
16 changes: 0 additions & 16 deletions
16
packages/react-storage/src/components/StorageBrowser/views/Controls/Title.tsx
This file was deleted.
Oops, something went wrong.
12 changes: 0 additions & 12 deletions
12
packages/react-storage/src/components/StorageBrowser/views/Controls/__tests__/Title.spec.tsx
This file was deleted.
Oops, something went wrong.
5 changes: 1 addition & 4 deletions
5
packages/react-storage/src/components/StorageBrowser/views/Controls/index.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 |
---|---|---|
@@ -1,10 +1,7 @@ | ||
export { EmptyMessageControl } from './EmptyMessage'; | ||
export { ExitControl } from './Exit'; | ||
export { LoadingControl } from './Loading'; | ||
export { MessageControl } from './Message'; | ||
export { OverwriteControl } from './Overwrite'; | ||
export { PaginateControl } from './Paginate'; | ||
export { SearchControl } from './Search'; | ||
export { TitleControl } from './Title'; | ||
export { TableControl } from './Table'; | ||
export { TableControl, LocationDetailViewTable } from './Table'; | ||
export { Controls } from './Controls'; |
14 changes: 0 additions & 14 deletions
14
...s/react-storage/src/components/StorageBrowser/views/LocationActionView/Controls/Title.tsx
This file was deleted.
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
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
Oops, something went wrong.