Skip to content

Commit

Permalink
Add additional test cases for image URL extraction
Browse files Browse the repository at this point in the history
  • Loading branch information
oogali committed Jul 8, 2022
1 parent 32db7ce commit 0574683
Showing 1 changed file with 28 additions and 7 deletions.
35 changes: 28 additions & 7 deletions src/Components/IssueControl.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -107,12 +107,33 @@ test('Issues ', () => {
})


test('extractImageFromIssue', () => {
const issue = {
// eslint-disable-next-line max-len
body: 'Test Issue body\r\n\r\n<img width=\'475\' alt=\'image\' src=\'https://user-images.githubusercontent.com/3433606/171650424-c9fa4450-684d-4f6c-8657-d80245116a5b.png\'>\r\n\r\nimageURL\r\nhttps://user-images.githubusercontent.com/3433606/171650424-c9fa4450-684d-4f6c-8657-d80245116a5b.png\r\nimageURL\r\n\r\ncamera=#c:-29.47,18.53,111.13,-30.27,20.97,-10.06\r\n\r\n\r\nurl = http://localhost:8080/share/v/p/index.ifc#c:-26.91,28.84,112.47,-22,16.21,-3.48',
}
describe('extractImageFromIssue', () => {
test('null issue', () => {
const issue = null
expect(extractImageFromIssue(issue)).toEqual('')
})

test('null issue body', () => {
const issue = {
body: null,
}
expect(extractImageFromIssue(issue)).toEqual('')
})

const expectedImageURL = 'https://user-images.githubusercontent.com/3433606/171650424-c9fa4450-684d-4f6c-8657-d80245116a5b.png'
expect(extractImageFromIssue(issue)).toEqual(expectedImageURL)
test('issue body without image URL header + trailer', () => {
const issue = {
body: 'http://testing.dev/an/image.png',
}
expect(extractImageFromIssue(issue)).toEqual('')
})

test('issue body with valid image URL', () => {
const issue = {
// eslint-disable-next-line max-len
body: 'Test Issue body\r\n\r\n<img width=\'475\' alt=\'image\' src=\'https://user-images.githubusercontent.com/3433606/171650424-c9fa4450-684d-4f6c-8657-d80245116a5b.png\'>\r\n\r\nimageURL\r\nhttps://user-images.githubusercontent.com/3433606/171650424-c9fa4450-684d-4f6c-8657-d80245116a5b.png\r\nimageURL\r\n\r\ncamera=#c:-29.47,18.53,111.13,-30.27,20.97,-10.06\r\n\r\n\r\nurl = http://localhost:8080/share/v/p/index.ifc#c:-26.91,28.84,112.47,-22,16.21,-3.48',
}

const expectedImageURL = 'https://user-images.githubusercontent.com/3433606/171650424-c9fa4450-684d-4f6c-8657-d80245116a5b.png'
expect(extractImageFromIssue(issue)).toEqual(expectedImageURL)
})
})

0 comments on commit 0574683

Please sign in to comment.