提交 0b3c33b8 编写于 作者: M Matthew Kwiecien

Adding unit tests to check for className when file is jsx.

上级 7221f92e
...@@ -63,6 +63,22 @@ const wrapInlineElementExpectedFormatFalse = ` ...@@ -63,6 +63,22 @@ const wrapInlineElementExpectedFormatFalse = `
</ul> </ul>
`; `;
const wrapMultiLineJsxExpected = `
<ul class="nav main">
<div className="hello">
<li class="item1">img</li>
<li class="item2">$hithere</li>
</div>
</ul>
`;
const wrapIndividualLinesJsxExpected = `
<ul class="nav main">
<div className="hello1"><li class="item1">img</li></div>
<div className="hello2"><li class="item2">$hithere</li></div>
</ul>
`;
suite('Tests for Wrap with Abbreviations', () => { suite('Tests for Wrap with Abbreviations', () => {
teardown(closeAllEditors); teardown(closeAllEditors);
...@@ -135,219 +151,219 @@ suite('Tests for Wrap with Abbreviations', () => { ...@@ -135,219 +151,219 @@ suite('Tests for Wrap with Abbreviations', () => {
</ul> </ul>
`; `;
return withRandomFileEditor(contents, 'html', (editor, _) => { return withRandomFileEditor(contents, 'html', (editor, _) => {
editor.selections = [new Selection(2, 0, 2, 0)]; editor.selections = [new Selection(2, 0, 2, 0)];
const promise = wrapWithAbbreviation({ abbreviation: 'li.hello|c' }); const promise = wrapWithAbbreviation({ abbreviation: 'li.hello|c' });
if (!promise) { if (!promise) {
assert.equal(1, 2, 'Wrap returned undefined instead of promise.'); assert.equal(1, 2, 'Wrap returned undefined instead of promise.');
return Promise.resolve(); return Promise.resolve();
} }
return promise.then(() => { return promise.then(() => {
assert.equal(editor.document.getText(), expectedContents); assert.equal(editor.document.getText(), expectedContents);
return Promise.resolve(); return Promise.resolve();
});
}); });
}); });
});
test('Wrap with abbreviation entire node when cursor is on opening tag', () => { test('Wrap with abbreviation entire node when cursor is on opening tag', () => {
const contents = ` const contents = `
<div class="nav main">
hello
</div>
`;
const expectedContents = `
<div>
<div class="nav main"> <div class="nav main">
hello hello
</div> </div>
`; </div>
const expectedContents = ` `;
<div>
<div class="nav main">
hello
</div>
</div>
`;
return withRandomFileEditor(contents, 'html', (editor, _) => { return withRandomFileEditor(contents, 'html', (editor, _) => {
editor.selections = [new Selection(1, 1, 1, 1)]; editor.selections = [new Selection(1, 1, 1, 1)];
const promise = wrapWithAbbreviation({ abbreviation: 'div' }); const promise = wrapWithAbbreviation({ abbreviation: 'div' });
if (!promise) { if (!promise) {
assert.equal(1, 2, 'Wrap returned undefined instead of promise.'); assert.equal(1, 2, 'Wrap returned undefined instead of promise.');
return Promise.resolve(); return Promise.resolve();
} }
return promise.then(() => { return promise.then(() => {
assert.equal(editor.document.getText(), expectedContents); assert.equal(editor.document.getText(), expectedContents);
return Promise.resolve(); return Promise.resolve();
});
}); });
}); });
});
test('Wrap with abbreviation entire node when cursor is on closing tag', () => { test('Wrap with abbreviation entire node when cursor is on closing tag', () => {
const contents = ` const contents = `
<div class="nav main">
hello
</div>
`;
const expectedContents = `
<div>
<div class="nav main"> <div class="nav main">
hello hello
</div> </div>
`; </div>
const expectedContents = ` `;
<div>
<div class="nav main">
hello
</div>
</div>
`;
return withRandomFileEditor(contents, 'html', (editor, _) => { return withRandomFileEditor(contents, 'html', (editor, _) => {
editor.selections = [new Selection(3, 1, 3, 1)]; editor.selections = [new Selection(3, 1, 3, 1)];
const promise = wrapWithAbbreviation({ abbreviation: 'div' }); const promise = wrapWithAbbreviation({ abbreviation: 'div' });
if (!promise) { if (!promise) {
assert.equal(1, 2, 'Wrap returned undefined instead of promise.'); assert.equal(1, 2, 'Wrap returned undefined instead of promise.');
return Promise.resolve(); return Promise.resolve();
} }
return promise.then(() => { return promise.then(() => {
assert.equal(editor.document.getText(), expectedContents); assert.equal(editor.document.getText(), expectedContents);
return Promise.resolve(); return Promise.resolve();
});
}); });
}); });
});
test('Wrap with multiline abbreviation doesnt add extra spaces', () => { test('Wrap with multiline abbreviation doesnt add extra spaces', () => {
// Issue #29898 // Issue #29898
const contents = ` const contents = `
hello hello
`; `;
const expectedContents = ` const expectedContents = `
<ul> <ul>
<li><a href="">hello</a></li> <li><a href="">hello</a></li>
</ul> </ul>
`; `;
return withRandomFileEditor(contents, 'html', (editor, _) => { return withRandomFileEditor(contents, 'html', (editor, _) => {
editor.selections = [new Selection(1, 2, 1, 2)]; editor.selections = [new Selection(1, 2, 1, 2)];
const promise = wrapWithAbbreviation({ abbreviation: 'ul>li>a' }); const promise = wrapWithAbbreviation({ abbreviation: 'ul>li>a' });
if (!promise) { if (!promise) {
assert.equal(1, 2, 'Wrap returned undefined instead of promise.'); assert.equal(1, 2, 'Wrap returned undefined instead of promise.');
return Promise.resolve(); return Promise.resolve();
} }
return promise.then(() => { return promise.then(() => {
assert.equal(editor.document.getText(), expectedContents); assert.equal(editor.document.getText(), expectedContents);
return Promise.resolve(); return Promise.resolve();
});
}); });
}); });
});
test('Wrap individual lines with abbreviation', () => { test('Wrap individual lines with abbreviation', () => {
const contents = ` const contents = `
<ul class="nav main"> <ul class="nav main">
<li class="item1">This $10 is not a tabstop</li> <li class="item1">This $10 is not a tabstop</li>
<li class="item2">hi.there</li> <li class="item2">hi.there</li>
</ul> </ul>
`; `;
const wrapIndividualLinesExpected = ` const wrapIndividualLinesExpected = `
<ul class="nav main"> <ul class="nav main">
<ul> <ul>
<li class="hello1"><li class="item1">This $10 is not a tabstop</li></li> <li class="hello1"><li class="item1">This $10 is not a tabstop</li></li>
<li class="hello2"><li class="item2">hi.there</li></li> <li class="hello2"><li class="item2">hi.there</li></li>
</ul>
</ul> </ul>
</ul>
`; `;
return withRandomFileEditor(contents, 'html', (editor, _) => { return withRandomFileEditor(contents, 'html', (editor, _) => {
editor.selections = [new Selection(2, 2, 3, 33)]; editor.selections = [new Selection(2, 2, 3, 33)];
const promise = wrapIndividualLinesWithAbbreviation({ abbreviation: 'ul>li.hello$*' }); const promise = wrapIndividualLinesWithAbbreviation({ abbreviation: 'ul>li.hello$*' });
if (!promise) { if (!promise) {
assert.equal(1, 2, 'Wrap Individual Lines with Abbreviation returned undefined.'); assert.equal(1, 2, 'Wrap Individual Lines with Abbreviation returned undefined.');
return Promise.resolve(); return Promise.resolve();
} }
return promise.then(() => { return promise.then(() => {
assert.equal(editor.document.getText(), wrapIndividualLinesExpected); assert.equal(editor.document.getText(), wrapIndividualLinesExpected);
return Promise.resolve(); return Promise.resolve();
});
}); });
}); });
});
test('Wrap individual lines with abbreviation with extra space selected', () => { test('Wrap individual lines with abbreviation with extra space selected', () => {
const contents = ` const contents = `
<ul class="nav main"> <ul class="nav main">
<li class="item1">img</li> <li class="item1">img</li>
<li class="item2">hi.there</li> <li class="item2">hi.there</li>
</ul>
`;
const wrapIndividualLinesExpected = `
<ul class="nav main">
<ul>
<li class="hello1"><li class="item1">img</li></li>
<li class="hello2"><li class="item2">hi.there</li></li>
</ul> </ul>
</ul>
`; `;
const wrapIndividualLinesExpected = ` return withRandomFileEditor(contents, 'html', (editor, _) => {
<ul class="nav main"> editor.selections = [new Selection(2, 1, 4, 0)];
<ul> const promise = wrapIndividualLinesWithAbbreviation({ abbreviation: 'ul>li.hello$*' });
<li class="hello1"><li class="item1">img</li></li> if (!promise) {
<li class="hello2"><li class="item2">hi.there</li></li> assert.equal(1, 2, 'Wrap Individual Lines with Abbreviation returned undefined.');
</ul> return Promise.resolve();
}
return promise.then(() => {
assert.equal(editor.document.getText(), wrapIndividualLinesExpected);
return Promise.resolve();
});
});
});
test('Wrap individual lines with abbreviation with comment filter', () => {
const contents = `
<ul class="nav main">
<li class="item1">img</li>
<li class="item2">hi.there</li>
</ul>
`;
const wrapIndividualLinesExpected = `
<ul class="nav main">
<ul>
<li class="hello"><li class="item1">img</li></li>
<!-- /.hello -->
<li class="hello"><li class="item2">hi.there</li></li>
<!-- /.hello -->
</ul> </ul>
</ul>
`; `;
return withRandomFileEditor(contents, 'html', (editor, _) => { return withRandomFileEditor(contents, 'html', (editor, _) => {
editor.selections = [new Selection(2, 1, 4, 0)]; editor.selections = [new Selection(2, 2, 3, 33)];
const promise = wrapIndividualLinesWithAbbreviation({ abbreviation: 'ul>li.hello$*' }); const promise = wrapIndividualLinesWithAbbreviation({ abbreviation: 'ul>li.hello*|c' });
if (!promise) { if (!promise) {
assert.equal(1, 2, 'Wrap Individual Lines with Abbreviation returned undefined.'); assert.equal(1, 2, 'Wrap Individual Lines with Abbreviation returned undefined.');
return Promise.resolve(); return Promise.resolve();
} }
return promise.then(() => { return promise.then(() => {
assert.equal(editor.document.getText(), wrapIndividualLinesExpected); assert.equal(editor.document.getText(), wrapIndividualLinesExpected);
return Promise.resolve(); return Promise.resolve();
});
}); });
}); });
});
test('Wrap individual lines with abbreviation with comment filter', () => { test('Wrap individual lines with abbreviation and trim', () => {
const contents = ` const contents = `
<ul class="nav main"> <ul class="nav main">
<li class="item1">img</li> • lorem ipsum
<li class="item2">hi.there</li> • lorem ipsum
</ul> </ul>
`; `;
const wrapIndividualLinesExpected = ` const wrapIndividualLinesExpected = `
<ul class="nav main"> <ul class="nav main">
<ul> <ul>
<li class="hello"><li class="item1">img</li></li> <li class="hello1">lorem ipsum</li>
<!-- /.hello --> <li class="hello2">lorem ipsum</li>
<li class="hello"><li class="item2">hi.there</li></li>
<!-- /.hello -->
</ul> </ul>
</ul> </ul>
`; `;
return withRandomFileEditor(contents, 'html', (editor, _) => { return withRandomFileEditor(contents, 'html', (editor, _) => {
editor.selections = [new Selection(2, 2, 3, 33)]; editor.selections = [new Selection(2, 3, 3, 16)];
const promise = wrapIndividualLinesWithAbbreviation({ abbreviation: 'ul>li.hello*|c' }); const promise = wrapIndividualLinesWithAbbreviation({ abbreviation: 'ul>li.hello$*|t' });
if (!promise) { if (!promise) {
assert.equal(1, 2, 'Wrap Individual Lines with Abbreviation returned undefined.'); assert.equal(1, 2, 'Wrap Individual Lines with Abbreviation returned undefined.');
return Promise.resolve(); return Promise.resolve();
} }
return promise.then(() => {
assert.equal(editor.document.getText(), wrapIndividualLinesExpected);
return Promise.resolve();
});
});
});
test('Wrap individual lines with abbreviation and trim', () => { return promise.then(() => {
const contents = ` assert.equal(editor.document.getText(), wrapIndividualLinesExpected);
<ul class="nav main"> return Promise.resolve();
• lorem ipsum
• lorem ipsum
</ul>
`;
const wrapIndividualLinesExpected = `
<ul class="nav main">
<ul>
<li class="hello1">lorem ipsum</li>
<li class="hello2">lorem ipsum</li>
</ul>
</ul>
`;
return withRandomFileEditor(contents, 'html', (editor, _) => {
editor.selections = [new Selection(2, 3, 3, 16)];
const promise = wrapIndividualLinesWithAbbreviation({ abbreviation: 'ul>li.hello$*|t' });
if (!promise) {
assert.equal(1, 2, 'Wrap Individual Lines with Abbreviation returned undefined.');
return Promise.resolve();
}
return promise.then(() => {
assert.equal(editor.document.getText(), wrapIndividualLinesExpected);
return Promise.resolve();
});
}); });
}); });
});
test('Wrap with abbreviation and format set to false', () => { test('Wrap with abbreviation and format set to false', () => {
return workspace.getConfiguration('emmet').update('syntaxProfiles',{ 'html' : { 'format': false } } , ConfigurationTarget.Global).then(() => { return workspace.getConfiguration('emmet').update('syntaxProfiles',{ 'html' : { 'format': false } } , ConfigurationTarget.Global).then(() => {
...@@ -384,11 +400,19 @@ suite('Tests for Wrap with Abbreviations', () => { ...@@ -384,11 +400,19 @@ suite('Tests for Wrap with Abbreviations', () => {
return testWrapWithAbbreviation([new Selection(2, 4, 3, 9), new Selection(5, 4, 6, 9)], 'div', wrapMultiLineExpected, htmlContentsForWrapMultiLineTests); return testWrapWithAbbreviation([new Selection(2, 4, 3, 9), new Selection(5, 4, 6, 9)], 'div', wrapMultiLineExpected, htmlContentsForWrapMultiLineTests);
}); });
test('Wrap multiline with abbreviation uses className for jsx files', () => {
return testWrapWithAbbreviation([new Selection(2,2,3,33)], '.hello', wrapMultiLineJsxExpected, htmlContentsForWrapTests, 'jsx');
});
test('Wrap individual line with abbreviation uses className for jsx files', () => {
return testWrapIndividualLinesWithAbbreviation([new Selection(2,2,3,33)], '.hello$*', wrapIndividualLinesJsxExpected, htmlContentsForWrapTests, 'jsx');
});
}); });
function testWrapWithAbbreviation(selections: Selection[], abbreviation: string, expectedContents: string, input: string = htmlContentsForWrapTests): Thenable<any> { function testWrapWithAbbreviation(selections: Selection[], abbreviation: string, expectedContents: string, input: string = htmlContentsForWrapTests, fileExtension: string = 'html'): Thenable<any> {
return withRandomFileEditor(input, 'html', (editor, _) => { return withRandomFileEditor(input, fileExtension, (editor, _) => {
editor.selections = selections; editor.selections = selections;
const promise = wrapWithAbbreviation({ abbreviation }); const promise = wrapWithAbbreviation({ abbreviation });
if (!promise) { if (!promise) {
...@@ -402,3 +426,19 @@ function testWrapWithAbbreviation(selections: Selection[], abbreviation: string, ...@@ -402,3 +426,19 @@ function testWrapWithAbbreviation(selections: Selection[], abbreviation: string,
}); });
}); });
} }
function testWrapIndividualLinesWithAbbreviation(selections: Selection[], abbreviation: string, expectedContents: string, input: string = htmlContentsForWrapTests, fileExtension: string = 'html'): Thenable<any> {
return withRandomFileEditor(input, fileExtension, (editor, _) => {
editor.selections = selections;
const promise = wrapIndividualLinesWithAbbreviation({ abbreviation });
if (!promise) {
assert.equal(1, 2, 'Wrap individual lines with Abbreviation returned undefined.');
return Promise.resolve();
}
return promise.then(() => {
assert.equal(editor.document.getText(), expectedContents);
return Promise.resolve();
});
});
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册