Skip to content

Commit 298a947

Browse files
committed
fix: fix duplicated loading. refactor a few tests
1 parent 3e41504 commit 298a947

File tree

4 files changed

+15
-14
lines changed

4 files changed

+15
-14
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "vue-image-kit",
3-
"version": "0.1.1",
3+
"version": "0.1.2",
44
"private": false,
55
"description": "Vue.js Image Kit Component with Lazy Load built in and Responsive Images",
66
"homepage": "https://github.com/guastallaigor/vue-image-kit#readme",

src/components/VueImageKit.vue

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<div v-if="dataUrl" class="vue-image-kit__placeholder" :style="{ backgroundColor }">
44
<img :src="placeholder || dataUrl" alt="Placeholder" :style="{ width: `${width}px`, height: `${height}px` }"/>
55
</div>
6-
<img class="vue-image-kit__img" :srcset="getSrcset" :sizes="getSizes" :src="getSrc" :alt="alt" :style="{ width: `${width}px`, height: `${height}px` }"/>
6+
<img class="vue-image-kit__img" :sizes="getSizes" :alt="alt" :style="{ width: `${width}px`, height: `${height}px` }"/>
77
</div>
88
</template>
99

@@ -75,13 +75,6 @@ export default {
7575
7676
return canvas.toDataURL()
7777
},
78-
getSrc () {
79-
const { showCanvas, dataUrl, imageKitPrefix, hash, src } = this
80-
81-
return showCanvas
82-
? dataUrl
83-
: `${imageKitPrefix}/${hash}/${src}`
84-
},
8578
getSrcset () {
8679
const { srcset, imageKitPrefix, hash, customTransform, src } = this
8780

tests/unit/__snapshots__/vue-image-kit.spec.js.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22

33
exports[`When I create the VueImageKit component should match snapshot 1`] = `
44
<div class="vue-image-kit">
5-
<!----> <img srcset="https://ik.imagekit.io/6xhf1gnexgdgk/tr:w-320/lion_BllLvaqVn.jpg 320w, https://ik.imagekit.io/6xhf1gnexgdgk/tr:w-480/lion_BllLvaqVn.jpg 480w, https://ik.imagekit.io/6xhf1gnexgdgk/tr:w-800/lion_BllLvaqVn.jpg 800w" sizes="(max-width: 320px) 280px, (max-width: 480px) 440px, (max-width: 800px) 760px 1080px" src="" alt="" class="vue-image-kit__img"></div>
5+
<!----> <img sizes="(max-width: 320px) 280px, (max-width: 480px) 440px, (max-width: 800px) 760px 1080px" alt="" class="vue-image-kit__img"></div>
66
`;

tests/unit/vue-image-kit.spec.js

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -122,26 +122,32 @@ describe('When I create the VueImageKit component', () => {
122122
expect(placeholder.attributes().style).toBe('background-color: rgb(255, 68, 0);') // #f40
123123
})
124124

125-
it('should have different srcset from default', () => {
125+
it('should have different srcset from default', async () => {
126126
const wrapper = createComponent({ ...item, srcset: [400, 600, 900] })
127127
const main = wrapper.find('.vue-image-kit > .vue-image-kit__img')
128128
expect(main.exists()).toBe(true)
129+
wrapper.vm.triggerIntersection({ isIntersecting: true })
130+
await wrapper.vm.$nextTick()
129131
const expected = 'https://ik.imagekit.io/6xhf1gnexgdgk/tr:w-400/lion_BllLvaqVn.jpg 400w, https://ik.imagekit.io/6xhf1gnexgdgk/tr:w-600/lion_BllLvaqVn.jpg 600w, https://ik.imagekit.io/6xhf1gnexgdgk/tr:w-900/lion_BllLvaqVn.jpg 900w'
130132
expect(main.attributes().srcset).toBe(expected)
131133
})
132134

133-
it('should have different sizes from default', () => {
135+
it('should have different sizes from default', async () => {
134136
const wrapper = createComponent({ ...item, srcset: [200, 250, 300] })
135137
const main = wrapper.find('.vue-image-kit > .vue-image-kit__img')
136138
expect(main.exists()).toBe(true)
139+
wrapper.vm.triggerIntersection({ isIntersecting: true })
140+
await wrapper.vm.$nextTick()
137141
const expected = '(max-width: 200px) 160px, (max-width: 250px) 210px, (max-width: 300px) 260px 1080px'
138142
expect(main.attributes().sizes).toBe(expected)
139143
})
140144

141-
it('should have different sizes and srcset from default', () => {
145+
it('should have different sizes and srcset from default', async () => {
142146
const wrapper = createComponent({ ...item, srcset: [210, 220, 230], sizes: [210, 220, 230] })
143147
const main = wrapper.find('.vue-image-kit > .vue-image-kit__img')
144148
expect(main.exists()).toBe(true)
149+
wrapper.vm.triggerIntersection({ isIntersecting: true })
150+
await wrapper.vm.$nextTick()
145151
const expected = '(max-width: 210px) 210px, (max-width: 220px) 220px, (max-width: 230px) 230px 1080px'
146152
expect(main.attributes().sizes).toBe(expected)
147153
const expectedSrcset = 'https://ik.imagekit.io/6xhf1gnexgdgk/tr:w-210/lion_BllLvaqVn.jpg 210w, https://ik.imagekit.io/6xhf1gnexgdgk/tr:w-220/lion_BllLvaqVn.jpg 220w, https://ik.imagekit.io/6xhf1gnexgdgk/tr:w-230/lion_BllLvaqVn.jpg 230w'
@@ -155,12 +161,14 @@ describe('When I create the VueImageKit component', () => {
155161
expect(main.attributes().sizes).toContain('1366px')
156162
})
157163

158-
it('should have a custom transform', () => {
164+
it('should have a custom transform', async () => {
159165
// https://imagekit.io/features/advanced-image-manipulation-blur-rotate-crop-background-radius
160166
const customTransform = 'c-at_max,bl-1:r-20,bg-FFCFA1'
161167
const wrapper = createComponent({ ...item, customTransform })
162168
const main = wrapper.find('.vue-image-kit > .vue-image-kit__img')
163169
expect(main.exists()).toBe(true)
170+
wrapper.vm.triggerIntersection({ isIntersecting: true })
171+
await wrapper.vm.$nextTick()
164172
expect(main.attributes().srcset).toContain(customTransform)
165173
})
166174

0 commit comments

Comments
 (0)