Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
10 changes: 5 additions & 5 deletions admin/godam-transcoder-functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -488,10 +488,10 @@ function rtgodam_add_status_columns_content( $column_name, $post_id ) {
</svg>
</div>
<?php if ( ! empty( $failure ) ) : ?>
<span class="status-text"><?php echo esc_html( $failure['message'] ); ?></span>
<span class="status-text" data-test-id="godam-transcode-failure-reason"><?php echo esc_html( $failure['message'] ); ?></span>
<?php rtgodam_render_transcoding_next_step( $failure ); ?>
<?php else : ?>
<span class="status-text"><?php esc_html_e( 'Transcoding failed, please try again.', 'godam' ); ?></span>
<span class="status-text" data-test-id="godam-transcode-failure-reason"><?php esc_html_e( 'Transcoding failed, please try again.', 'godam' ); ?></span>
<?php endif; ?>
</div>
<?php
Expand Down Expand Up @@ -536,14 +536,14 @@ function rtgodam_render_transcoding_next_step( $failure ) {
return;
}
?>
<span class="status-next-step">
<span class="status-next-step" data-test-id="godam-transcode-next-step">
<?php if ( ! empty( $failure['next_step'] ) && ! empty( $failure['next_step_url'] ) ) : ?>
<a href="<?php echo esc_url( $failure['next_step_url'] ); ?>" target="_blank" rel="noopener noreferrer"><?php echo esc_html( $failure['next_step'] ); ?></a>
<a href="<?php echo esc_url( $failure['next_step_url'] ); ?>" target="_blank" rel="noopener noreferrer" data-test-id="godam-transcode-next-step-link"><?php echo esc_html( $failure['next_step'] ); ?></a>
<?php elseif ( ! empty( $failure['next_step'] ) ) : ?>
<?php echo esc_html( $failure['next_step'] ); ?>
<?php endif; ?>
<?php if ( ! empty( $failure['support_url'] ) ) : ?>
<a href="<?php echo esc_url( $failure['support_url'] ); ?>" target="_blank" rel="noopener noreferrer"><?php esc_html_e( 'Contact support', 'godam' ); ?></a>
<a href="<?php echo esc_url( $failure['support_url'] ); ?>" target="_blank" rel="noopener noreferrer" data-test-id="godam-transcode-support-link"><?php esc_html_e( 'Contact support', 'godam' ); ?></a>
<?php endif; ?>
</span>
<?php
Expand Down
17 changes: 14 additions & 3 deletions assets/src/js/media-library/transcoding-status/failure.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,23 @@ export const isLinkable = ( url ) => typeof url === 'string' && /^https?:\/\//i.
/**
* Build a link that opens in a new tab.
*
* @since n.e.x.t Takes an optional `testId`.
*
* @param {string} href URL.
* @param {string} text Link text.
* @param {string} className Optional class name.
* @param {string} testId Optional `data-test-id`, for the E2E tests.
*
* @return {HTMLAnchorElement} The link.
*/
export const link = ( href, text, className = '' ) => {
export const link = ( href, text, className = '', testId = '' ) => {
const anchor = document.createElement( 'a' );
if ( className ) {
anchor.className = className;
}
if ( testId ) {
anchor.setAttribute( 'data-test-id', testId );
}
anchor.href = href;
anchor.target = '_blank';
anchor.rel = 'noopener noreferrer';
Expand Down Expand Up @@ -58,9 +64,10 @@ export const renderNextStep = ( container, failure ) => {

const line = document.createElement( 'span' );
line.className = NEXT_STEP_CLASS;
line.setAttribute( 'data-test-id', 'godam-transcode-next-step' );

if ( failure.next_step && isLinkable( failure.next_step_url ) ) {
line.append( link( failure.next_step_url, failure.next_step ) );
line.append( link( failure.next_step_url, failure.next_step, '', 'godam-transcode-next-step-link' ) );
} else if ( failure.next_step ) {
line.append( document.createTextNode( failure.next_step ) );
}
Expand All @@ -69,7 +76,7 @@ export const renderNextStep = ( container, failure ) => {
if ( line.childNodes.length ) {
line.append( document.createTextNode( ' ' ) );
}
line.append( link( failure.support_url, __( 'Contact support', 'godam' ) ) );
line.append( link( failure.support_url, __( 'Contact support', 'godam' ), '', 'godam-transcode-support-link' ) );
}

container.append( line );
Expand All @@ -88,6 +95,8 @@ export const cssString = ( text ) => JSON.stringify( String( text ) );
* Put a failed file's reason on its grid status icon: in the hover tooltip, and as the
* icon's accessible name. With no reason, the stylesheet's generic label shows instead.
*
* @since n.e.x.t Marks the icon with a `data-test-id` while it carries a reason.
*
* @param {HTMLElement} loader The `.transcoding-status__loader` element.
* @param {string} message Why it failed, from the server.
*/
Expand All @@ -101,11 +110,13 @@ export const setFailureText = ( loader, message ) => {
loader.removeAttribute( 'title' );
loader.removeAttribute( 'aria-label' );
loader.removeAttribute( 'role' );
loader.removeAttribute( 'data-test-id' );
return;
}

loader.style.setProperty( '--status-text', cssString( message ) );
loader.setAttribute( 'title', message );
loader.setAttribute( 'role', 'img' );
loader.setAttribute( 'aria-label', message );
loader.setAttribute( 'data-test-id', 'godam-transcode-failure-tooltip' );
};
38 changes: 38 additions & 0 deletions assets/src/js/media-library/transcoding-status/failure.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/**
* Unit tests for the grid view's failure tooltip on the transcode status icon.
*/

/**
* Internal dependencies
*/
import { setFailureText } from './failure';

describe( 'setFailureText', () => {
let loader;

beforeEach( () => {
document.body.innerHTML = '<div class="transcoding-status__loader"></div>';
loader = document.querySelector( '.transcoding-status__loader' );
} );

it( 'puts the reason in the tooltip and marks the icon for the E2E tests', () => {
setFailureText( loader, 'Your GoDAM storage is full.' );

expect( loader.style.getPropertyValue( '--status-text' ) ).toBe( '"Your GoDAM storage is full."' );
expect( loader.getAttribute( 'aria-label' ) ).toBe( 'Your GoDAM storage is full.' );
expect( loader.getAttribute( 'data-test-id' ) ).toBe( 'godam-transcode-failure-tooltip' );
} );

it( 'clears the reason and the test ID when there is none', () => {
setFailureText( loader, 'Your GoDAM storage is full.' );
setFailureText( loader, '' );

expect( loader.style.getPropertyValue( '--status-text' ) ).toBe( '' );
expect( loader.hasAttribute( 'aria-label' ) ).toBe( false );
expect( loader.hasAttribute( 'data-test-id' ) ).toBe( false );
} );

it( 'does nothing without an icon', () => {
expect( () => setFailureText( null, 'x' ) ).not.toThrow();
} );
} );
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,9 @@ class ListViewTranscodingStatus {

const statusText = element.querySelector( '.status-text' );

// Only a failed or stuck file has a next step.
// Only a failed or stuck file has a next step, and a reason to point the tests at.
renderNextStep( element, null );
statusText.removeAttribute( 'data-test-id' );

// Handle failed transcoding state
if ( data.status === 'failed' ) {
Expand Down Expand Up @@ -203,6 +204,7 @@ class ListViewTranscodingStatus {
const failureMessage = data.error_msg || __( 'Transcoding failed, please try again.', 'godam' );
loader.style.setProperty( '--status-text', cssString( failureMessage ) );
statusText.textContent = failureMessage;
statusText.setAttribute( 'data-test-id', 'godam-transcode-failure-reason' );

renderNextStep( element, data.failure );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,4 +125,34 @@ describe( 'ListViewTranscodingStatus — failed state', () => {

expect( document.querySelector( '#list-transcoder-status-55 .status-next-step' ) ).toBeNull();
} );

it( 'marks the reason, next step and links for the E2E tests', () => {
render();

new ListViewTranscodingStatus().updateAttachmentStatus( '55', {
status: 'failed',
error_msg: 'Your GoDAM storage is full.',
failure: {
next_step: 'Upgrade plan',
next_step_url: 'https://app.godam.io/plans',
support_url: 'https://app.godam.io/helpdesk/my-tickets',
},
} );

const element = document.querySelector( '#list-transcoder-status-55' );
expect( element.querySelector( '[data-test-id="godam-transcode-failure-reason"]' ).textContent ).toBe( 'Your GoDAM storage is full.' );
expect( element.querySelector( '[data-test-id="godam-transcode-next-step"]' ) ).not.toBeNull();
expect( element.querySelector( '[data-test-id="godam-transcode-next-step-link"]' ).href ).toBe( 'https://app.godam.io/plans' );
expect( element.querySelector( '[data-test-id="godam-transcode-support-link"]' ).href ).toBe( 'https://app.godam.io/helpdesk/my-tickets' );
} );

it( 'drops the reason\'s test ID once the file transcodes', () => {
render();
const status = new ListViewTranscodingStatus();

status.updateAttachmentStatus( '55', { status: 'failed', error_msg: 'x' } );
status.updateAttachmentStatus( '55', { status: 'transcoded', progress: 100 } );

expect( document.querySelector( '[data-test-id^="godam-transcode-"]' ) ).toBeNull();
} );
} );
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,30 @@ import { isLinkable, link } from '../../transcoding-status/failure';

const PANEL_CLASS = 'godam-transcoding-refusal';

/**
* Prefix of the panel's `data-test-id`s, for the E2E tests.
*/
const TEST_ID = 'godam-transcode-failure-panel';

/**
* Build an element with a class and optional text.
*
* @since n.e.x.t Takes an optional `testId`.
*
* @param {string} tag Tag name.
* @param {string} className Class name.
* @param {string} text Text content.
* @param {string} testId Optional `data-test-id`.
*
* @return {HTMLElement} The element.
*/
const el = ( tag, className, text = '' ) => {
const el = ( tag, className, text = '', testId = '' ) => {
const node = document.createElement( tag );
node.className = className;
node.textContent = text;
if ( testId ) {
node.setAttribute( 'data-test-id', testId );
}

return node;
};
Expand Down Expand Up @@ -134,37 +145,37 @@ const renderTranscodingRefusalPanel = ( view ) => {
return;
}

const panel = el( 'div', PANEL_CLASS );
const panel = el( 'div', PANEL_CLASS, '', TEST_ID );
panel.setAttribute( 'role', 'status' );

panel.append(
el( 'p', `${ PANEL_CLASS }__title`, titleFor( failure.kind ) ),
el( 'p', `${ PANEL_CLASS }__reason`, failure.message ),
el( 'p', `${ PANEL_CLASS }__title`, titleFor( failure.kind ), `${ TEST_ID }-title` ),
el( 'p', `${ PANEL_CLASS }__reason`, failure.message, `${ TEST_ID }-reason` ),
);

// "Upload a smaller file" and the like: nothing to click, so say it.
if ( failure.next_step && ! failure.next_step_url && String( failure.action ).startsWith( 'upload_' ) ) {
panel.append( el( 'p', `${ PANEL_CLASS }__next-step`, failure.next_step ) );
panel.append( el( 'p', `${ PANEL_CLASS }__next-step`, failure.next_step, `${ TEST_ID }-next-step` ) );
}

const actions = el( 'div', `${ PANEL_CLASS }__actions` );
const status = el( 'p', `${ PANEL_CLASS }__status` );
const status = el( 'p', `${ PANEL_CLASS }__status`, '', `${ TEST_ID }-status` );

if ( failure.next_step && isLinkable( failure.next_step_url ) ) {
actions.append( link( failure.next_step_url, failure.next_step, 'button' ) );
actions.append( link( failure.next_step_url, failure.next_step, 'button', `${ TEST_ID }-next-step-link` ) );
}

// While the plugin is still retrying on its own, a manual retry would only race it, and a
// failure that would happen the same way again (a password-protected document) gets none.
if ( model.get( 'transcoding_can_retranscode' ) && 'retrying' !== failure.kind && false !== failure.retryable ) {
const button = el( 'button', 'button', __( 'Retranscode', 'godam' ) );
const button = el( 'button', 'button', __( 'Retranscode', 'godam' ), `${ TEST_ID }-retranscode` );
button.type = 'button';
button.addEventListener( 'click', () => retranscode( model, button, status ) );
actions.append( button );
}

if ( isLinkable( failure.support_url ) ) {
actions.append( link( failure.support_url, __( 'Contact support', 'godam' ), `${ PANEL_CLASS }__support` ) );
actions.append( link( failure.support_url, __( 'Contact support', 'godam' ), `${ PANEL_CLASS }__support`, `${ TEST_ID }-support-link` ) );
}

if ( actions.childElementCount ) {
Expand All @@ -176,7 +187,7 @@ const renderTranscodingRefusalPanel = ( view ) => {
const detail = isRefusal( failure.code ) ? model.get( 'transcoding_error_detail' ) : '';

if ( detail ) {
const details = el( 'details', `${ PANEL_CLASS }__details` );
const details = el( 'details', `${ PANEL_CLASS }__details`, '', `${ TEST_ID }-details` );
details.append(
el( 'summary', '', __( 'Details for support', 'godam' ) ),
el( 'p', '', detail ),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,4 +204,28 @@ describe( 'transcoding refusal panel', () => {
expect( text ).not.toContain( '(ID 55)' );
expect( button.disabled ).toBe( false );
} );

it( 'marks the panel and its parts for the E2E tests', () => {
renderTranscodingRefusalPanel( view( {
...refused,
transcoding_failure: { ...refused.transcoding_failure, support_url: 'https://app.godam.io/helpdesk/my-tickets' },
} ) );

const byTestId = ( id ) => document.querySelector( `[data-test-id="${ id }"]` );

expect( byTestId( 'godam-transcode-failure-panel' ) ).toBe( panel() );
expect( byTestId( 'godam-transcode-failure-panel-title' ).textContent ).toBe( 'This file couldn\'t be transcoded' );
expect( byTestId( 'godam-transcode-failure-panel-reason' ).textContent ).toBe( refused.transcoding_error_msg );
expect( byTestId( 'godam-transcode-failure-panel-next-step-link' ).href ).toContain( 'app.godam.io/web/billing' );
expect( byTestId( 'godam-transcode-failure-panel-retranscode' ).textContent ).toBe( 'Retranscode' );
expect( byTestId( 'godam-transcode-failure-panel-support-link' ).href ).toBe( 'https://app.godam.io/helpdesk/my-tickets' );
expect( byTestId( 'godam-transcode-failure-panel-status' ) ).not.toBeNull();
expect( byTestId( 'godam-transcode-failure-panel-details' ) ).not.toBeNull();
} );

it( 'marks the next step that has nothing to click', () => {
renderTranscodingRefusalPanel( view( failed( { kind: 'failed', code: 'oom', message: 'Too big.', action: 'upload_smaller', next_step: 'Upload a smaller file.' } ) ) );

expect( document.querySelector( '[data-test-id="godam-transcode-failure-panel-next-step"]' ).textContent ).toBe( 'Upload a smaller file.' );
} );
} );
Loading