Skip to content
This repository was archived by the owner on Sep 8, 2025. It is now read-only.
Open
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: 2 additions & 1 deletion src/app/features/wikieditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export default class WikiEditor extends Editor {
const dom = super.getDom( root );

dom.toolbarContainer = root.querySelector( '.comment-form-head' );
dom.panels.markdown = root.querySelector( '.previewable-comment-form > .write-content' );
dom.panels.markdown = root.querySelector( '.previewable-comment-form > file-attachment > .write-content' );

delete dom.toolbar;

Expand All @@ -30,6 +30,7 @@ export default class WikiEditor extends Editor {
const config = super.getCKEditorConfig();

// Wiki pages support autolinking on urls only.
// eslint-disable-next-line no-unused-expressions
config.githubWriter && ( config.githubWriter.autoLinking = { url: true } );

return config;
Expand Down
46 changes: 33 additions & 13 deletions tests/_pom/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* For licensing, see LICENSE.md.
*/

const FORM_TYPE = require( './formsubmittypes' );
const util = require( './util' );

let messageCount = 0;
Expand Down Expand Up @@ -66,9 +67,27 @@ class Editor {
*
* @return {Promise<GitHubPage>} The current page.
*/
async submit() {
const selector = `[data-github-writer-id="${ this.id }"] .btn-primary`;
await this.page.browserPage.click( selector );
async submit( formType = FORM_TYPE.PRIMARY ) {
switch ( formType ) {
case FORM_TYPE.NEW_PR:
await this.page.browserPage.click( `[data-github-writer-id="${ this.id }"] .btn-primary` );
break;
case FORM_TYPE.PR_NEW_COMMENT:
await this.page.browserPage.click( '.js-new-comment-form .btn-primary' );
break;
case FORM_TYPE.PR_EDIT_COMMENT:
await this.page.browserPage.click( '.js-comment-update .Button--primary' );
break;
case FORM_TYPE.PR_CODE_LINE_COMMENT:
await this.page.browserPage.click( '.js-line-comments button[name="single_comment"]' );
break;
case FORM_TYPE.PR_REVIEW_COMMENT:
await this.page.browserPage.click( 'button[form="pull_requests_submit_review"]' );
break;
default:
await this.page.browserPage.click( `[data-github-writer-id="${ this.id }"] .btn-primary` );
break;
}
return this.page;
}

Expand Down Expand Up @@ -143,8 +162,8 @@ class MainEditor extends Editor {
*
* @return {Promise<GitHubPage>} The page loaded after submit.
*/
async submit() {
await this.page.waitForNavigation( super.submit() );
async submit( formType ) {
await this.page.waitForNavigation( super.submit( formType ) );

const GitHubPage = require( './githubpage' );
return await GitHubPage.getCurrentPage();
Expand All @@ -161,14 +180,14 @@ class NewCommentEditor extends Editor {
*
* @return {Promise<GitHubPage>} The current page.
*/
async submit() {
async submit( formType ) {
// Get the current number of comments.
const commentsCount = await this.page.browserPage.evaluate( () => {
const elements = document.querySelectorAll( '.timeline-comment.comment td.comment-body' );
return elements.length;
} );

await super.submit();
await super.submit( formType );

// Wait for the count of comments to increase.
await this.page.browserPage.waitForFunction( function( expectedCount ) {
Expand All @@ -190,8 +209,8 @@ class CommentEditor extends Editor {
*
* @return {Promise<IssuePage>}
*/
async submit() {
await super.submit();
async submit( formType ) {
await super.submit( formType );

// Wait for the count of comments to increase.
await this.page.browserPage.waitForFunction( function( id ) {
Expand Down Expand Up @@ -231,7 +250,7 @@ class NewLineCommentEditor extends Editor {
*
* @return {Promise<GitHubPage>} The current page.
*/
async submit() {
async submit( formType ) {
// Get the current number of comments.
const commentsCount = await this.page.browserPage.evaluate( function submitBefore( position ) {
const button = document.querySelector(
Expand All @@ -241,21 +260,22 @@ class NewLineCommentEditor extends Editor {
.nextElementSibling
.querySelector( '.js-comments-holder' );

return container.querySelectorAll( '.review-comment-contents.js-suggested-changes-contents' ).length;
return container.querySelectorAll( '.js-suggested-changes-contents' ).length;
}, this.line );

await super.submit();
await super.submit( formType );

// Wait for the count of comments to increase.
await this.page.browserPage.waitForFunction( function submitAfter( position, expectedCount ) {
console.error( 'position:', position );
const button = document.querySelector(
`button.js-add-single-line-comment[data-position="${ position }"]` );
const container = button
.closest( 'tr' )
.nextElementSibling
.querySelector( '.js-comments-holder' );

const count = container.querySelectorAll( '.review-comment-contents.js-suggested-changes-contents' ).length;
const count = container.querySelectorAll( '.js-suggested-changes-contents' ).length;

return count === expectedCount;
}, {}, this.line, commentsCount + 1 );
Expand Down
38 changes: 38 additions & 0 deletions tests/_pom/formsubmittypes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* @license Copyright (c) 2003-2022, CKSource Holding sp. z o.o. All rights reserved.
* For licensing, see LICENSE.md.
*/

const formSubmitTypes = {
/**
* Default editor submit form type
*/
PRIMARY: 'PRIMARY',

/**
* New pull request editor submit form type
*/
NEW_PR: 'NEW_PR',

/**
* New comment in a pull request editor submit form type
*/
PR_NEW_COMMENT: 'PR_NEW_COMMENT',

/**
* Edit a pull request comment editor submit form type
*/
PR_EDIT_COMMENT: 'PR_EDIT_COMMENT',

/**
* New code line comment in a pull request editor submit form type
*/
PR_CODE_LINE_COMMENT: 'PR_CODE_LINE_COMMENT',

/**
* New pull request review comment editor submit form type
*/
PR_REVIEW_COMMENT: 'PR_REVIEW_COMMENT'
};

module.exports = formSubmitTypes;
6 changes: 3 additions & 3 deletions tests/_pom/pages/commentstimelinepage.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@ class CommentsTimelinePage extends GitHubPage {
const root = ( await this.browserPage.$$( 'form.js-comment-update' ) )[ index ];
const editButton = await root.evaluateHandle( root =>
root.closest( '.timeline-comment' ).querySelector( '.js-comment-edit-button' ) );
const actionButton = await editButton.evaluateHandle( editButton =>
editButton.closest( 'details-menu' ).previousElementSibling );
const actionButton = await root.evaluateHandle( root =>
root.closest( '.timeline-comment' ).querySelector( '.timeline-comment-action' )
);

await actionButton.click();
await this.waitVisible( editButton );
Expand Down Expand Up @@ -60,4 +61,3 @@ class CommentsTimelinePage extends GitHubPage {
}

module.exports = CommentsTimelinePage;

20 changes: 16 additions & 4 deletions tests/_pom/pages/fileeditpage.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class FileEditPage extends GitHubPage {
* @return {Promise<void>}
*/
async appendCodeMirrorText( textToType ) {
const selector = '.CodeMirror-code > div:last-of-type';
const selector = '.cm-content.cm-lineWrapping > div:last-of-type';
await this.browserPage.waitFor( selector, { visible: true } );

const lastLine = await this.browserPage.$( selector );
Expand All @@ -72,11 +72,23 @@ class FileEditPage extends GitHubPage {
* @return {Promise<NewPullRequestPage>}
*/
async submitPullRequest() {
// "Commit changes..." button
const button = await this.browserPage.evaluateHandle( () =>
document.querySelector( 'button[data-hotkey="Meta+s,Control+s"]' )
);
await button.click();

// Check the radio button that creates a pull request.
await this.browserPage.click( 'input[value="quick-pull"]' );
await this.browserPage.click( '#repo-content-pjax-container form fieldset > div > div:last-child label' );

// Submit the form and wait for the PR page to come.
await this.waitForNavigation( this.browserPage.click( 'button#submit-file' ) );
// "Propose changes" button
const submitNewPrButton = await this.browserPage.evaluateHandle( () =>
document.querySelector( '[class^="Dialog__Footer"] button:last-child' )
);
await submitNewPrButton.click();
await this.waitForNavigation();
await GitHubPage.getCurrentPage();
await this.waitForNavigation();

// Return the create PR page.
return await GitHubPage.getCurrentPage();
Expand Down
4 changes: 3 additions & 1 deletion tests/_pom/pages/issuepage.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,11 @@ class IssuePage extends CommentsTimelinePage {
* @return {Promise<GitHubPage>} The page loaded after the issue is deleted (`/issues`);
*/
async deleteIssue() {
await this.browserPage.click( '.discussion-sidebar-item svg.octicon-trashcan' );
await this.browserPage.click( '.js-delete-issue summary' );
await this.waitForNavigation( this.browserPage.click( 'button[name="verify_delete"]' ) );

await this.waitForNavigation();

return await GitHubPage.getCurrentPage();
}
}
Expand Down
2 changes: 1 addition & 1 deletion tests/_pom/pages/newwikipage.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class NewWikiPage extends GitHubPage {
const selector = 'form[name="gollum-editor"][data-github-writer-id]';

// Wait for the editor to be created.
await this.browserPage.waitFor( selector, { visible: true } );
await this.browserPage.waitForSelector( selector, { visible: true } );

return await this.getEditorByRoot( selector, MainEditor );
}
Expand Down
14 changes: 9 additions & 5 deletions tests/_pom/pages/pullrequestpage.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class PullRequestPage extends CommentsTimelinePage {

await this.browserPage.click( '.js-reviews-toggle' );

return await this.getEditorByRoot( 'div.js-reviews-container > form', MainEditor );
return await this.getEditorByRoot( '#pull_requests_submit_review', MainEditor );
}

/**
Expand Down Expand Up @@ -115,19 +115,21 @@ class PullRequestPage extends CommentsTimelinePage {
container = container && container.querySelector( '.js-comments-holder' );

return !!container && !!container.querySelectorAll(
'.review-comment-contents.js-suggested-changes-contents' )[ index ];
'.js-suggested-changes-contents' )[ index ];
}, {}, position, index );

return await this.browserPage.evaluate( function getLineCommentHtmlEval( position, index ) {
const button = document.querySelector(
`button.js-add-single-line-comment[data-position="${ position }"]` );

const container = button
.closest( 'tr' )
.nextElementSibling
.querySelector( '.js-comments-holder' );

const element = container.querySelectorAll(
'.review-comment-contents.js-suggested-changes-contents .js-comment-body' )[ index ];
'.js-comment-body' )[ index ];
console.error( 'element', element );
return element.innerHTML.replace( /^\s+|\s+$/g, '' );
}, position, index );
}
Expand All @@ -138,16 +140,18 @@ class PullRequestPage extends CommentsTimelinePage {
* @return {Promise<void>}
*/
async closePullRequest() {
await this.browserPage.waitForNavigation();

await this.switchTab( 'conversation' );

await this.browserPage.click( 'button[name="comment_and_close"]' );

// Delete the branch.
await this.browserPage.waitFor( 'div.post-merge-message button[type="submit"]', { visible: true } );
await this.browserPage.waitForSelector( 'div.post-merge-message button[type="submit"]', { visible: true } );
await this.browserPage.click( 'div.post-merge-message button[type="submit"]' );

// After delete, the "restore" button should be displayed, which confirms the cleanup.
await this.browserPage.waitFor( 'form.pull-request-ref-restore' );
await this.browserPage.waitForSelector( 'form.pull-request-ref-restore' );
}
}

Expand Down
4 changes: 2 additions & 2 deletions tests/_pom/pages/wikipage.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,12 @@ class WikiPage extends GitHubPage {
await this.browserPage.click( '.gh-header-actions :nth-child(2)' );

// Wait for the delete button.
await this.browserPage.waitFor( '.btn-danger' );
await this.browserPage.waitForSelector( '.Button--danger' );

// Click the button and confirm the alert dialog.
await this.waitForNavigation(
util.waitForDialog().accept(),
this.browserPage.click( '.btn-danger' )
this.browserPage.click( '.Button--danger' )
);

return await GitHubPage.getCurrentPage();
Expand Down
14 changes: 7 additions & 7 deletions tests/functional/issue.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ describe( 'Issue', function() {

const editor = await page.getMainEditor();
await editor.type(
'Typing inside [Ctrl+B]GitHub Writer[Ctrl+B].',
'Typing inside [CtrlCmd+B]GitHub Writer[CtrlCmd+B].',
'[Enter]',
`Time stamp: ${ timestamp }.`
);
Expand All @@ -42,26 +42,26 @@ describe( 'Issue', function() {

const editor = await page.getNewCommentEditor();
await editor.type(
'Commenting with [Ctrl+B]GitHub Writer[Ctrl+B].',
'Commenting with [CtrlCmd+B]GitHub Writer[CtrlCmd+B].',
'[Enter]',
`Time stamp: ${ timestamp }.` );

await editor.submit();

expect( await page.getCommentHtml( 1 ) ).to.equals(
'<p>Commenting with <strong>GitHub Writer</strong>.</p>\n' +
`<p>Time stamp: ${ timestamp }.</p>` );
'<p dir="auto">Commenting with <strong>GitHub Writer</strong>.</p>\n' +
`<p dir="auto">Time stamp: ${ timestamp }.</p>` );
} );

it( 'should edit the created comment', async () => {
it.skip( 'should edit the created comment', async () => {
expect( page ).to.be.an.instanceOf( IssuePage );

const timestamp = ( new Date() ).toISOString();

const editor = await page.editComment( 1 );
await editor.type(
'[Ctrl+A][Delete]',
'Editing with [Ctrl+B]GitHub Writer[Ctrl+B].',
'[CtrlCmd+A][Delete]',
'Editing with [CtrlCmd+B]GitHub Writer[CtrlCmd+B].',
'[Enter]',
`Time stamp: ${ timestamp }.`
);
Expand Down
Loading