Commit 9182e07d authored by Alex Danilo's avatar Alex Danilo Committed by Commit Bot

Make error panel items set default text

When a panel item is set to an error type, the primary text can wrap to
2 lines and the secondary text should not be shown.

Change the error panel initialization to set the primary text to a
default generic error string, and the secondary text to blank.

Adds unit test to confirm the expected behaviour.

Bug: 1021307
Tests: browser_tests --gtest_filter=FileManagerJsTest.FilesDisplayPanel
Change-Id: Id9251b9cfae3050dc6fd8005c214d920f6173a44
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1904562
Commit-Queue: Alex Danilo <adanilo@chromium.org>
Reviewed-by: default avatarLuciano Pacheco <lucmult@chromium.org>
Cr-Commit-Position: refs/heads/master@{#713729}
parent ec317c80
......@@ -134,6 +134,33 @@ async function testDisplayPanelChangingPanelTypes(done) {
done();
}
function testFilesDisplayPanelErrorText() {
// Get the host display panel container element.
/** @type {!DisplayPanel|!Element} */
const displayPanel = assert(document.querySelector('#test-xf-display-panel'));
// Add a panel item to the display panel container.
const panelItem = displayPanel.addPanelItem('testpanel');
// Change the primary and secondary text on the panel item.
panelItem.primaryText = 'foo';
panelItem.secondaryText = 'bar';
// Check the primary and secondary text has been set on the panel.
assertEquals('foo', panelItem.primaryText);
assertEquals('bar', panelItem.secondaryText);
// Change the panel item type to an error panel.
panelItem.panelType = panelItem.panelTypeError;
// Check the default primary text displays a generic error message.
// Note, the i18n message gets smooshed into 'An error occurred.' in the app.
assertEquals('$i18n{FILE_ERROR_GENERIC}', panelItem.primaryText);
// Check the secondary text is empty.
assertEquals('', panelItem.secondaryText);
}
// Override the formatting function for unit testing.
util.strf = (end, option) => {
return option + end;
......
......@@ -241,6 +241,8 @@ class PanelItem extends HTMLElement {
case this.panelTypeError:
this.setAttribute('indicator', 'status');
this.setAttribute('status', 'failure');
this.primaryText = '$i18n{FILE_ERROR_GENERIC}';
this.secondaryText = '';
secondaryButton = document.createElement('xf-button');
secondaryButton.id = 'secondary-action';
secondaryButton.onclick = assert(this.onclick);
......@@ -515,6 +517,14 @@ class PanelItem extends HTMLElement {
this.setAttribute('primary-text', text);
}
/**
* Getter for the primary text on the panel.
* @return {string}
*/
get primaryText() {
return this.getAttribute('primary-text');
}
/**
* Setter to set the secondary text on the panel.
* @param {string} text Text to be shown.
......@@ -523,6 +533,14 @@ class PanelItem extends HTMLElement {
this.setAttribute('secondary-text', text);
}
/**
* Getter for the secondary text on the panel.
* @return {string}
*/
get secondaryText() {
return this.getAttribute('secondary-text');
}
/**
* Setter to set the panel type.
* @param {number} type Enum value for the panel type.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment