Skip to content

Commit

Permalink
unit test p0
Browse files Browse the repository at this point in the history
  • Loading branch information
VargaJoe committed Sep 27, 2023
1 parent 3b913dd commit 9a78463
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export const DefaultItemTemplate: React.FC<DefaultItemTemplateProps> = (props) =
const { content, repository } = props

const renderIcon = (item: GenericContent | User | Image) => {
console.log('renderIcon')
if (repository?.schemas.isContentFromType<User>(item, 'User')) {
const avatarUrl = item.Avatar?.Url
if (avatarUrl) {
Expand Down
4 changes: 4 additions & 0 deletions packages/sn-controls-react/test/__mocks__/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,7 @@ export const testArticle = {
export const testFolder = {
Type: 'Folder',
} as GenericContent

export const testImage = {
Type: 'Image',
} as GenericContent
34 changes: 33 additions & 1 deletion packages/sn-controls-react/test/reference-grid.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { ReferencePicker } from '../src/fieldcontrols/reference-grid/reference-p

const defaultSettings = {
Type: 'ReferenceFieldSetting',
AllowedTypes: ['User', 'Group'],
AllowedTypes: ['User', 'Group', 'Image'],
SelectionRoots: ['/Root/IMS', '/Root'],
Name: 'Members',
FieldClassName: 'SenseNet.ContentRepository.Fields.ReferenceField',
Expand All @@ -43,6 +43,17 @@ const userContent = {
},
}

let imageContent = {
Name: 'Test Image',
Path: '/Root/Content/Images/Picture.jpg',
DisplayName: 'Test Image',
Id: 4830,
Type: 'Image',
Enabled: true,
PageCount: 0,
Version: 'v1.0.A',
}

const repository: any = {
load: jest.fn((props) => {
return { d: userContent }
Expand Down Expand Up @@ -247,5 +258,26 @@ describe('Reference grid field control', () => {

expect(wrapper.update().find(Avatar).text()).toBe('A.M')
})

it('should render img tag if type is image but PageCount is 0', async () => {
const repo = {
loadCollection: jest.fn(() => {
return { d: { results: [{ ...imageContent }] } }
}),
schemas: {
isContentFromType: jest.fn((a, b) => b === 'Image'),
},
configuration: repository.configuration,
} as any
let wrapper: any
await act(async () => {
wrapper = mount(
<ReferenceGrid actionName="browse" settings={defaultSettings} content={imageContent} repository={repo} />,
)
})

expect(wrapper.update().find('img').prop('src')).toContain(imageContent.Path)
expect(wrapper.update().find('img').prop('alt')).toBe(imageContent.DisplayName)
})
})
})

0 comments on commit 9a78463

Please sign in to comment.