1- import { test , expect } from "@playwright/test" ;
1+ import { expect , test } from "@playwright/test" ;
22
33test . afterEach ( "Cleanup session" , async ( { page } ) => {
44 // Because the test isolation that will open a new session for every test executed, and that exceeds Mendix's license limit of 5 sessions, so we need to force logout after each test.
@@ -10,14 +10,15 @@ test.describe("combobox-web", () => {
1010 await page . goto ( "/p/combobox" ) ;
1111 await page . waitForLoadState ( "networkidle" ) ;
1212 await page . click ( ".mx-name-actionButton1" ) ;
13+ await page . waitForLoadState ( "networkidle" ) ;
1314 } ) ;
1415
1516 test . describe ( "data source types" , ( ) => {
1617 test ( "renders combobox using association" , async ( { page } ) => {
1718 const comboBox = page . locator ( ".mx-name-comboBox1" ) ;
1819 await expect ( comboBox ) . toBeVisible ( { timeout : 10000 } ) ;
1920 await expect ( comboBox ) . toHaveScreenshot ( `comboBoxAssociation.png` ) ;
20- await page . click ( ".mx-name-comboBox1" ) ;
21+ await comboBox . click ( ) ;
2122 await expect ( page . locator ( ".modal-body .mx-name-layoutGrid1" ) . first ( ) ) . toHaveScreenshot (
2223 `comboBoxAssociationOpen.png`
2324 ) ;
@@ -28,7 +29,7 @@ test.describe("combobox-web", () => {
2829 const comboBox = page . locator ( ".mx-name-comboBox4" ) ;
2930 await expect ( comboBox ) . toBeVisible ( { timeout : 10000 } ) ;
3031 await expect ( comboBox ) . toHaveScreenshot ( `comboBoxAssociationRowClick.png` ) ;
31- await page . click ( ".mx-name-comboBox4" ) ;
32+ await comboBox . click ( ) ;
3233 await expect ( page . locator ( ".modal-body .mx-name-layoutGrid1" ) . first ( ) ) . toHaveScreenshot (
3334 `comboBoxAssociationRowClickOpen.png`
3435 ) ;
@@ -38,7 +39,7 @@ test.describe("combobox-web", () => {
3839 const comboBox = page . locator ( ".mx-name-comboBox2" ) ;
3940 await expect ( comboBox ) . toBeVisible ( { timeout : 10000 } ) ;
4041 await expect ( comboBox ) . toHaveScreenshot ( `comboBoxEnum.png` ) ;
41- await page . click ( ".mx-name-comboBox2" ) ;
42+ await comboBox . click ( ) ;
4243 await expect ( page . locator ( ".modal-body .mx-name-layoutGrid1" ) . first ( ) ) . toHaveScreenshot (
4344 `comboBoxEnumOpen.png`
4445 ) ;
@@ -48,7 +49,7 @@ test.describe("combobox-web", () => {
4849 await page . click ( ".mx-name-tabPage2" ) ;
4950 const comboBox = page . locator ( ".mx-name-comboBox5" ) ;
5051 await expect ( comboBox ) . toBeVisible ( { timeout : 10000 } ) ;
51- await page . click ( ".mx-name-comboBox5" ) ;
52+ await comboBox . click ( ) ;
5253 await expect ( page . locator ( ".mx-name-comboBox5 .widget-combobox-menu" ) . first ( ) ) . toHaveScreenshot (
5354 `comboBoxEnumFooter.png`
5455 ) ;
@@ -58,15 +59,15 @@ test.describe("combobox-web", () => {
5859 await page . click ( ".mx-name-tabPage2" ) ;
5960 const comboBox = page . locator ( ".mx-name-comboBox6" ) ;
6061 await expect ( comboBox ) . toBeVisible ( { timeout : 10000 } ) ;
61- await page . click ( ".mx-name-comboBox6" ) ;
62+ await comboBox . click ( ) ;
6263 await expect ( comboBox ) . toHaveScreenshot ( `comboBoxReadOnly.png` ) ;
6364 } ) ;
6465
6566 test ( "renders combobox using boolean" , async ( { page } ) => {
6667 const comboBox = page . locator ( ".mx-name-comboBox3" ) ;
6768 await expect ( comboBox ) . toBeVisible ( { timeout : 10000 } ) ;
6869 await expect ( comboBox ) . toHaveScreenshot ( `comboBoxBoolean.png` ) ;
69- await page . click ( ".mx-name-comboBox3" ) ;
70+ await comboBox . click ( ) ;
7071 await expect ( page . locator ( ".modal-body .mx-name-layoutGrid1" ) . first ( ) ) . toHaveScreenshot (
7172 `comboBoxBooleanOpen.png`
7273 ) ;
@@ -77,7 +78,7 @@ test.describe("combobox-web", () => {
7778 const comboBox = page . locator ( ".mx-name-comboBox7" ) ;
7879 await expect ( comboBox ) . toBeVisible ( { timeout : 10000 } ) ;
7980 await expect ( comboBox ) . toHaveScreenshot ( `comboBoxStatic.png` ) ;
80- await page . click ( ".mx-name-comboBox7" ) ;
81+ await comboBox . click ( ) ;
8182 await expect ( page . locator ( ".modal-body .mx-name-layoutGrid1" ) . first ( ) ) . toHaveScreenshot (
8283 `comboBoxStaticOpen.png`
8384 ) ;
@@ -88,7 +89,7 @@ test.describe("combobox-web", () => {
8889 const comboBox = page . locator ( ".mx-name-comboBox8" ) ;
8990 await expect ( comboBox ) . toBeVisible ( { timeout : 10000 } ) ;
9091 await expect ( comboBox ) . toHaveScreenshot ( `comboBoxDatabase.png` ) ;
91- await page . click ( ".mx-name-comboBox8" ) ;
92+ await comboBox . click ( ) ;
9293 await expect ( page . locator ( ".modal-body .mx-name-layoutGrid1" ) . first ( ) ) . toHaveScreenshot (
9394 `comboBoxDatabaseOpen.png`
9495 ) ;
@@ -97,8 +98,8 @@ test.describe("combobox-web", () => {
9798 test ( "renders a filter result" , async ( { page } ) => {
9899 const comboBox = page . locator ( ".mx-name-comboBox2" ) ;
99100 await expect ( comboBox ) . toBeVisible ( { timeout : 10000 } ) ;
100- await page . click ( ".mx-name-comboBox2" ) ;
101- await page . locator ( ".mx-name-comboBox2 .widget-combobox-input" ) . fill ( "A" ) ;
101+ await comboBox . click ( ) ;
102+ await getFilterInput ( comboBox ) . fill ( "A" ) ;
102103 await expect ( page . locator ( ".modal-body .mx-name-layoutGrid1" ) . first ( ) ) . toHaveScreenshot (
103104 `comboBoxFiltering.png`
104105 ) ;
@@ -108,7 +109,7 @@ test.describe("combobox-web", () => {
108109 await page . click ( ".mx-name-tabPage2" ) ;
109110 const comboBox = page . locator ( ".mx-name-comboBox4" ) ;
110111 await expect ( comboBox ) . toBeVisible ( { timeout : 10000 } ) ;
111- await page . locator ( ".mx-name-comboBox4 .widget-combobox-icon-container" ) . first ( ) . click ( ) ;
112+ await comboBox . locator ( ".widget-combobox-icon-container" ) . first ( ) . click ( ) ;
112113 await expect ( page . locator ( ".modal-body .mx-name-layoutGrid1" ) . first ( ) ) . toHaveScreenshot (
113114 `comboBoxRemoveSelection.png`
114115 ) ;
@@ -118,11 +119,77 @@ test.describe("combobox-web", () => {
118119 await page . click ( ".mx-name-tabPage2" ) ;
119120 const comboBox = page . locator ( ".mx-name-comboBox4" ) ;
120121 await expect ( comboBox ) . toBeVisible ( { timeout : 10000 } ) ;
121- await page . locator ( ".mx-name-comboBox4 .widget-combobox-clear-button" ) . nth ( 3 ) . click ( ) ;
122+ await comboBox . locator ( ".widget-combobox-clear-button" ) . nth ( 3 ) . click ( ) ;
122123 await expect ( page . locator ( ".modal-body .mx-name-layoutGrid1" ) . first ( ) ) . toHaveScreenshot (
123124 `comboBoxRemoveAllSelection.png`
124125 ) ;
125126 } ) ;
126127 } ) ;
127128 } ) ;
129+
130+ test . describe ( "searching and selecting" , ( ) => {
131+ test ( "clears with backspace" , async ( { page } ) => {
132+ const comboBox = page . locator ( ".mx-name-comboBox2" ) ;
133+ await expect ( comboBox ) . toBeVisible ( { timeout : 10000 } ) ;
134+
135+ // check nothing is selected
136+ await expect ( getSelectedText ( comboBox ) ) . toContainClass ( "widget-combobox-placeholder-empty" ) ;
137+
138+ // open the dropdown
139+ await page . click ( ".mx-name-comboBox2" ) ;
140+
141+ // select europe
142+ await getOptionItem ( comboBox , "Europe" ) . click ( { delay : 10 } ) ;
143+ await expect ( getSelectedText ( comboBox ) ) . toContainText ( "Europe" ) ;
144+
145+ // check input stays focused
146+ await expect ( getFilterInput ( comboBox ) ) . toBeFocused ( ) ;
147+
148+ // press Backspace to clear
149+ await page . keyboard . press ( "Backspace" ) ;
150+
151+ // check if cleared
152+ await expect ( getSelectedText ( comboBox ) ) . toContainClass ( "widget-combobox-placeholder-empty" ) ;
153+ } ) ;
154+
155+ test ( "types filter when selected" , async ( { page } ) => {
156+ const comboBox = page . locator ( ".mx-name-comboBox2" ) ;
157+ await expect ( comboBox ) . toBeVisible ( { timeout : 10000 } ) ;
158+
159+ // check nothing is selected
160+ await expect ( getSelectedText ( comboBox ) ) . toContainClass ( "widget-combobox-placeholder-empty" ) ;
161+
162+ // open the dropdown
163+ await page . click ( ".mx-name-comboBox2" ) ;
164+
165+ // select europe
166+ await getOptionItem ( comboBox , "Europe" ) . click ( { delay : 10 } ) ;
167+ await expect ( getSelectedText ( comboBox ) ) . toContainText ( "Europe" ) ;
168+
169+ // check input stays focused
170+ await expect ( getFilterInput ( comboBox ) ) . toBeFocused ( ) ;
171+
172+ // type filter text
173+ await page . keyboard . type ( "aaa" ) ;
174+
175+ // check if filtered
176+ await expect ( getOptions ( comboBox ) ) . toHaveText ( [ "Antartica" , "Australia" ] ) ;
177+ } ) ;
178+ } ) ;
128179} ) ;
180+
181+ function getOptions ( combobox ) {
182+ return combobox . locator ( `[role=listbox] [role=option]` ) ;
183+ }
184+
185+ function getOptionItem ( combobox , text ) {
186+ return combobox . locator ( `[role=listbox] [role=option]:has-text("${ text } ")` ) ;
187+ }
188+
189+ function getSelectedText ( combobox ) {
190+ return combobox . locator ( ".widget-combobox-placeholder-text" ) ;
191+ }
192+
193+ function getFilterInput ( combobox ) {
194+ return combobox . locator ( "input" ) ;
195+ }
0 commit comments