Support multi cursor in Emmet Update Image Size

This commit is contained in:
Ramya Achutha Rao
2017-07-24 18:34:55 -07:00
parent 686d6959ea
commit 764dd415ad
2 changed files with 198 additions and 44 deletions

View File

@@ -0,0 +1,150 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import * as assert from 'assert';
import { Selection, commands } from 'vscode';
import { withRandomFileEditor, closeAllEditors } from './testUtils';
import * as path from 'path';
suite('Tests for Emmet actions on html tags', () => {
teardown(closeAllEditors);
const filePath = path.join(__dirname, '../../../../resources/linux/code.png');
test('update image css with multiple cursors in css file', () => {
const cssContents = `
.one {
margin: 10px;
padding: 10px;
background-image: url(https://github.com/Microsoft/vscode/blob/master/resources/linux/code.png);
}
.two {
background-image: url(https://github.com/Microsoft/vscode/blob/master/resources/linux/code.png);
height: 42px;
}
.three {
background-image: url(${filePath});
width: 42px;
}
`;
const expectedContents = `
.one {
margin: 10px;
padding: 10px;
background-image: url(https://github.com/Microsoft/vscode/blob/master/resources/linux/code.png);
width: 32px;
height: 32px;
}
.two {
background-image: url(https://github.com/Microsoft/vscode/blob/master/resources/linux/code.png);
width: 32px;
height: 32px;
}
.three {
background-image: url(${filePath});
height: 1024px;
width: 1024px;
}
`;
return withRandomFileEditor(cssContents, 'css', (editor, doc) => {
editor.selections = [
new Selection(4, 50, 4, 50),
new Selection(7, 50, 7, 50),
new Selection(11, 50, 11, 50)
];
return commands.executeCommand('emmet.updateImageSize').then(() => {
assert.equal(doc.getText(), expectedContents);
return Promise.resolve();
});
});
});
test('update image size in css in html file with multiple cursors', () => {
const htmlWithCssContents = `
<html>
<style>
.one {
margin: 10px;
padding: 10px;
background-image: url(https://github.com/Microsoft/vscode/blob/master/resources/linux/code.png);
}
.two {
background-image: url(https://github.com/Microsoft/vscode/blob/master/resources/linux/code.png);
height: 42px;
}
.three {
background-image: url(${filePath});
width: 42px;
}
</style>
</html>
`;
const expectedContents = `
<html>
<style>
.one {
margin: 10px;
padding: 10px;
background-image: url(https://github.com/Microsoft/vscode/blob/master/resources/linux/code.png);
width: 32px;
height: 32px;
}
.two {
background-image: url(https://github.com/Microsoft/vscode/blob/master/resources/linux/code.png);
width: 32px;
height: 32px;
}
.three {
background-image: url(${filePath});
height: 1024px;
width: 1024px;
}
</style>
</html>
`;
return withRandomFileEditor(htmlWithCssContents, 'html', (editor, doc) => {
editor.selections = [
new Selection(6, 50, 6, 50),
new Selection(9, 50, 9, 50),
new Selection(13, 50, 13, 50)
];
return commands.executeCommand('emmet.updateImageSize').then(() => {
assert.equal(doc.getText(), expectedContents);
return Promise.resolve();
});
});
});
test('update image size in img tag in html file with multiple cursors', () => {
const htmlwithimgtag = `
<html>
<img id="one" src="${filePath}" />
<img id="two" src="https://github.com/Microsoft/vscode/blob/master/resources/linux/code.png" width="56" />
<img id="three" src="https://github.com/Microsoft/vscode/blob/master/resources/linux/code.png" height="56" />
</html>
`;
const expectedContents = `
<html>
<img id="one" src="${filePath}" width="1024" height="1024" />
<img id="two" src="https://github.com/Microsoft/vscode/blob/master/resources/linux/code.png" width="32" height="32" />
<img id="three" src="https://github.com/Microsoft/vscode/blob/master/resources/linux/code.png" height="32" width="32" />
</html>
`;
return withRandomFileEditor(htmlwithimgtag, 'html', (editor, doc) => {
editor.selections = [
new Selection(2, 50, 2, 50),
new Selection(3, 50, 3, 50),
new Selection(4, 50, 4, 50)
];
return commands.executeCommand('emmet.updateImageSize').then(() => {
assert.equal(doc.getText(), expectedContents);
return Promise.resolve();
});
});
});
});