Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test: refactor unit test to use data-uri instead #16847

Merged
merged 3 commits into from
Aug 1, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions test/unit/mocks/uri.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

42 changes: 19 additions & 23 deletions test/unit/specs/avatar.spec.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {createTest, createVue, destroyVM} from '../util';
import { createTest, createVue, destroyVM, wait } from '../util';
import Avatar from 'packages/avatar';
import { IMAGE_SUCCESS, IMAGE_FAIL } from '../mocks/uri';

describe('Avatar', () => {
let vm;
Expand Down Expand Up @@ -63,18 +64,18 @@ describe('Avatar', () => {
it('image avatar', () => {
vm = createVue({
template: `
<el-avatar src="https://cube.elemecdn.com/0/88/03b0d39583f48206768a7534e55bcpng.png"></el-avatar>
<el-avatar src="${IMAGE_SUCCESS}"></el-avatar>
`
}, true);
const imgElm = vm.$el.children[0];
expect(imgElm.tagName.toUpperCase()).to.equal('IMG');
expect(imgElm.src).to.equal('https://cube.elemecdn.com/0/88/03b0d39583f48206768a7534e55bcpng.png');
expect(imgElm.src).to.equal(IMAGE_SUCCESS);
});

it('image fallback', (done) => {
it('image fallback', async() => {
vm = createVue({
template: `
<el-avatar src="https://empty" @error="errorHandler">
<el-avatar src="${IMAGE_FAIL}" @error="errorHandler">
fallback
</el-avatar>
`,
Expand All @@ -84,14 +85,12 @@ describe('Avatar', () => {
}
}
}, true);
setTimeout(() => {
const avatarElm = vm.$el;
expect(avatarElm.textContent.trim()).to.equal('fallback');
done();
}, 3000);
await wait();
const avatarElm = vm.$el;
expect(avatarElm.textContent.trim()).to.equal('fallback');
});

it('image fit', (done) => {
it('image fit', async() => {
vm = createVue({
template: `
<div>
Expand All @@ -103,21 +102,18 @@ describe('Avatar', () => {
data() {
return {
fits: ['fill', 'contain', 'cover', 'none', 'scale-down'],
url: 'https://fuss10.elemecdn.com/e/5d/4a731a90594a4af544c0c25941171jpeg.jpeg'
url: IMAGE_SUCCESS
};
}
}, true);
setTimeout(() => {
const containerElm = vm.$el;
expect(containerElm.children[0].children[0].style.objectFit).to.equal('cover');
expect(containerElm.children[1].children[0].style.objectFit).to.equal('fill');
expect(containerElm.children[2].children[0].style.objectFit).to.equal('contain');
expect(containerElm.children[3].children[0].style.objectFit).to.equal('cover');
expect(containerElm.children[4].children[0].style.objectFit).to.equal('none');
expect(containerElm.children[5].children[0].style.objectFit).to.equal('scale-down');

done();
}, 3000);
await wait();
const containerElm = vm.$el;
expect(containerElm.children[0].children[0].style.objectFit).to.equal('cover');
expect(containerElm.children[1].children[0].style.objectFit).to.equal('fill');
expect(containerElm.children[2].children[0].style.objectFit).to.equal('contain');
expect(containerElm.children[3].children[0].style.objectFit).to.equal('cover');
expect(containerElm.children[4].children[0].style.objectFit).to.equal('none');
expect(containerElm.children[5].children[0].style.objectFit).to.equal('scale-down');
});
});

7 changes: 5 additions & 2 deletions test/unit/specs/image.spec.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { createTest, createVue, destroyVM, wait } from '../util';
import Image from 'packages/image';
import { IMAGE_SUCCESS, IMAGE_FAIL } from '../mocks/uri';

const src = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEAAAABACAYAAACqaXHeAAAFmklEQVR4Xu2ba2wUVRTH/2cWtlaooFQwKpr4CkESTQBNUAkodGeaKFGD2u6WGPyAmmAEEZmpj1VhBghE/KKGBIztDIXAByWBnQ1oQREfARNiDDHiF1+ooBiksVt295hFiqSdxx3KdmcH5uv+z+3//O65c19TwgX+0AWePy4CuFgBISCQ3J6+DFLuVQKmg2k4gK3xuvw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qgAIImntTcYu4UBpLKtU8D8aRQAMJD/uSZeu2t6Oi8MILldHU8SfRMFAG67wN7cHFeCcz5svaZ4koWvosO9FGbdlI1Wt850BNCSXTSMOX4iEhVAaDAT+o5AAEriVEYrgHBmj+8FI7QVwJzLjei+fPOUN0rnG46P66FoMqMdIUK9SBWEGIDvjZIrgFRGOyR6qBlWAMzQLEU3vDrRvQJsdR+BJlZzBYh8VuM1BHYSQehCMpwVwF1mwqjrewYotBk69RK0tS0AHq7eChC7UPEYAto6As6c9VfdLED8tJkwfL9DcH8J2upqgBZWbwXgalPWD/v59wCgvQTgNb8GSr+H7x3AB0zZuF3EuyuA5oz6jET0pkgjYQPAzEstxSh1oO/jVQFzALzn20IIK0CKFa5vm7niBxHvHgsh9QEQfSDSSP8KWDSaOe54GyvS3sA0vMuUjemibbgPgWzrVInZ8RChb+N9AQSdRkXNiul4qikbn4hp4f5/g7N3vDAiXpCOEcj/IwpG0VT02Nl/9NSOshjvGMinMaJJ9OqYeYulGLODxHkml7TVZ8GYT0Q3uDfKXQxaY8n6i06aZnvJDGKaB8JMAo0IYk5UW7r5BbAtNhRz22YYf4jGlXT+vRuktSrUXgRQhZ12Xi1f8BXwL38cy1+mrtJNAAAAAElFTkSuQmCC';
const src = IMAGE_SUCCESS;

describe('Image', () => {
let vm;
Expand All @@ -28,7 +29,9 @@ describe('Image', () => {
});

it('load failed', async() => {
vm = createTest(Image, true);
vm = createTest(Image, {
src: IMAGE_FAIL
}, true);
await wait();
const error = vm.$el.querySelector('.el-image__error');
expect(error).to.be.exist;
Expand Down