Skip to content

Commit

Permalink
Add tests for indent levels
Browse files Browse the repository at this point in the history
  • Loading branch information
Ben Jervis committed Feb 13, 2024
1 parent 2c5cfd2 commit c964fbb
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 7 deletions.
59 changes: 54 additions & 5 deletions cypress/e2e/keymaps.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
assertCodePaneContains,
loadPlayroom,
selectNextWords,
selectLines,
selectNextLines,
selectNextCharacters,
selectToStartOfLine,
selectToEndOfLine,
Expand Down Expand Up @@ -70,7 +70,7 @@ describe('Keymaps', () => {

it('should swap multiple lines up and down with a selection', () => {
typeCode('{rightArrow}');
selectLines(1);
selectNextLines(1);
selectNextCharacters(3);

typeCode('{alt+downArrow}');
Expand Down Expand Up @@ -298,7 +298,7 @@ describe('Keymaps', () => {
typeCode(`{${modifierKey}+alt+downArrow}`);
typeCode('{shift+alt+downArrow}{upArrow}');

selectLines(1);
selectNextLines(1);
selectToEndOfLine();

typeCode(`{shift+${modifierKey}+,}`);
Expand Down Expand Up @@ -380,11 +380,35 @@ describe('Keymaps', () => {
<div>Third line</div>
`);
});

it('and respect indent levels', () => {
loadPlayroom(`
<div>
<div>First line</div>
<div>Second line</div>
<div>Third line</div>
</div>
`);

moveBy(0, 1);
selectToEndOfLine();

typeComment();
typeCode('c');

assertCodePaneContains(dedent`
<div>
{/* c */}
<div>Second line</div>
<div>Third line</div>
</div>
`);
});
});

describe('should wrap a multi line selection in a block comment', () => {
it('standard', () => {
selectLines(3);
selectNextLines(3);

typeComment();

Expand All @@ -397,7 +421,7 @@ describe('Keymaps', () => {

it('when the lines are only partially selected', () => {
moveBy(5);
selectLines(2);
selectNextLines(1);

typeComment();

Expand All @@ -408,6 +432,31 @@ describe('Keymaps', () => {
`);
});

it('and respect indent levels', () => {
loadPlayroom(`
<div>
<div>First line</div>
<div>Second line</div>
<div>Third line</div>
</div>
`);

moveBy(0, 1);
moveBy(7);
selectNextLines(1);
selectNextWords(1);

typeComment();
typeCode('c');

assertCodePaneContains(dedent`
<div>
{/* <div>c line</div> */}
<div>Third line</div>
</div>
`);
});

// TODO: Update this to handle non-selections
it.skip('should not create a comment when there is no selection', () => {
typeComment();
Expand Down
7 changes: 5 additions & 2 deletions cypress/support/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,11 @@ export const selectToEndOfLine = () => {
* @param {number | undefined} y
*/
export const moveBy = (x, y = 0) => {
const xDirection = x >= 0 ? '{rightArrow}' : '{leftArrow}';
typeCode(xDirection.repeat(x));
if (x) {
const xDirection = x >= 0 ? '{rightArrow}' : '{leftArrow}';
typeCode(xDirection.repeat(x));
}

if (y) {
const yDirection = y >= 0 ? '{downArrow}' : '{upArrow}';
typeCode(yDirection.repeat(y));
Expand Down

0 comments on commit c964fbb

Please sign in to comment.