Skip to content

Commit

Permalink
Merge pull request #3601 from kbase/UIP-46-die-cleanup
Browse files Browse the repository at this point in the history
UIP-46 fix bug with displaying wildcard in data type input in app cell info tab
  • Loading branch information
briehl authored Jul 25, 2024
2 parents 7cd2a51 + cdb813f commit f83f609
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ define(['domPurify', 'common/format', 'common/html', 'util/string'], (
html,
string
) => {
'use strict';

// Note - would destructure in the arguments, but that would require a change to eslint rules.
const { sanitize } = DOMPurify;

Expand All @@ -29,7 +27,11 @@ define(['domPurify', 'common/format', 'common/html', 'util/string'], (
const parameterArray = appSpec.parameters.map((param) => {
const textOptions = param.text_options;
let types = null;
if (textOptions && Array.isArray(textOptions.valid_ws_types)) {
if (
textOptions &&
Array.isArray(textOptions.valid_ws_types) &&
textOptions.valid_ws_types.indexOf('*') === -1
) {
const typesArray = textOptions.valid_ws_types.map((type) => {
return a(
{
Expand Down Expand Up @@ -220,12 +222,12 @@ define(['domPurify', 'common/format', 'common/html', 'util/string'], (
),
appTag
? span(
{
class: `${cssBaseClass}__tag label label-primary`,
title: `${appTag} version of the app`,
},
appTag
)
{
class: `${cssBaseClass}__tag label label-primary`,
title: `${appTag} version of the app`,
},
appTag
)
: '',
]
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ define([
], (Promise, KBWidget, $, Config, APIUtil, kbase_client_api, GenericClient, Jupyter) => {
const STAGING_EXPORT_APP = 'kb_staging_exporter/export_to_staging';
const JSON_EXPORT_APP = 'kb_staging_exporter/export_json_to_staging';
const CSS_BASE = 'kb-download-panel';

return KBWidget({
name: 'kbaseNarrativeDownloadPanel',
Expand Down Expand Up @@ -92,19 +93,19 @@ define([
},

renderStructure: function () {
const $container = $('<div>').addClass('kb-download-panel');
const $label = $('<div>').addClass('kb-download-panel__label').append('Export as:');
const $buttons = $('<div>').addClass('kb-download-panel__buttons');
const $container = $('<div>').addClass(CSS_BASE);
const $label = $('<div>').addClass(`${CSS_BASE}__label`).append('Export as:');
const $buttons = $('<div>').addClass(`${CSS_BASE}__buttons`);
$container.append($label).append($buttons);

this.$elem.append($container);
this.$statusDiv = $('<div>').addClass('kb-download-panel__status');
this.$statusDiv = $('<div>').addClass(`${CSS_BASE}__status`);
this.$elem.append(this.$statusDiv.hide());
},

renderDownloadButtons: function () {
const downloaders = this.prepareDownloaders(this.type);
const $btnPanel = this.$elem.find('.kb-download-panel__buttons');
const $btnPanel = this.$elem.find(`.${CSS_BASE}__buttons`);
downloaders.forEach((dlInfo) => {
if (dlInfo.name.toLocaleLowerCase() === 'staging') {
$btnPanel.append(
Expand Down Expand Up @@ -259,7 +260,7 @@ define([
},

showMessage: function (msg) {
this.$statusDiv.empty().append(msg);
this.$statusDiv.empty().append(msg).show();
},

showError: function (error) {
Expand All @@ -272,11 +273,14 @@ define([
}
// error is final state, so reactivate!
this.$elem.find('.kb-data-list-btn').prop('disabled', false);
this.$statusDiv.empty().append(
$('<span>')
.addClass('kb-download-panel__status_error')
.append('Error: ' + error)
);
this.$statusDiv
.empty()
.append(
$('<span>')
.addClass(`${CSS_BASE}__status_error`)
.append('Error: ' + error)
)
.show();
},

stopTimer: function () {
Expand Down
22 changes: 20 additions & 2 deletions test/unit/spec/common/cellComponents/tabs/infoTab-Spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ define(['common/cellComponents/tabs/infoTab', 'common/props', 'testUtil'], (
Props,
TestUtil
) => {
'use strict';

describe('The App Info Tab module', () => {
it('loads', () => {
expect(InfoTab).not.toBe(null);
Expand Down Expand Up @@ -86,6 +84,13 @@ define(['common/cellComponents/tabs/infoTab', 'common/props', 'testUtil'], (
ui_name: 'Adapters',
id: 'adapters',
},
{
text_options: {
valid_ws_types: ['*', 'SomeModule.SomeType'],
},
ui_name: 'Any old object',
id: 'any_old_object',
},
],
},
tag: APP.ONE.TAG,
Expand Down Expand Up @@ -305,6 +310,19 @@ define(['common/cellComponents/tabs/infoTab', 'common/props', 'testUtil'], (
).toBe(appData[APP.ONE.ID].app.spec.parameters[1].ui_name);
});

it('renders no links for a parameter than can be a wildcard type', () => {
const paramThree = container.querySelectorAll(
`.${cssBaseClass}__list_item--params`
)[2];
expect(
paramThree.querySelector(`.${cssBaseClass}__param--id`).textContent
).toBe(appData[APP.ONE.ID].app.spec.parameters[2].id);
expect(
paramThree.querySelector(`.${cssBaseClass}__param--ui-name`).textContent
).toBe(appData[APP.ONE.ID].app.spec.parameters[2].ui_name);
expect(paramThree.querySelectorAll('a').length).toBe(0);
});

it('renders run stats correctly', () => {
if (isMulti) {
// no run stats in the multi-app version
Expand Down
19 changes: 10 additions & 9 deletions test/unit/spec/narrative_core/kbaseNarrativeDownloadPanel-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ define([
], ($, kbaseNarrativeDownloadPanel, Jupyter, Mocks, TestUtil, Config) => {
const JSON_EXPORT_APP = 'kb_staging_exporter/export_json_to_staging';
const STAGING_EXPORT_APP = 'kb_staging_exporter/export_to_staging';
const CSS_BASE = 'kb-download-panel';

describe('The kbaseNarrativeDownloadPanel widget', () => {
let $div = null;
Expand Down Expand Up @@ -124,7 +125,7 @@ define([
});

await initDownloadPanel(null, {});
const $status = $div.find('.kb-download-status');
const $status = $div.find(`.${CSS_BASE}__status`);
expect($status.text()).toContain('Error: an error happened');
});

Expand Down Expand Up @@ -236,14 +237,14 @@ define([
await TestUtil.waitForElementState(
$div[0],
() => {
const text = $div[0].querySelector('.kb-download-status').textContent || '';
const text = $div[0].querySelector(`.${CSS_BASE}__status`).textContent || '';
return text.endsWith(errorMsg);
},
() => {
exportBtns[0].click();
}
);
expect($div[0].querySelector('.kb-download-status').textContent).toContain(errorMsg);
expect($div[0].querySelector(`.${CSS_BASE}__status`).textContent).toContain(errorMsg);
expect(widget.timer).toBeNull();
});

Expand Down Expand Up @@ -323,22 +324,22 @@ define([
await TestUtil.waitForElementState(
$div[0],
() => {
const text = $div[0].querySelector('.kb-download-status').textContent || '';
const text = $div[0].querySelector(`.${CSS_BASE}__status`).textContent || '';
return text.endsWith('some log');
},
() => {
exportBtns[0].click();
}
);
expect($div[0].querySelector('.kb-download-status').textContent).toContain('some log');
expect($div[0].querySelector(`.${CSS_BASE}__status`).textContent).toContain('some log');
expect(widget.timer).not.toBeNull();

await TestUtil.waitForElementState($div[0], () => {
const text = $div[0].querySelector('.kb-download-status').textContent;
const text = $div[0].querySelector(`.${CSS_BASE}__status`).textContent;
return text === '';
});

expect($div[0].querySelector('.kb-download-status').textContent).toBe('');
expect($div[0].querySelector(`.${CSS_BASE}__status`).textContent).toBe('');
expect(widget.timer).toBeNull();
});

Expand Down Expand Up @@ -383,14 +384,14 @@ define([
await TestUtil.waitForElementState(
$div[0],
() => {
const text = $div[0].querySelector('.kb-download-status').textContent || '';
const text = $div[0].querySelector(`.${CSS_BASE}__status`).textContent || '';
return text.endsWith(errorMsg);
},
() => {
exportBtns[0].click();
}
);
expect($div[0].querySelector('.kb-download-status').textContent).toContain(errorMsg);
expect($div[0].querySelector(`.${CSS_BASE}__status`).textContent).toContain(errorMsg);
expect(widget.timer).toBeNull();
});

Expand Down

0 comments on commit f83f609

Please sign in to comment.