|
| 1 | +import DataGrid from 'devextreme-testcafe-models/dataGrid'; |
| 2 | +import { createWidget } from '../../../../helpers/createWidget'; |
| 3 | +import url from '../../../../helpers/getPageUrl'; |
| 4 | + |
| 5 | +fixture.disablePageReloads`Grouping Panel - check borders and backgrounds with various options` |
| 6 | + .page(url(__dirname, '../../../container.html')); |
| 7 | + |
| 8 | +interface MatrixOptions { |
| 9 | + rowAlternationEnabled: boolean; |
| 10 | + showColumnLines: boolean; |
| 11 | + showRowLines: boolean; |
| 12 | + showBorders: boolean; |
| 13 | + hasFixedColumn: boolean; |
| 14 | + hasMasterDetail: boolean; |
| 15 | +} |
| 16 | + |
| 17 | +const SELECTORS = { |
| 18 | + gridContainer: 'container', |
| 19 | + masterDetailRowClass: 'dx-master-detail-row', |
| 20 | + groupRowClass: 'dx-group-row', |
| 21 | + rowLinesClass: 'dx-row-lines', |
| 22 | + groupSpaceClass: 'dx-datagrid-group-space', |
| 23 | + pointerEventsNoneClass: 'dx-pointer-events-none', |
| 24 | + rowAlternativeClass: 'dx-row-alt', |
| 25 | +}; |
| 26 | + |
| 27 | +const BORDER_WIDTH = { |
| 28 | + big: 2, |
| 29 | + normal: 1, |
| 30 | + none: 0, |
| 31 | +}; |
| 32 | + |
| 33 | +const dataSource = [ |
| 34 | + { |
| 35 | + group: 'A', |
| 36 | + label: 'LABEL_A_0', |
| 37 | + value: 'VALUE_A_0', |
| 38 | + count: 1, |
| 39 | + }, |
| 40 | + { |
| 41 | + group: 'A', |
| 42 | + label: 'LABEL_A_1', |
| 43 | + value: 'VALUE_A_1', |
| 44 | + count: 2, |
| 45 | + }, |
| 46 | + { |
| 47 | + group: 'B', |
| 48 | + label: 'LABEL_B_0', |
| 49 | + value: 'VALUE_B_0', |
| 50 | + count: 3, |
| 51 | + }, |
| 52 | + { |
| 53 | + group: 'B', |
| 54 | + label: 'LABEL_B_1', |
| 55 | + value: 'VALUE_B_1', |
| 56 | + count: 4, |
| 57 | + }, |
| 58 | + { |
| 59 | + group: 'B', |
| 60 | + label: 'LABEL_B_2', |
| 61 | + value: 'VALUE_B_2', |
| 62 | + count: 5, |
| 63 | + }, |
| 64 | + { |
| 65 | + group: 'C', |
| 66 | + label: 'LABEL_C_0', |
| 67 | + value: 'VALUE_C_0', |
| 68 | + count: 6, |
| 69 | + }, |
| 70 | + { |
| 71 | + group: 'C', |
| 72 | + label: 'LABEL_C_1', |
| 73 | + value: 'VALUE_C_1', |
| 74 | + count: 7, |
| 75 | + }, |
| 76 | +]; |
| 77 | + |
| 78 | +const getTestParams = ({ |
| 79 | + rowAlternationEnabled, |
| 80 | + showColumnLines, |
| 81 | + showRowLines, |
| 82 | + showBorders, |
| 83 | + hasFixedColumn, |
| 84 | + hasMasterDetail, |
| 85 | +}: MatrixOptions) => [ |
| 86 | + `rowAlternationEnabled: ${rowAlternationEnabled}`, |
| 87 | + `showColumnLines: ${showColumnLines}`, |
| 88 | + `showRowLines: ${showRowLines}`, |
| 89 | + `showBorders: ${showBorders}`, |
| 90 | + `hasFixedColumn: ${hasFixedColumn}`, |
| 91 | + `hasMasterDetail: ${hasMasterDetail}`, |
| 92 | +].join(', '); |
| 93 | + |
| 94 | +const createDataGrid = async ({ |
| 95 | + rowAlternationEnabled, |
| 96 | + showColumnLines, |
| 97 | + showRowLines, |
| 98 | + showBorders, |
| 99 | + hasFixedColumn, |
| 100 | + hasMasterDetail, |
| 101 | +}: MatrixOptions) => { |
| 102 | + await createWidget('dxDataGrid', { |
| 103 | + dataSource, |
| 104 | + columnFixing: { |
| 105 | + // @ts-expect-error private option |
| 106 | + legacyMode: true, |
| 107 | + }, |
| 108 | + columns: [ |
| 109 | + { |
| 110 | + dataField: 'group', |
| 111 | + groupIndex: 0, |
| 112 | + }, |
| 113 | + { |
| 114 | + dataField: 'label', |
| 115 | + fixed: hasFixedColumn, |
| 116 | + }, |
| 117 | + 'value', |
| 118 | + 'count', |
| 119 | + ], |
| 120 | + summary: { |
| 121 | + groupItems: [{ |
| 122 | + column: 'count', |
| 123 | + summaryType: 'sum', |
| 124 | + }], |
| 125 | + }, |
| 126 | + masterDetail: hasMasterDetail |
| 127 | + ? { |
| 128 | + enabled: true, |
| 129 | + autoExpandAll: true, |
| 130 | + template: ($container) => { |
| 131 | + $('<div>') |
| 132 | + .text('MASTER DETAIL') |
| 133 | + .appendTo($container); |
| 134 | + }, |
| 135 | + } |
| 136 | + : undefined, |
| 137 | + editing: { |
| 138 | + mode: 'row', |
| 139 | + allowDeleting: true, |
| 140 | + confirmDelete: false, |
| 141 | + }, |
| 142 | + showBorders, |
| 143 | + rowAlternationEnabled, |
| 144 | + showRowLines, |
| 145 | + showColumnLines, |
| 146 | + }); |
| 147 | +}; |
| 148 | + |
| 149 | +const checkShowBordersState = async ( |
| 150 | + t: TestController, |
| 151 | + dataGrid: DataGrid, |
| 152 | + showBorders: boolean, |
| 153 | +) => { |
| 154 | + const expectedBorderWidth = showBorders ? BORDER_WIDTH.normal : BORDER_WIDTH.none; |
| 155 | + |
| 156 | + const gridContainer = dataGrid.getContainer(); |
| 157 | + const containerClasses = await gridContainer.getAttribute('class'); |
| 158 | + |
| 159 | + if (showBorders) { |
| 160 | + await t.expect(containerClasses).contains('dx-datagrid-borders'); |
| 161 | + } else { |
| 162 | + await t.expect(containerClasses).notContains('dx-datagrid-borders'); |
| 163 | + } |
| 164 | + |
| 165 | + const headersContainer = dataGrid.getHeadersContainer(); |
| 166 | + |
| 167 | + const borderTop = await headersContainer.getStyleProperty('border-top-width'); |
| 168 | + const borderLeft = await headersContainer.getStyleProperty('border-left-width'); |
| 169 | + const borderRight = await headersContainer.getStyleProperty('border-right-width'); |
| 170 | + |
| 171 | + await t.expect(parseInt(borderTop, 10)).eql(expectedBorderWidth); |
| 172 | + await t.expect(parseInt(borderLeft, 10)).eql(expectedBorderWidth); |
| 173 | + await t.expect(parseInt(borderRight, 10)).eql(expectedBorderWidth); |
| 174 | + |
| 175 | + const rowsView = dataGrid.getRowsView(); |
| 176 | + |
| 177 | + const rowsViewBorderLeft = await rowsView.getStyleProperty('border-left-width'); |
| 178 | + const rowsViewBorderRight = await rowsView.getStyleProperty('border-right-width'); |
| 179 | + const rowsViewBorderBottom = await rowsView.getStyleProperty('border-bottom-width'); |
| 180 | + |
| 181 | + await t.expect(parseInt(rowsViewBorderLeft, 10)).eql(expectedBorderWidth); |
| 182 | + await t.expect(parseInt(rowsViewBorderRight, 10)).eql(expectedBorderWidth); |
| 183 | + await t.expect(parseInt(rowsViewBorderBottom, 10)).eql(expectedBorderWidth); |
| 184 | +}; |
| 185 | + |
| 186 | +const checkShowRowLinesState = async ( |
| 187 | + t: TestController, |
| 188 | + dataGrid: DataGrid, |
| 189 | + showRowLines: boolean, |
| 190 | + showBorders: boolean, |
| 191 | +) => { |
| 192 | + const expectedBorderWidth = showRowLines ? BORDER_WIDTH.normal : BORDER_WIDTH.none; |
| 193 | + /* |
| 194 | + getRows() returns double collection of rows (two tables) when |
| 195 | + columnFixing.legacyMode = true AND DataGrid has fixed columns |
| 196 | + */ |
| 197 | + const filteredRows = dataGrid.getRows().filter(`.${SELECTORS.rowLinesClass}`); |
| 198 | + const cells = filteredRows.find('td'); |
| 199 | + const cellsCount = await cells.count; |
| 200 | + |
| 201 | + for (let i = 0; i < cellsCount; i += 1) { |
| 202 | + const dataCell = cells.nth(i); |
| 203 | + |
| 204 | + // Skip checking for last lines if showBorders is enabled |
| 205 | + if (showBorders) { |
| 206 | + const parentRow = dataCell.parent('tr'); |
| 207 | + const nextRow = parentRow.nextSibling('tr.dx-row-lines'); |
| 208 | + const isLastRow = await nextRow.count === 0; |
| 209 | + |
| 210 | + if (isLastRow) { |
| 211 | + // eslint-disable-next-line no-continue |
| 212 | + continue; |
| 213 | + } |
| 214 | + } |
| 215 | + |
| 216 | + const borderBottom = await dataCell.getStyleProperty('border-bottom-width'); |
| 217 | + await t.expect(parseInt(borderBottom, 10)).eql(expectedBorderWidth); |
| 218 | + } |
| 219 | +}; |
| 220 | + |
| 221 | +const checkShowColumnLinesState = async ( |
| 222 | + t: TestController, |
| 223 | + dataGrid: DataGrid, |
| 224 | + showColumnLines: boolean, |
| 225 | +) => { |
| 226 | + const getExpBorderWith = ( |
| 227 | + isColumnLinesEnabled: boolean, |
| 228 | + hasPointerEventsNoneClass: boolean, |
| 229 | + ) => { |
| 230 | + if (hasPointerEventsNoneClass) { |
| 231 | + return BORDER_WIDTH.big; |
| 232 | + } |
| 233 | + |
| 234 | + if (isColumnLinesEnabled) { |
| 235 | + return BORDER_WIDTH.normal; |
| 236 | + } |
| 237 | + |
| 238 | + return BORDER_WIDTH.none; |
| 239 | + }; |
| 240 | + |
| 241 | + /* |
| 242 | + getRows() returns double collection of rows (two tables) when |
| 243 | + columnFixing.legacyMode = true AND DataGrid has fixed columns |
| 244 | + */ |
| 245 | + const filteredRows = dataGrid.getRows().filter(`:not(.${SELECTORS.masterDetailRowClass})`); |
| 246 | + const cells = filteredRows.find(`td:not(.${SELECTORS.groupSpaceClass})`); |
| 247 | + |
| 248 | + const cellsCount = await cells.count; |
| 249 | + |
| 250 | + for (let i = 0; i < cellsCount; i += 1) { |
| 251 | + const cell = cells.nth(i); |
| 252 | + |
| 253 | + const parentRow = cell.parent('tr'); |
| 254 | + const rowCells = parentRow.find(`td:not(.${SELECTORS.groupSpaceClass})`); |
| 255 | + const rowCellsCount = await rowCells.count; |
| 256 | + const indexInRow = await cell.prevSibling(`td:not(.${SELECTORS.groupSpaceClass})`).count; |
| 257 | + |
| 258 | + const isFirstCellInRow = indexInRow === 0; |
| 259 | + const isLastCellInRow = indexInRow === rowCellsCount - 1; |
| 260 | + |
| 261 | + const cellClasses = await cell.getAttribute('class'); |
| 262 | + const hasPointerEventsNoneClass = cellClasses?.includes(SELECTORS.pointerEventsNoneClass); |
| 263 | + const expectedBorderWidth = getExpBorderWith(showColumnLines, !!hasPointerEventsNoneClass); |
| 264 | + |
| 265 | + if (!isFirstCellInRow) { |
| 266 | + const borderLeftWidth = await cell.getStyleProperty('border-left-width'); |
| 267 | + |
| 268 | + await t.expect(parseInt(borderLeftWidth, 10)).eql(expectedBorderWidth); |
| 269 | + } |
| 270 | + |
| 271 | + if (!isLastCellInRow) { |
| 272 | + const borderRightWidth = await cell.getStyleProperty('border-right-width'); |
| 273 | + |
| 274 | + await t.expect(parseInt(borderRightWidth, 10)).eql(expectedBorderWidth); |
| 275 | + } |
| 276 | + } |
| 277 | +}; |
| 278 | + |
| 279 | +const checkRowAlternationEnabledState = async ( |
| 280 | + t: TestController, |
| 281 | + dataGrid: DataGrid, |
| 282 | + rowAlternationEnabled: boolean, |
| 283 | +) => { |
| 284 | + /* |
| 285 | + getRows() returns double collection of rows (two tables) when |
| 286 | + columnFixing.legacyMode = true AND DataGrid has fixed columns |
| 287 | + */ |
| 288 | + const filteredRows = dataGrid.getRows().filter(`:not(.${SELECTORS.masterDetailRowClass})`); |
| 289 | + const filteredRowsLength = await filteredRows.count; |
| 290 | + |
| 291 | + let i = 1; |
| 292 | + while (i < filteredRowsLength) { |
| 293 | + const currentRow = filteredRows.nth(i); |
| 294 | + const previousRow = filteredRows.nth(i - 1); |
| 295 | + |
| 296 | + const currentClasses = await currentRow.getAttribute('class'); |
| 297 | + const previousClasses = await previousRow.getAttribute('class'); |
| 298 | + |
| 299 | + if (currentClasses?.includes(SELECTORS.groupRowClass)) { |
| 300 | + i += 2; |
| 301 | + // eslint-disable-next-line no-continue |
| 302 | + continue; |
| 303 | + } |
| 304 | + |
| 305 | + if (previousClasses?.includes(SELECTORS.groupRowClass)) { |
| 306 | + i += 1; |
| 307 | + // eslint-disable-next-line no-continue |
| 308 | + continue; |
| 309 | + } |
| 310 | + |
| 311 | + const currentHasAltClass = currentClasses?.includes(SELECTORS.rowAlternativeClass); |
| 312 | + const previousHasAltClass = previousClasses?.includes(SELECTORS.rowAlternativeClass); |
| 313 | + |
| 314 | + if (rowAlternationEnabled) { |
| 315 | + await t.expect(currentHasAltClass).notEql(previousHasAltClass); |
| 316 | + } else { |
| 317 | + await t.expect(currentHasAltClass).eql(previousHasAltClass); |
| 318 | + } |
| 319 | + |
| 320 | + const currentFirstCell = currentRow.find('td').nth(0); |
| 321 | + const previousFirstCell = previousRow.find('td').nth(0); |
| 322 | + |
| 323 | + const currentFirstCellBg = await currentFirstCell.getStyleProperty('background-color'); |
| 324 | + const previousFirstCellBg = await previousFirstCell.getStyleProperty('background-color'); |
| 325 | + |
| 326 | + if (rowAlternationEnabled) { |
| 327 | + await t.expect(currentFirstCellBg).notEql(previousFirstCellBg); |
| 328 | + } else { |
| 329 | + await t.expect(currentFirstCellBg).eql(previousFirstCellBg); |
| 330 | + } |
| 331 | + |
| 332 | + i += 1; |
| 333 | + } |
| 334 | +}; |
| 335 | + |
| 336 | +const verifyGridStyles = async (t: TestController, dataGrid: DataGrid, { |
| 337 | + showBorders, showRowLines, rowAlternationEnabled, showColumnLines, |
| 338 | +}: MatrixOptions) => { |
| 339 | + await checkShowBordersState(t, dataGrid, showBorders); |
| 340 | + await checkShowRowLinesState(t, dataGrid, showRowLines, showBorders); |
| 341 | + await checkShowColumnLinesState(t, dataGrid, showColumnLines); |
| 342 | + await checkRowAlternationEnabledState(t, dataGrid, rowAlternationEnabled); |
| 343 | +}; |
| 344 | + |
| 345 | +const functionalTest = (matrixOptions: MatrixOptions) => { |
| 346 | + test(`Should have correct applied styles with ${getTestParams(matrixOptions)}`, async (t) => { |
| 347 | + const dataGrid = new DataGrid(`#${SELECTORS.gridContainer}`); |
| 348 | + await dataGrid.isReady(); |
| 349 | + |
| 350 | + await verifyGridStyles(t, dataGrid, matrixOptions); |
| 351 | + |
| 352 | + const rowIdx = matrixOptions.hasMasterDetail ? 8 : 5; |
| 353 | + const colIdx = matrixOptions.hasMasterDetail ? 5 : 4; |
| 354 | + const deleteBtn = matrixOptions.hasFixedColumn |
| 355 | + ? dataGrid.getFixedDataRow(rowIdx).getCommandCell(colIdx).element |
| 356 | + : dataGrid.getDataRow(rowIdx).getCommandCell(colIdx).element; |
| 357 | + |
| 358 | + await t.click(deleteBtn); |
| 359 | + |
| 360 | + await verifyGridStyles(t, dataGrid, matrixOptions); |
| 361 | + }).before(async () => { |
| 362 | + await createDataGrid(matrixOptions); |
| 363 | + }); |
| 364 | +}; |
| 365 | + |
| 366 | +[true, false].forEach((hasFixedColumn) => { |
| 367 | + [true, false].forEach((hasMasterDetail) => { |
| 368 | + [true, false].forEach((rowAlternationEnabled) => { |
| 369 | + [true, false].forEach((showColumnLines) => { |
| 370 | + [true, false].forEach((showRowLines) => { |
| 371 | + [true, false].forEach((showBorders) => { |
| 372 | + const matrixOptions: MatrixOptions = { |
| 373 | + rowAlternationEnabled, |
| 374 | + showColumnLines, |
| 375 | + showRowLines, |
| 376 | + showBorders, |
| 377 | + hasFixedColumn, |
| 378 | + hasMasterDetail, |
| 379 | + }; |
| 380 | + functionalTest(matrixOptions); |
| 381 | + }); |
| 382 | + }); |
| 383 | + }); |
| 384 | + }); |
| 385 | + }); |
| 386 | +}); |
0 commit comments