Skip to content

Commit

Permalink
unit test for refimg thumbnail
Browse files Browse the repository at this point in the history
  • Loading branch information
VargaJoe committed Sep 8, 2023
1 parent 4484697 commit 66626a7
Showing 1 changed file with 37 additions and 2 deletions.
39 changes: 37 additions & 2 deletions packages/sn-controls-react/test/reference-grid.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,23 @@ const userContent = {

const imageContent = {
Name: 'Test Image',
Path: '/Root/IMS/Public/alba',
Path: '/Root/Content/Images/Picture.jpg',
DisplayName: 'Test Image',
Id: 4830,
Type: 'Image',
Enabled: true,
PageCount: 0,
}

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

const repository: any = {
Expand Down Expand Up @@ -257,7 +269,7 @@ describe('Reference grid field control', () => {
expect(wrapper.update().find(Avatar).text()).toBe('A.M')
})

it('should render img tag if type is image', async () => {
it('should render img tag if type is image but PageCount is 0', async () => {
const repo = {
loadCollection: jest.fn(() => {
return { d: { results: [{ ...imageContent }] } }
Expand All @@ -277,5 +289,28 @@ describe('Reference grid field control', () => {
expect(wrapper.update().find('img').prop('src')).toContain(imageContent.Path)
expect(wrapper.update().find('img').prop('alt')).toBe(imageContent.DisplayName)
})

it('should render img tag with thumbnail if type is image but PageCount is greater than 0', async () => {
const repo = {
loadCollection: jest.fn(() => {
return { d: { results: [{ ...imageContentWithPreview }] } }
}),
schemas: {
isContentFromType: jest.fn((a, b) => b === 'Image'),
},
configuration: repository.configuration,
} as any
let wrapper: any
await act(async () => {
wrapper = mount(
<ReferencePicker repository={repo} fieldSettings={{ ...defaultSettings, Type: 'Image' }} path="" />,
)
})

expect(wrapper.update().find('img').prop('src')).toContain(
`${imageContentWithPreview.Path}/Previews/${imageContentWithPreview.Version}/thumbnail1.png`,
)
expect(wrapper.update().find('img').prop('alt')).toBe(imageContentWithPreview.DisplayName)
})
})
})

0 comments on commit 66626a7

Please sign in to comment.