Skip to content

Commit

Permalink
Merge pull request #122 from ckeditor/t/118
Browse files Browse the repository at this point in the history
Fix e2e tests
  • Loading branch information
Dumluregn authored Jul 29, 2020
2 parents 41145bc + 3f96ad6 commit 4fff407
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 32 deletions.
2 changes: 1 addition & 1 deletion e2e/protractor.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@ exports.config = {
});
jasmine.getEnv().addReporter(new SpecReporter({ spec: { displayStacktrace: true } }));
}
};
};
22 changes: 9 additions & 13 deletions e2e/src/app.e2e-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ describe( 'workspace-project App', () => {
expect( page.getParagraphText() ).toEqual( 'CKEditor 4 integration with Angular' );
} );

it( 'should display editor with initial content', async () => {
it( 'should display editor with initial content', () => {
editables.forEach( editable => expect( page.getHtmlString( editable ) )
.toBe( '<p>Getting used to an entirely different culture can be challeng' +
'ing. While it’s also nice to learn about cultures online or from books, nothing comes close to experiencing cultural d' +
Expand All @@ -37,8 +37,8 @@ describe( 'workspace-project App', () => {
} );

describe( 'typing', () => {
it( `in editor1 should update editors content`, testTyping( editables, 0 ) );
it( `in editor2 should update editors content`, testTyping( editables, 1 ) );
it( `in editor1 should update editors content`, testTyping( 0 ) );
it( `in editor2 should update editors content`, testTyping( 1 ) );
} );
} );

Expand All @@ -51,27 +51,23 @@ describe( 'workspace-project App', () => {
editables = [ await page.getEditable() ];
} );

it( 'should display editor with initial content', async () => {
it( 'should display editor with initial content', () => {
expect( page.getHtmlString( editables[ 0 ] ) )
.toBe( '<p>A <strong>really</strong> nice fellow.</p>' );
} );

it( `typing should update editor content`, testTyping( editables, 0 ) );
it( `typing should update editor content`, testTyping( 0 ) );
} );

function testTyping( elements, elementIndex: number ) {
function testTyping( elementIndex: number ) {
return async function() {
const keys = [
'Foo! ',
protractor.Key.chord( protractor.Key.CONTROL, 'b' ),
'Bar?'
];
const text = 'Foo! Bar?';

await page.updateValue( editables[ elementIndex ], keys );
await page.updateValue( editables[ elementIndex ], text );

editables.forEach( item => {
expect( page.getHtmlString( item ) )
.toBe( '<p>Foo!&nbsp;<strong>Bar?</strong></p>' );
.toBe( '<p>Foo! Bar?</p>' );
} );
};
}
Expand Down
26 changes: 9 additions & 17 deletions e2e/src/app.po.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ export class AppPage {
return element( by.css( 'app-root h1' ) ).getText();
}

waitForElement( el: ElementFinder ) {
async waitForElement( el: ElementFinder ) {
return browser.wait( protractor.ExpectedConditions.presenceOf( el ) ).then( () => el );
}

async getEditable() {
return this.getElementByCss( '.cke_editable:not(.cke_editable_inline)' );
}

getInlineEditable() {
async getInlineEditable() {
return this.getElementByCss( '.cke_editable_inline' );
}

Expand All @@ -32,24 +32,16 @@ export class AppPage {
return el;
}

getHtmlString( el: WebElement ) {
return el.getAttribute( 'innerHTML' ).then( str => str.replace( /\u200B/g, '' ) );
async getHtmlString( el: WebElement ) {
return el.getAttribute( 'innerHTML' );
}

async updateValue( el: WebElement, keys: string[] ) {
async updateValue( el: WebElement, text: string ) {
await el.clear();
await el.click();
await this.selectAll();
// Since Chrome 77 with webdirver-manager@12.1.7 protractor.sendKeys() doesn't
// clear current selection, we have to clean it manually (#51).
await this.delete();
await el.sendKeys( ...keys );
}

selectAll() {
return browser.executeScript( 'document.execCommand( "selectAll", false, null )' );
}

delete() {
return browser.executeScript( 'document.execCommand( "delete", false, null )' );
for ( let i = 0; i < text.length; i++ ) {
await el.sendKeys( text.charAt( i ) );
}
}
}
3 changes: 2 additions & 1 deletion src/app/demo-form/demo-form.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ <h3>User profile form</h3>
<ckeditor
[(ngModel)]="model.description"
id="description"
name="description">
name="description"
type="divarea">
</ckeditor>

<p *ngIf="description && description.dirty" class="alert">Description is "dirty".</p>
Expand Down

0 comments on commit 4fff407

Please sign in to comment.