Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add data-testid attr to the close button for modal #3394

Merged
merged 5 commits into from
Aug 16, 2023
Merged
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
8 changes: 8 additions & 0 deletions client/luigi-client.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export declare interface ModalSettings {
size?: 'fullscreen' | 'l' | 'm' | 's';
width?: string;
height?: string;
closebtn_data_testid?: string;
}

export declare interface SplitViewSettings {
Expand Down Expand Up @@ -330,6 +331,10 @@ export declare interface LinkManager {
* @param {Object} modalSettings opens a view in a modal. Use these settings to configure the modal's title and size
* @param {string} modalSettings.title modal title. By default, it is the node label. If there is no label, it is left empty
* @param {('fullscreen'|'l'|'m'|'s')} [modalSettings.size="l"] size of the modal
* @param {string} modalSettings.width lets you specify a precise width for the modal. Allowed units are 'px', '%', 'rem', 'em', 'vh' and 'vw'.
* @param {string} modalSettings.height lets you specify a precise height for the modal. Allowed units are 'px', '%', 'rem', 'em', 'vh' and 'vw'.
* @param {boolean} modalSettings.keepPrevious Lets you open multiple modals. Keeps the previously opened modal and allows to open another modal on top of the previous one. By default the previous modals are discarded.
* @param {string} modalSettings.closebtn_data_testid lets you specify a `data_testid` for the close button. Default value is `lui-modal-index-0`. If multiple modals are opened the index will be increased per modal.
* @param {Object} splitViewSettings opens a view in a split view. Use these settings to configure the split view's behaviour
* @param {string} splitViewSettings.title split view title. By default, it is the node label. If there is no label, it is left empty
* @param {number} [splitViewSettings.size=40] height of the split view in percent
Expand Down Expand Up @@ -410,7 +415,10 @@ export declare interface LinkManager {
* @param {Object} [modalSettings] opens a view in a modal. Use these settings to configure the modal's title and size
* @param {string} modalSettings.title modal title. By default, it is the node label. If there is no label, it is left empty
* @param {('fullscreen'|'l'|'m'|'s')} [modalSettings.size="l"] size of the modal
* @param {string} modalSettings.width lets you specify a precise width for the modal. Allowed units are 'px', '%', 'rem', 'em', 'vh' and 'vw'.
* @param {string} modalSettings.height lets you specify a precise height for the modal. Allowed units are 'px', '%', 'rem', 'em', 'vh' and 'vw'.
* @param {boolean} modalSettings.keepPrevious Lets you open multiple modals. Keeps the previously opened modal and allows to open another modal on top of the previous one. By default the previous modals are discarded.
* @param {string} modalSettings.closebtn_data_testid lets you specify a `data_testid` for the close button. Default value is `lui-modal-index-0`. If multiple modals are opened the index will be increased per modal.
* @example
* LuigiClient.linkManager().openAsModal('projects/pr1/users', {title:'Users', size:'m'});
*/
Expand Down
7 changes: 6 additions & 1 deletion client/luigi-element.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export declare interface ModalSettings {
size?: 'fullscreen' | 'l' | 'm' | 's';
width?: string;
height?: string;
closebtn_data_testid?: string;
}

export declare interface SplitViewSettings {
Expand Down Expand Up @@ -187,6 +188,8 @@ export declare interface LinkManager {
* @param {('fullscreen'|'l'|'m'|'s')} [modalSettings.size="l"] size of the modal
* @param {string} modalSettings.width lets you specify a precise width for the modal. Allowed units are 'px', '%', 'rem', 'em', 'vh' and 'vw'.
* @param {string} modalSettings.height lets you specify a precise height for the modal. Allowed units are 'px', '%', 'rem', 'em', 'vh' and 'vw'.
* @param {boolean} modalSettings.keepPrevious Lets you open multiple modals. Keeps the previously opened modal and allows to open another modal on top of the previous one. By default the previous modals are discarded.
* @param {string} modalSettings.closebtn_data_testid lets you specify a `data_testid` for the close button. Default value is `lui-modal-index-0`. If multiple modals are opened the index will be increased per modal.
* @param {Object} splitViewSettings opens a view in a split view. Use these settings to configure the split view's behaviour
* @param {string} splitViewSettings.title split view title. By default, it is the node label. If there is no label, it is left empty
* @param {number} [splitViewSettings.size=40] height of the split view in percent
Expand Down Expand Up @@ -217,7 +220,9 @@ export declare interface LinkManager {
* @param {('fullscreen'|'l'|'m'|'s')} [modalSettings.size="l"] size of the modal
* @param {string} modalSettings.width lets you specify a precise width for the modal. Allowed units are 'px', '%', 'rem', 'em', 'vh' and 'vw'.
* @param {string} modalSettings.height lets you specify a precise height for the modal. Allowed units are 'px', '%', 'rem', 'em', 'vh' and 'vw'.
* @param {Function} onCloseCallback callback function called upon closing the openened modal
* @param {boolean} modalSettings.keepPrevious Lets you open multiple modals. Keeps the previously opened modal and allows to open another modal on top of the previous one. By default the previous modals are discarded.
* @param {string} modalSettings.closebtn_data_testid lets you specify a `data_testid` for the close button. Default value is `lui-modal-index-0`. If multiple modals are opened the index will be increased per modal.
* @param {Function} onCloseCallback callback function called upon closing the opened modal
* @example
* LuigiClient.linkManager().openAsModal('projects/pr1/users', {title:'Users', size:'m'});
*/
Expand Down
3 changes: 3 additions & 0 deletions client/src/linkManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ export class linkManager extends LuigiClientBase {
* @param {('fullscreen'|'l'|'m'|'s')} [modalSettings.size="l"] size of the modal
* @param {string} modalSettings.width lets you specify a precise width for the modal. Allowed units are 'px', '%', 'rem', 'em', 'vh' and 'vw'.
* @param {string} modalSettings.height lets you specify a precise height for the modal. Allowed units are 'px', '%', 'rem', 'em', 'vh' and 'vw'.
* @param {boolean} modalSettings.keepPrevious Lets you open multiple modals. Keeps the previously opened modal and allows to open another modal on top of the previous one. By default the previous modals are discarded.
* @param {string} modalSettings.closebtn_data_testid lets you specify a `data_testid` for the close button. Default value is `lui-modal-index-0`. If multiple modals are opened the index will be increased per modal.
* @param {Object} splitViewSettings opens a view in a split view. Use these settings to configure the split view's behaviour
* @param {string} splitViewSettings.title split view title. By default, it is the node label. If there is no label, it is left empty
* @param {number} [splitViewSettings.size=40] height of the split view in percent
Expand Down Expand Up @@ -162,6 +164,7 @@ export class linkManager extends LuigiClientBase {
* @param {string} modalSettings.width lets you specify a precise width for the modal. Allowed units are 'px', '%', 'rem', 'em', 'vh' and 'vw'.
* @param {string} modalSettings.height lets you specify a precise height for the modal. Allowed units are 'px', '%', 'rem', 'em', 'vh' and 'vw'.
* @param {boolean} modalSettings.keepPrevious Lets you open multiple modals. Keeps the previously opened modal and allows to open another modal on top of the previous one. By default the previous modals are discarded.
* @param {string} modalSettings.closebtn_data_testid lets you specify a `data_testid` for the close button. Default value is `lui-modal-index-0`. If multiple modals are opened the index will be increased per modal.
* @example
* LuigiClient.linkManager().openAsModal('projects/pr1/users', {title:'Users', size:'m'});
*/
Expand Down
3 changes: 3 additions & 0 deletions core/src/Modal.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,9 @@
class="fd-button fd-button--transparent fd-button--compact"
on:click={() => dispatch('close', { activeDrawer: false })}
aria-label="close"
data-testid={settings.closebtn_data_testid && isModal
? settings.closebtn_data_testid
: 'lui-modal-index-' + modalIndex}
>
<i class="sap-icon sap-icon--decline" />
</button>
Expand Down
4 changes: 4 additions & 0 deletions core/src/core-api/navigation.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ class LuigiNavigationManager {
* @param {('fullscreen'|'l'|'m'|'s')} [modalSettings.size="l"] size of the modal
* @param {string} modalSettings.width lets you specify a precise width for the modal. Allowed units are 'px', '%', 'rem', 'em', 'vh' and 'vw'.
* @param {string} modalSettings.height lets you specify a precise height for the modal. Allowed units are 'px', '%', 'rem', 'em', 'vh' and 'vw'.
* @param {boolean} modalSettings.keepPrevious Lets you open multiple modals. Keeps the previously opened modal and allows to open another modal on top of the previous one. By default the previous modals are discarded.
* @param {string} modalSettings.closebtn_data_testid lets you specify a `data_testid` for the close button. Default value is `lui-modal-index-0`. If multiple modals are opened the index will be increased per modal.
* @param {Object} splitViewSettings opens a view in a split view. Use these settings to configure the split view's behaviour
* @param {string} splitViewSettings.title split view title. By default, it is the node label. If there is no label, it is left empty
* @param {number} [splitViewSettings.size=40] height of the split view in percent
Expand All @@ -55,6 +57,8 @@ class LuigiNavigationManager {
* @param {('fullscreen'|'l'|'m'|'s')} [modalSettings.size="l"] size of the modal
* @param {string} modalSettings.width lets you specify a precise width for the modal. Allowed units are 'px', '%', 'rem', 'em', 'vh' and 'vw'.
* @param {string} modalSettings.height lets you specify a precise height for the modal. Allowed units are 'px', '%', 'rem', 'em', 'vh' and 'vw'.
* @param {boolean} modalSettings.keepPrevious Lets you open multiple modals. Keeps the previously opened modal and allows to open another modal on top of the previous one. By default the previous modals are discarded.
* @param {string} modalSettings.closebtn_data_testid lets you specify a `data_testid` for the close button. Default value is `lui-modal-index-0`. If multiple modals are opened the index will be increased per modal.
* @param {Function} onCloseCallback callback function called upon closing the opened modal
* @example
* Luigi.navigation().openAsModal('projects/pr1/users', {title:'Users', size:'m'});
Expand Down
3 changes: 3 additions & 0 deletions docs/luigi-client-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -576,6 +576,8 @@ Navigates to the given path in the application hosted by Luigi. It contains eith
- `modalSettings.size` **(`"fullscreen"` \| `"l"` \| `"m"` \| `"s"`)** size of the modal (optional, default `"l"`)
- `modalSettings.width` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** lets you specify a precise width for the modal. Allowed units are 'px', '%', 'rem', 'em', 'vh' and 'vw'.
- `modalSettings.height` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** lets you specify a precise height for the modal. Allowed units are 'px', '%', 'rem', 'em', 'vh' and 'vw'.
- `modalSettings.keepPrevious` **[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** Lets you open multiple modals. Keeps the previously opened modal and allows to open another modal on top of the previous one. By default the previous modals are discarded.
- `modalSettings.closebtn_data_testid` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** lets you specify a `data_testid` for the close button. Default value is `lui-modal-index-0`. If multiple modals are opened the index will be increased per modal.
- `splitViewSettings` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** opens a view in a split view. Use these settings to configure the split view's behaviour
- `splitViewSettings.title` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** split view title. By default, it is the node label. If there is no label, it is left empty
- `splitViewSettings.size` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** height of the split view in percent (optional, default `40`)
Expand Down Expand Up @@ -627,6 +629,7 @@ Opens a view in a modal. You can specify the modal's title and size. If you don'
- `modalSettings.width` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** lets you specify a precise width for the modal. Allowed units are 'px', '%', 'rem', 'em', 'vh' and 'vw'.
- `modalSettings.height` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** lets you specify a precise height for the modal. Allowed units are 'px', '%', 'rem', 'em', 'vh' and 'vw'.
- `modalSettings.keepPrevious` **[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** Lets you open multiple modals. Keeps the previously opened modal and allows to open another modal on top of the previous one. By default the previous modals are discarded.
- `modalSettings.closebtn_data_testid` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** lets you specify a `data_testid` for the close button. Default value is `lui-modal-index-0`. If multiple modals are opened the index will be increased per modal.

##### Examples

Expand Down
4 changes: 4 additions & 0 deletions docs/luigi-core-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -534,6 +534,8 @@ Navigates to the given path in the application. It contains either a full absolu
- `modalSettings.size` **(`"fullscreen"` \| `"l"` \| `"m"` \| `"s"`)** size of the modal (optional, default `"l"`)
- `modalSettings.width` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** lets you specify a precise width for the modal. Allowed units are 'px', '%', 'rem', 'em', 'vh' and 'vw'.
- `modalSettings.height` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** lets you specify a precise height for the modal. Allowed units are 'px', '%', 'rem', 'em', 'vh' and 'vw'.
- `modalSettings.keepPrevious` **[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** Lets you open multiple modals. Keeps the previously opened modal and allows to open another modal on top of the previous one. By default the previous modals are discarded.
- `modalSettings.closebtn_data_testid` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** lets you specify a `data_testid` for the close button. Default value is `lui-modal-index-0`. If multiple modals are opened the index will be increased per modal.
- `splitViewSettings` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** opens a view in a split view. Use these settings to configure the split view's behaviour
- `splitViewSettings.title` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** split view title. By default, it is the node label. If there is no label, it is left empty
- `splitViewSettings.size` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** height of the split view in percent (optional, default `40`)
Expand Down Expand Up @@ -563,6 +565,8 @@ Opens a view in a modal. You can specify the modal's title and size. If you do n
- `modalSettings.size` **(`"fullscreen"` \| `"l"` \| `"m"` \| `"s"`)** size of the modal (optional, default `"l"`)
- `modalSettings.width` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** lets you specify a precise width for the modal. Allowed units are 'px', '%', 'rem', 'em', 'vh' and 'vw'.
- `modalSettings.height` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** lets you specify a precise height for the modal. Allowed units are 'px', '%', 'rem', 'em', 'vh' and 'vw'.
- `modalSettings.keepPrevious` **[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** Lets you open multiple modals. Keeps the previously opened modal and allows to open another modal on top of the previous one. By default the previous modals are discarded.
- `modalSettings.closebtn_data_testid` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** lets you specify a `data_testid` for the close button. Default value is `lui-modal-index-0`. If multiple modals are opened the index will be increased per modal.
- `onCloseCallback` **[Function](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function)** callback function called upon closing the opened modal

##### Examples
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,21 @@ describe('Navigation', () => {
cy.get('[data-testid=modal-mf]').should('not.exist');
});

it.only('Define a data-testid for close button on modal', () => {
cy.window().then(win => {
win.Luigi.navigation().openAsModal('/projects/pr1/developers', { closebtn_data_testid: 'MyCustomTestId' });
});
cy.get('[data-testid=MyCustomTestId]')
.should('be.visible')
.click();
cy.window().then(win => {
win.Luigi.navigation().openAsModal('/projects/pr1/developers');
});
cy.get('[data-testid=lui-modal-index-0]')
.should('be.visible')
.click();
});

it('Nav sync - click sidenav', () => {
// projects page
cy.get('.fd-shellbar')
Expand Down