Skip to content

Commit

Permalink
fix: update test for replaceImge.
Browse files Browse the repository at this point in the history
  • Loading branch information
svrnm committed Aug 4, 2021
1 parent b18ddd5 commit 6801eb1
Showing 1 changed file with 26 additions and 26 deletions.
52 changes: 26 additions & 26 deletions test/commands/ReplaceImage.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,77 +21,77 @@ describe('ReplaceImage', function () {
const img = {
src: 'asdf'
}
new ReplaceImage('', '').apply(img, 'src')
assert.equal(img.src, 'asdf')
new ReplaceImage('', ['']).apply(img, 'src')
assert.strictEqual(img.src, 'asdf')
})

it('should replace src with exact match', function () {
const img = {
src: 'http://cdn.example.com/images/test.png'
}
new ReplaceImage('http://cdn.example.com/images/test.png', 'another.png').apply(img, 'src')
assert.equal(img.src, 'another.png')
new ReplaceImage('another.png', ['http://cdn.example.com/images/test.png']).apply(img, 'src')
assert.strictEqual(img.src, 'another.png')
})

it('should replace src with prefix match', function () {
const img = {
src: 'http://cdn.example.com/images/test.png'
}
new ReplaceImage('http://cdn.example.com/*', 'another.png').apply(img, 'src')
assert.equal(img.src, 'another.png')
new ReplaceImage('another.png', ['http://cdn.example.com/*']).apply(img, 'src')
assert.strictEqual(img.src, 'another.png')
})

it('should replace src with suffix match', function () {
const img = {
src: 'http://cdn.example.com/images/test.png'
}
new ReplaceImage('*/test.png', 'another.png').apply(img, 'src')
assert.equal(img.src, 'another.png')
new ReplaceImage('another.png', ['*/test.png']).apply(img, 'src')
assert.strictEqual(img.src, 'another.png')
})

it('should replace src with "contains" match', function () {
const img = {
src: 'http://cdn.example.com/images/test.png'
}
new ReplaceImage('*example.com*', 'another.png').apply(img, 'src')
assert.equal(img.src, 'another.png')
new ReplaceImage('another.png', ['*example.com*']).apply(img, 'src')
assert.strictEqual(img.src, 'another.png')
})

it('should replace src with "not" match', function () {
const img = {
src: 'http://cdn.example.net/images/test.png'
}
new ReplaceImage('!http://cdn.example.net/images/test.png', 'another.png').apply(img, 'src')
assert.equal(img.src, 'http://cdn.example.net/images/test.png')
new ReplaceImage('!http://cdn.example.com/images/test.png', 'another.png').apply(img, 'src')
assert.equal(img.src, 'another.png')
new ReplaceImage('another.png', ['!http://cdn.example.net/images/test.png']).apply(img, 'src')
assert.strictEqual(img.src, 'http://cdn.example.net/images/test.png')
new ReplaceImage('another.png', ['!http://cdn2.example.com/images/test.png']).apply(img, 'src')
assert.strictEqual(img.src, 'another.png')
})

it('should replace src with "contains" and "not" match', function () {
const img = {
src: 'http://cdn.example.net/images/test.png'
}
new ReplaceImage('!*example.net*', 'another.png').apply(img, 'src')
assert.equal(img.src, 'http://cdn.example.net/images/test.png')
new ReplaceImage('!*example.com*', 'another.png').apply(img, 'src')
assert.equal(img.src, 'another.png')
new ReplaceImage('another.png', ['!*example.net*']).apply(img, 'src')
assert.strictEqual(img.src, 'http://cdn.example.net/images/test.png')
new ReplaceImage('another.png', ['!*example.com*']).apply(img, 'src')
assert.strictEqual(img.src, 'another.png')
})

it('should leave target unchanged for a mismatch', function () {
const img = {
src: 'http://cdn.example.com/images/test.png'
}
new ReplaceImage('http://cdn.example.net/images/test.png', 'another.png').apply(img, 'src')
assert.equal(img.src, 'http://cdn.example.com/images/test.png')
new ReplaceImage('another.png', ['http://cdn.example.net/images/test.png']).apply(img, 'src')
assert.strictEqual(img.src, 'http://cdn.example.com/images/test.png')

new ReplaceImage('http://cdn.example.net/*', 'another.png').apply(img, 'src')
assert.equal(img.src, 'http://cdn.example.com/images/test.png')
new ReplaceImage('another.png', ['http://cdn.example.net/*']).apply(img, 'src')
assert.strictEqual(img.src, 'http://cdn.example.com/images/test.png')

new ReplaceImage('*/test.gif', 'another.png').apply(img, 'src')
assert.equal(img.src, 'http://cdn.example.com/images/test.png')
new ReplaceImage('another.png', ['*/test.gif']).apply(img, 'src')
assert.strictEqual(img.src, 'http://cdn.example.com/images/test.png')

new ReplaceImage('*example.net*', 'another.png').apply(img, 'src')
assert.equal(img.src, 'http://cdn.example.com/images/test.png')
new ReplaceImage('another.png', ['*example.net*']).apply(img, 'src')
assert.strictEqual(img.src, 'http://cdn.example.com/images/test.png')
})
})
})

0 comments on commit 6801eb1

Please sign in to comment.