Skip to content

Commit 0824b8e

Browse files
Add test IDs to the transcode failure surfaces (#2393)
* Add test IDs to the media list view's transcode failure - The failure reason, the next step and its links get a data-test-id, both when the page prints them and when polling redraws them. - link() takes an optional test ID. - The reason's test ID goes away once the file stops failing. * Add a test ID to the grid view's transcode failure tooltip - setFailureText() marks the status icon with a data-test-id while it carries a failure reason, and removes it with the reason. - Unit tests for setFailureText(). * Add test IDs to the attachment details transcode failure panel - The panel and its title, reason, next step, Upgrade/next-step link, Retranscode button, Contact support link, status line and support details each get a data-test-id under godam-transcode-failure-panel. - el() takes an optional test ID. * Use @SInCE 2.11.0 for the changes in this PR It goes straight into the 2.11.0 release, after the version bump.
1 parent cc7e546 commit 0824b8e

7 files changed

Lines changed: 135 additions & 19 deletions

File tree

‎admin/godam-transcoder-functions.php‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -488,10 +488,10 @@ function rtgodam_add_status_columns_content( $column_name, $post_id ) {
488488
</svg>
489489
</div>
490490
<?php if ( ! empty( $failure ) ) : ?>
491-
<span class="status-text"><?php echo esc_html( $failure['message'] ); ?></span>
491+
<span class="status-text" data-test-id="godam-transcode-failure-reason"><?php echo esc_html( $failure['message'] ); ?></span>
492492
<?php rtgodam_render_transcoding_next_step( $failure ); ?>
493493
<?php else : ?>
494-
<span class="status-text"><?php esc_html_e( 'Transcoding failed, please try again.', 'godam' ); ?></span>
494+
<span class="status-text" data-test-id="godam-transcode-failure-reason"><?php esc_html_e( 'Transcoding failed, please try again.', 'godam' ); ?></span>
495495
<?php endif; ?>
496496
</div>
497497
<?php
@@ -536,14 +536,14 @@ function rtgodam_render_transcoding_next_step( $failure ) {
536536
return;
537537
}
538538
?>
539-
<span class="status-next-step">
539+
<span class="status-next-step" data-test-id="godam-transcode-next-step">
540540
<?php if ( ! empty( $failure['next_step'] ) && ! empty( $failure['next_step_url'] ) ) : ?>
541-
<a href="<?php echo esc_url( $failure['next_step_url'] ); ?>" target="_blank" rel="noopener noreferrer"><?php echo esc_html( $failure['next_step'] ); ?></a>
541+
<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>
542542
<?php elseif ( ! empty( $failure['next_step'] ) ) : ?>
543543
<?php echo esc_html( $failure['next_step'] ); ?>
544544
<?php endif; ?>
545545
<?php if ( ! empty( $failure['support_url'] ) ) : ?>
546-
<a href="<?php echo esc_url( $failure['support_url'] ); ?>" target="_blank" rel="noopener noreferrer"><?php esc_html_e( 'Contact support', 'godam' ); ?></a>
546+
<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>
547547
<?php endif; ?>
548548
</span>
549549
<?php

‎assets/src/js/media-library/transcoding-status/failure.js‎

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,23 @@ export const isLinkable = ( url ) => typeof url === 'string' && /^https?:\/\//i.
2020
/**
2121
* Build a link that opens in a new tab.
2222
*
23+
* @since 2.11.0 Takes an optional `testId`.
24+
*
2325
* @param {string} href URL.
2426
* @param {string} text Link text.
2527
* @param {string} className Optional class name.
28+
* @param {string} testId Optional `data-test-id`, for the E2E tests.
2629
*
2730
* @return {HTMLAnchorElement} The link.
2831
*/
29-
export const link = ( href, text, className = '' ) => {
32+
export const link = ( href, text, className = '', testId = '' ) => {
3033
const anchor = document.createElement( 'a' );
3134
if ( className ) {
3235
anchor.className = className;
3336
}
37+
if ( testId ) {
38+
anchor.setAttribute( 'data-test-id', testId );
39+
}
3440
anchor.href = href;
3541
anchor.target = '_blank';
3642
anchor.rel = 'noopener noreferrer';
@@ -58,9 +64,10 @@ export const renderNextStep = ( container, failure ) => {
5864

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

6269
if ( failure.next_step && isLinkable( failure.next_step_url ) ) {
63-
line.append( link( failure.next_step_url, failure.next_step ) );
70+
line.append( link( failure.next_step_url, failure.next_step, '', 'godam-transcode-next-step-link' ) );
6471
} else if ( failure.next_step ) {
6572
line.append( document.createTextNode( failure.next_step ) );
6673
}
@@ -69,7 +76,7 @@ export const renderNextStep = ( container, failure ) => {
6976
if ( line.childNodes.length ) {
7077
line.append( document.createTextNode( ' ' ) );
7178
}
72-
line.append( link( failure.support_url, __( 'Contact support', 'godam' ) ) );
79+
line.append( link( failure.support_url, __( 'Contact support', 'godam' ), '', 'godam-transcode-support-link' ) );
7380
}
7481

7582
container.append( line );
@@ -88,6 +95,8 @@ export const cssString = ( text ) => JSON.stringify( String( text ) );
8895
* Put a failed file's reason on its grid status icon: in the hover tooltip, and as the
8996
* icon's accessible name. With no reason, the stylesheet's generic label shows instead.
9097
*
98+
* @since 2.11.0 Marks the icon with a `data-test-id` while it carries a reason.
99+
*
91100
* @param {HTMLElement} loader The `.transcoding-status__loader` element.
92101
* @param {string} message Why it failed, from the server.
93102
*/
@@ -101,11 +110,13 @@ export const setFailureText = ( loader, message ) => {
101110
loader.removeAttribute( 'title' );
102111
loader.removeAttribute( 'aria-label' );
103112
loader.removeAttribute( 'role' );
113+
loader.removeAttribute( 'data-test-id' );
104114
return;
105115
}
106116

107117
loader.style.setProperty( '--status-text', cssString( message ) );
108118
loader.setAttribute( 'title', message );
109119
loader.setAttribute( 'role', 'img' );
110120
loader.setAttribute( 'aria-label', message );
121+
loader.setAttribute( 'data-test-id', 'godam-transcode-failure-tooltip' );
111122
};
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/**
2+
* Unit tests for the grid view's failure tooltip on the transcode status icon.
3+
*/
4+
5+
/**
6+
* Internal dependencies
7+
*/
8+
import { setFailureText } from './failure';
9+
10+
describe( 'setFailureText', () => {
11+
let loader;
12+
13+
beforeEach( () => {
14+
document.body.innerHTML = '<div class="transcoding-status__loader"></div>';
15+
loader = document.querySelector( '.transcoding-status__loader' );
16+
} );
17+
18+
it( 'puts the reason in the tooltip and marks the icon for the E2E tests', () => {
19+
setFailureText( loader, 'Your GoDAM storage is full.' );
20+
21+
expect( loader.style.getPropertyValue( '--status-text' ) ).toBe( '"Your GoDAM storage is full."' );
22+
expect( loader.getAttribute( 'aria-label' ) ).toBe( 'Your GoDAM storage is full.' );
23+
expect( loader.getAttribute( 'data-test-id' ) ).toBe( 'godam-transcode-failure-tooltip' );
24+
} );
25+
26+
it( 'clears the reason and the test ID when there is none', () => {
27+
setFailureText( loader, 'Your GoDAM storage is full.' );
28+
setFailureText( loader, '' );
29+
30+
expect( loader.style.getPropertyValue( '--status-text' ) ).toBe( '' );
31+
expect( loader.hasAttribute( 'aria-label' ) ).toBe( false );
32+
expect( loader.hasAttribute( 'data-test-id' ) ).toBe( false );
33+
} );
34+
35+
it( 'does nothing without an icon', () => {
36+
expect( () => setFailureText( null, 'x' ) ).not.toThrow();
37+
} );
38+
} );

‎assets/src/js/media-library/transcoding-status/list-view-transcoding-status.js‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,9 @@ class ListViewTranscodingStatus {
110110

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

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

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

207209
renderNextStep( element, data.failure );
208210
}

‎assets/src/js/media-library/transcoding-status/list-view-transcoding-status.test.js‎

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,4 +125,34 @@ describe( 'ListViewTranscodingStatus — failed state', () => {
125125

126126
expect( document.querySelector( '#list-transcoder-status-55 .status-next-step' ) ).toBeNull();
127127
} );
128+
129+
it( 'marks the reason, next step and links for the E2E tests', () => {
130+
render();
131+
132+
new ListViewTranscodingStatus().updateAttachmentStatus( '55', {
133+
status: 'failed',
134+
error_msg: 'Your GoDAM storage is full.',
135+
failure: {
136+
next_step: 'Upgrade plan',
137+
next_step_url: 'https://app.godam.io/plans',
138+
support_url: 'https://app.godam.io/helpdesk/my-tickets',
139+
},
140+
} );
141+
142+
const element = document.querySelector( '#list-transcoder-status-55' );
143+
expect( element.querySelector( '[data-test-id="godam-transcode-failure-reason"]' ).textContent ).toBe( 'Your GoDAM storage is full.' );
144+
expect( element.querySelector( '[data-test-id="godam-transcode-next-step"]' ) ).not.toBeNull();
145+
expect( element.querySelector( '[data-test-id="godam-transcode-next-step-link"]' ).href ).toBe( 'https://app.godam.io/plans' );
146+
expect( element.querySelector( '[data-test-id="godam-transcode-support-link"]' ).href ).toBe( 'https://app.godam.io/helpdesk/my-tickets' );
147+
} );
148+
149+
it( 'drops the reason\'s test ID once the file transcodes', () => {
150+
render();
151+
const status = new ListViewTranscodingStatus();
152+
153+
status.updateAttachmentStatus( '55', { status: 'failed', error_msg: 'x' } );
154+
status.updateAttachmentStatus( '55', { status: 'transcoded', progress: 100 } );
155+
156+
expect( document.querySelector( '[data-test-id^="godam-transcode-"]' ) ).toBeNull();
157+
} );
128158
} );

‎assets/src/js/media-library/views/fields/transcoding-refusal-panel.js‎

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,30 @@ import { isLinkable, link } from '../../transcoding-status/failure';
1212

1313
const PANEL_CLASS = 'godam-transcoding-refusal';
1414

15+
/**
16+
* Prefix of the panel's `data-test-id`s, for the E2E tests.
17+
*/
18+
const TEST_ID = 'godam-transcode-failure-panel';
19+
1520
/**
1621
* Build an element with a class and optional text.
1722
*
23+
* @since 2.11.0 Takes an optional `testId`.
24+
*
1825
* @param {string} tag Tag name.
1926
* @param {string} className Class name.
2027
* @param {string} text Text content.
28+
* @param {string} testId Optional `data-test-id`.
2129
*
2230
* @return {HTMLElement} The element.
2331
*/
24-
const el = ( tag, className, text = '' ) => {
32+
const el = ( tag, className, text = '', testId = '' ) => {
2533
const node = document.createElement( tag );
2634
node.className = className;
2735
node.textContent = text;
36+
if ( testId ) {
37+
node.setAttribute( 'data-test-id', testId );
38+
}
2839

2940
return node;
3041
};
@@ -134,37 +145,37 @@ const renderTranscodingRefusalPanel = ( view ) => {
134145
return;
135146
}
136147

137-
const panel = el( 'div', PANEL_CLASS );
148+
const panel = el( 'div', PANEL_CLASS, '', TEST_ID );
138149
panel.setAttribute( 'role', 'status' );
139150

140151
panel.append(
141-
el( 'p', `${ PANEL_CLASS }__title`, titleFor( failure.kind ) ),
142-
el( 'p', `${ PANEL_CLASS }__reason`, failure.message ),
152+
el( 'p', `${ PANEL_CLASS }__title`, titleFor( failure.kind ), `${ TEST_ID }-title` ),
153+
el( 'p', `${ PANEL_CLASS }__reason`, failure.message, `${ TEST_ID }-reason` ),
143154
);
144155

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

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

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

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

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

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

178189
if ( detail ) {
179-
const details = el( 'details', `${ PANEL_CLASS }__details` );
190+
const details = el( 'details', `${ PANEL_CLASS }__details`, '', `${ TEST_ID }-details` );
180191
details.append(
181192
el( 'summary', '', __( 'Details for support', 'godam' ) ),
182193
el( 'p', '', detail ),

‎assets/src/js/media-library/views/fields/transcoding-refusal-panel.test.js‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,4 +204,28 @@ describe( 'transcoding refusal panel', () => {
204204
expect( text ).not.toContain( '(ID 55)' );
205205
expect( button.disabled ).toBe( false );
206206
} );
207+
208+
it( 'marks the panel and its parts for the E2E tests', () => {
209+
renderTranscodingRefusalPanel( view( {
210+
...refused,
211+
transcoding_failure: { ...refused.transcoding_failure, support_url: 'https://app.godam.io/helpdesk/my-tickets' },
212+
} ) );
213+
214+
const byTestId = ( id ) => document.querySelector( `[data-test-id="${ id }"]` );
215+
216+
expect( byTestId( 'godam-transcode-failure-panel' ) ).toBe( panel() );
217+
expect( byTestId( 'godam-transcode-failure-panel-title' ).textContent ).toBe( 'This file couldn\'t be transcoded' );
218+
expect( byTestId( 'godam-transcode-failure-panel-reason' ).textContent ).toBe( refused.transcoding_error_msg );
219+
expect( byTestId( 'godam-transcode-failure-panel-next-step-link' ).href ).toContain( 'app.godam.io/web/billing' );
220+
expect( byTestId( 'godam-transcode-failure-panel-retranscode' ).textContent ).toBe( 'Retranscode' );
221+
expect( byTestId( 'godam-transcode-failure-panel-support-link' ).href ).toBe( 'https://app.godam.io/helpdesk/my-tickets' );
222+
expect( byTestId( 'godam-transcode-failure-panel-status' ) ).not.toBeNull();
223+
expect( byTestId( 'godam-transcode-failure-panel-details' ) ).not.toBeNull();
224+
} );
225+
226+
it( 'marks the next step that has nothing to click', () => {
227+
renderTranscodingRefusalPanel( view( failed( { kind: 'failed', code: 'oom', message: 'Too big.', action: 'upload_smaller', next_step: 'Upload a smaller file.' } ) ) );
228+
229+
expect( document.querySelector( '[data-test-id="godam-transcode-failure-panel-next-step"]' ).textContent ).toBe( 'Upload a smaller file.' );
230+
} );
207231
} );

0 commit comments

Comments
 (0)