@mtes-mct/monitor-ui 4.0.3 → 4.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +14 -0
- package/cypress/commands/clickButton.d.ts +2 -2
- package/cypress/commands/fill/checkMultiCheckboxOptions.d.ts +1 -1
- package/cypress/commands/fill/pickSelectOption.d.ts +1 -1
- package/cypress/index.js +97 -67
- package/cypress/index.js.map +1 -1
- package/cypress/utils/findElementBytext.d.ts +1 -1
- package/fields/CoordinatesInput/index.d.ts +1 -1
- package/index.js +21 -21
- package/index.js.map +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,17 @@
|
|
|
1
|
+
## [4.0.4](https://github.com/MTES-MCT/monitor-ui/compare/v4.0.3...v4.0.4) (2023-03-30)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* **cypress:** improve fill command reliability ([26ad3f7](https://github.com/MTES-MCT/monitor-ui/commit/26ad3f7d8e5558181a4adaa9ad4cdb0f9b2ae9c7))
|
|
7
|
+
|
|
8
|
+
## [4.0.3](https://github.com/MTES-MCT/monitor-ui/compare/v4.0.2...v4.0.3) (2023-03-29)
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Bug Fixes
|
|
12
|
+
|
|
13
|
+
* **fields:** handle value change in MultiSelect ([e4b80fa](https://github.com/MTES-MCT/monitor-ui/commit/e4b80fa78de54085d905a7e1afded79440c157e7))
|
|
14
|
+
|
|
1
15
|
## [4.0.2](https://github.com/MTES-MCT/monitor-ui/compare/v4.0.1...v4.0.2) (2023-03-29)
|
|
2
16
|
|
|
3
17
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/// <reference types="cypress" />
|
|
2
2
|
/// <reference types="cypress" />
|
|
3
|
-
export declare function clickButton(label: string, { index, withinSelector }?: Partial<{
|
|
3
|
+
export declare function clickButton(prevSubjectElements: HTMLElement[] | undefined, label: string, { index, withinSelector }?: Partial<{
|
|
4
4
|
index: number | undefined;
|
|
5
5
|
withinSelector: string | undefined;
|
|
6
|
-
}>, leftRetries?: number): Cypress.Chainable<JQuery<
|
|
6
|
+
}>, leftRetries?: number): Cypress.Chainable<JQuery<HTMLElement>>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare function checkMultiCheckboxOptions(fieldsetElement: HTMLElement, values: string[] | undefined):
|
|
1
|
+
export declare function checkMultiCheckboxOptions(fieldsetElement: HTMLElement, values: string[] | undefined, leftRetries?: number): void;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
/// <reference types="cypress" />
|
|
2
2
|
/// <reference types="cypress" />
|
|
3
|
-
export declare function pickSelectOption(cypressSelectInputElement: Cypress.Chainable<JQuery<HTMLElement>>, value: string | undefined):
|
|
3
|
+
export declare function pickSelectOption(cypressSelectInputElement: Cypress.Chainable<JQuery<HTMLElement>>, value: string | undefined): void;
|
package/cypress/index.js
CHANGED
|
@@ -47,29 +47,47 @@ function findElementBytext(selector, text, { fallbackSelector, index = 0, inElem
|
|
|
47
47
|
return foundElement;
|
|
48
48
|
}
|
|
49
49
|
|
|
50
|
-
const RETRIES$
|
|
51
|
-
function clickButton(label, { index = 0, withinSelector } = {}, leftRetries = RETRIES$
|
|
50
|
+
const RETRIES$2 = 5;
|
|
51
|
+
function clickButton(prevSubjectElements, label, { index = 0, withinSelector } = {}, leftRetries = RETRIES$2) {
|
|
52
|
+
const prevSubjectElement = prevSubjectElements ? prevSubjectElements[0] : undefined;
|
|
53
|
+
if (prevSubjectElements && !prevSubjectElements[0]) {
|
|
54
|
+
throw new Error('`prevSubjectElements[0]` is undefined.');
|
|
55
|
+
}
|
|
52
56
|
const preSelector = withinSelector ? `${withinSelector} ` : '';
|
|
53
|
-
const
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
57
|
+
const iconButtonElementByAriaLabel = prevSubjectElement
|
|
58
|
+
? Cypress.$(prevSubjectElement).find(`${preSelector}button[aria-label="${label}"]`).get(index)
|
|
59
|
+
: Cypress.$(`${preSelector}button[aria-label="${label}"]`).get(index);
|
|
60
|
+
const iconButtonElementByTitle = prevSubjectElement
|
|
61
|
+
? Cypress.$(prevSubjectElement).find(`${preSelector}button[aria-label="${label}"]`).get(index)
|
|
62
|
+
: Cypress.$(`${preSelector}button[title="${label}"]`).get(index);
|
|
63
|
+
const textButtonElement = findElementBytext(`${preSelector}button`, label, {
|
|
64
|
+
index,
|
|
65
|
+
inElement: prevSubjectElement
|
|
66
|
+
});
|
|
67
|
+
const menuItemElement = findElementBytext(`${preSelector}[role="menuitem"]`, label, {
|
|
68
|
+
index,
|
|
69
|
+
inElement: prevSubjectElement
|
|
70
|
+
});
|
|
71
|
+
if (iconButtonElementByAriaLabel) {
|
|
72
|
+
return cy.wrap(iconButtonElementByAriaLabel).scrollIntoView().click({ force: true }).wait(250);
|
|
73
|
+
}
|
|
74
|
+
if (iconButtonElementByTitle) {
|
|
75
|
+
return cy.wrap(iconButtonElementByTitle).scrollIntoView().click({ force: true }).wait(250);
|
|
58
76
|
}
|
|
59
77
|
if (menuItemElement) {
|
|
60
78
|
return cy
|
|
61
79
|
.wrap(menuItemElement)
|
|
62
80
|
.scrollIntoView()
|
|
63
|
-
.
|
|
81
|
+
.forceClick()
|
|
64
82
|
.wait(250);
|
|
65
83
|
}
|
|
66
84
|
if (textButtonElement) {
|
|
67
|
-
return cy.wrap(textButtonElement).scrollIntoView().
|
|
85
|
+
return cy.wrap(textButtonElement).scrollIntoView().forceClick().wait(250);
|
|
68
86
|
}
|
|
69
87
|
if (leftRetries > 0) {
|
|
70
88
|
return cy.wait(250).then(() => {
|
|
71
|
-
cy.log(`Retrying (${RETRIES$
|
|
72
|
-
return clickButton(label, { index, withinSelector }, leftRetries - 1);
|
|
89
|
+
cy.log(`Retrying (${RETRIES$2 - leftRetries + 1} / ${RETRIES$2})...`);
|
|
90
|
+
return clickButton(prevSubjectElements, label, { index, withinSelector }, leftRetries - 1);
|
|
73
91
|
});
|
|
74
92
|
}
|
|
75
93
|
throw new Error(`Unable to find button with label "${label}".`);
|
|
@@ -81,7 +99,7 @@ function clickButton(label, { index = 0, withinSelector } = {}, leftRetries = RE
|
|
|
81
99
|
*/
|
|
82
100
|
function clickOutside(xPosition = 0, yPosition = 0) {
|
|
83
101
|
cy.log(`Click outside at position: ${xPosition}, ${yPosition}`);
|
|
84
|
-
cy.get('body').click(xPosition, yPosition);
|
|
102
|
+
cy.get('body').click(xPosition, yPosition, { force: true });
|
|
85
103
|
}
|
|
86
104
|
|
|
87
105
|
// I have no idea why I have to add this dirty hack of setting an external variable
|
|
@@ -676,14 +694,22 @@ function checkCheckbox(checkboxInputElement, value) {
|
|
|
676
694
|
}
|
|
677
695
|
}
|
|
678
696
|
|
|
679
|
-
|
|
680
|
-
|
|
697
|
+
const RETRIES$1 = 5;
|
|
698
|
+
function checkMultiCheckboxOptions(fieldsetElement, values, leftRetries = RETRIES$1) {
|
|
699
|
+
cy.wrap(fieldsetElement).scrollIntoView();
|
|
700
|
+
cy.wrap(fieldsetElement).find('input[type="checkbox"]').uncheck({ force: true }).wait(250);
|
|
701
|
+
if (fieldsetElement.querySelector('[aria-checked="true"]') && leftRetries > 0) {
|
|
702
|
+
cy.wait(250).then(() => {
|
|
703
|
+
cy.log(`Retrying (${RETRIES$1 - leftRetries + 1} / ${RETRIES$1})...`);
|
|
704
|
+
checkMultiCheckboxOptions(fieldsetElement, values, leftRetries - 1);
|
|
705
|
+
});
|
|
706
|
+
return;
|
|
707
|
+
}
|
|
681
708
|
if (values) {
|
|
682
709
|
values.forEach(value => {
|
|
683
710
|
cy.wrap(fieldsetElement).find('label').contains(value).find('input[type="checkbox"]').check({ force: true });
|
|
684
711
|
});
|
|
685
712
|
}
|
|
686
|
-
return fieldsetElement;
|
|
687
713
|
}
|
|
688
714
|
|
|
689
715
|
function checkMultiRadioOption(fieldsetElement, value) {
|
|
@@ -707,7 +733,7 @@ function fillTextarea(textareaElement, value) {
|
|
|
707
733
|
|
|
708
734
|
function fillTextInput(textInputElement, value) {
|
|
709
735
|
if (value) {
|
|
710
|
-
cy.wrap(textInputElement).scrollIntoView().type(value);
|
|
736
|
+
cy.wrap(textInputElement).scrollIntoView().type(value, { force: true });
|
|
711
737
|
}
|
|
712
738
|
else {
|
|
713
739
|
cy.wrap(textInputElement).scrollIntoView().clear();
|
|
@@ -715,51 +741,49 @@ function fillTextInput(textInputElement, value) {
|
|
|
715
741
|
}
|
|
716
742
|
|
|
717
743
|
function pickMultiSelectOptions(cypressMultiSelectInputElement, values) {
|
|
718
|
-
cypressMultiSelectInputElement
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
.parent()
|
|
722
|
-
.parent()
|
|
723
|
-
.parent()
|
|
724
|
-
.then(([rsuiteMultiSelectWrapperElement]) => {
|
|
725
|
-
if (!rsuiteMultiSelectWrapperElement) {
|
|
726
|
-
throw new Error('This should never happen.');
|
|
744
|
+
cypressMultiSelectInputElement.parents('.Field-MultiSelect').then(([fieldElement]) => {
|
|
745
|
+
if (!fieldElement) {
|
|
746
|
+
throw new Error('`fieldElement` is undefined.');
|
|
727
747
|
}
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
748
|
+
cy.wrap(fieldElement).scrollIntoView();
|
|
749
|
+
const maybeCleanButton = fieldElement.querySelector('.rs-picker-toggle-clean');
|
|
750
|
+
if (maybeCleanButton) {
|
|
751
|
+
cy.wrap(fieldElement).find('.rs-picker-toggle-clean').forceClick().wait(250);
|
|
731
752
|
}
|
|
732
753
|
if (!values) {
|
|
733
754
|
return;
|
|
734
755
|
}
|
|
735
|
-
cy.wrap(
|
|
736
|
-
cy.
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
throw new Error('This should never happen.');
|
|
756
|
+
cy.wrap(fieldElement).find('.rs-picker-toggle-caret').forceClick();
|
|
757
|
+
cy.get('.rs-picker-picker-check-menu').then(([multiSelectMenuElement]) => {
|
|
758
|
+
if (!multiSelectMenuElement) {
|
|
759
|
+
throw new Error('`multiSelectMenuElement` is undefined.');
|
|
740
760
|
}
|
|
741
|
-
const maybeSearchInput =
|
|
761
|
+
const maybeSearchInput = multiSelectMenuElement.querySelector('.rs-picker-search-bar-input');
|
|
742
762
|
values.forEach(value => {
|
|
743
763
|
if (maybeSearchInput) {
|
|
744
|
-
cy.
|
|
764
|
+
cy.get('.rs-picker-picker-check-menu').find('.rs-picker-search-bar-input').type(value);
|
|
745
765
|
}
|
|
746
|
-
cy.get('.rs-
|
|
766
|
+
cy.get('.rs-picker-picker-check-menu')
|
|
767
|
+
.find('.rs-checkbox-checker')
|
|
768
|
+
.contains(value)
|
|
769
|
+
.scrollIntoView()
|
|
770
|
+
.forceClick();
|
|
747
771
|
});
|
|
748
|
-
const offsetLeft =
|
|
749
|
-
?
|
|
772
|
+
const offsetLeft = fieldElement.offsetLeft
|
|
773
|
+
? fieldElement.offsetLeft
|
|
750
774
|
: (() => {
|
|
751
|
-
if (!
|
|
752
|
-
throw new Error('`
|
|
775
|
+
if (!fieldElement.offsetParent) {
|
|
776
|
+
throw new Error('`fieldElement.offsetParent` is undefined.');
|
|
753
777
|
}
|
|
754
|
-
return
|
|
778
|
+
return fieldElement.offsetParent.offsetLeft;
|
|
755
779
|
})();
|
|
756
|
-
const offsetTop =
|
|
757
|
-
?
|
|
780
|
+
const offsetTop = fieldElement.offsetTop !== 0
|
|
781
|
+
? fieldElement.offsetTop
|
|
758
782
|
: (() => {
|
|
759
|
-
if (!
|
|
760
|
-
throw new Error('`
|
|
783
|
+
if (!fieldElement.offsetParent) {
|
|
784
|
+
throw new Error('`fieldElement.offsetParent` is undefined.');
|
|
761
785
|
}
|
|
762
|
-
return
|
|
786
|
+
return fieldElement.offsetParent.offsetTop;
|
|
763
787
|
})();
|
|
764
788
|
// TODO Investigate that (this should be -1).
|
|
765
789
|
cy.clickOutside(offsetLeft, offsetTop - 16);
|
|
@@ -770,36 +794,36 @@ function pickMultiSelectOptions(cypressMultiSelectInputElement, values) {
|
|
|
770
794
|
|
|
771
795
|
function pickSelectOption(cypressSelectInputElement, value) {
|
|
772
796
|
cypressSelectInputElement
|
|
773
|
-
.
|
|
774
|
-
.parent()
|
|
775
|
-
.parent()
|
|
776
|
-
.parent()
|
|
777
|
-
.parent()
|
|
797
|
+
.parents('.Field-Select')
|
|
778
798
|
.scrollIntoView()
|
|
779
|
-
.then(([
|
|
780
|
-
if (!
|
|
781
|
-
throw new Error('
|
|
799
|
+
.then(([fieldElement]) => {
|
|
800
|
+
if (!fieldElement) {
|
|
801
|
+
throw new Error('`fieldElement` is undefined.');
|
|
782
802
|
}
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
803
|
+
cy.wrap(fieldElement).scrollIntoView();
|
|
804
|
+
const maybeCleanButton = fieldElement.querySelector('.rs-picker-toggle-clean');
|
|
805
|
+
if (maybeCleanButton) {
|
|
806
|
+
cy.wrap(fieldElement).find('.rs-picker-toggle-clean').scrollIntoView().forceClick().wait(250);
|
|
786
807
|
}
|
|
787
808
|
if (!value) {
|
|
788
809
|
return;
|
|
789
810
|
}
|
|
790
|
-
cy.wrap(
|
|
791
|
-
cy.get('.rs-picker-select-menu').then(([
|
|
792
|
-
if (!
|
|
793
|
-
throw new Error('
|
|
811
|
+
cy.wrap(fieldElement).find('.rs-picker-toggle-caret').click();
|
|
812
|
+
cy.get('.rs-picker-select-menu').then(([selectMenuElement]) => {
|
|
813
|
+
if (!selectMenuElement) {
|
|
814
|
+
throw new Error('`selectMenuElement` is undefined.');
|
|
794
815
|
}
|
|
795
|
-
const maybeSearchInput =
|
|
816
|
+
const maybeSearchInput = selectMenuElement.querySelector('.rs-picker-search-bar-input');
|
|
796
817
|
if (maybeSearchInput) {
|
|
797
|
-
cy.wrap(
|
|
818
|
+
cy.wrap(selectMenuElement).find('.rs-picker-search-bar-input').type(value);
|
|
798
819
|
}
|
|
799
|
-
cy.
|
|
820
|
+
cy.wrap(selectMenuElement)
|
|
821
|
+
.get('.rs-picker-select-menu-item')
|
|
822
|
+
.contains(value)
|
|
823
|
+
.scrollIntoView()
|
|
824
|
+
.click({ force: true });
|
|
800
825
|
});
|
|
801
826
|
});
|
|
802
|
-
return cypressSelectInputElement;
|
|
803
827
|
}
|
|
804
828
|
|
|
805
829
|
/* eslint-disable cypress/no-assigning-return-values */
|
|
@@ -917,14 +941,20 @@ function forceClick([subject]) {
|
|
|
917
941
|
if (!subject) {
|
|
918
942
|
throw new Error(`Could not find subject.`);
|
|
919
943
|
}
|
|
920
|
-
|
|
944
|
+
console.log(subject);
|
|
945
|
+
try {
|
|
946
|
+
return subject.click({ force: true });
|
|
947
|
+
}
|
|
948
|
+
catch (_) {
|
|
949
|
+
return cy.wrap(subject).click({ force: true });
|
|
950
|
+
}
|
|
921
951
|
}
|
|
922
952
|
|
|
923
953
|
function getDataCy(dataCy) {
|
|
924
954
|
return cy.get(`[data-cy="${dataCy}"]`);
|
|
925
955
|
}
|
|
926
956
|
|
|
927
|
-
Cypress.Commands.add('clickButton', clickButton);
|
|
957
|
+
Cypress.Commands.add('clickButton', { prevSubject: 'optional' }, clickButton);
|
|
928
958
|
Cypress.Commands.add('clickLink', (linkText) => cy.get('a').contains(linkText).click());
|
|
929
959
|
/**
|
|
930
960
|
* @description
|