|
| 1 | +/** |
| 2 | + * Core field type conversion tests - Checkbox, Time, Checklist |
| 3 | + * |
| 4 | + * These tests exercise lazy field-type switching on web to mirror desktop behaviour. |
| 5 | + * They focus on core conversions that are reliable and deterministic. |
| 6 | + */ |
| 7 | +import { FieldType, waitForReactUpdate } from '../../support/selectors'; |
| 8 | +import { |
| 9 | + generateRandomEmail, |
| 10 | + getLastFieldId, |
| 11 | + getCellsForField, |
| 12 | + getDataRowCellsForField, |
| 13 | + typeTextIntoCell, |
| 14 | + loginAndCreateGrid, |
| 15 | + addNewProperty, |
| 16 | + editLastProperty, |
| 17 | + setupFieldTypeTest, |
| 18 | +} from '../../support/field-type-test-helpers'; |
| 19 | + |
| 20 | +describe('Field Type - Core Conversions', () => { |
| 21 | + beforeEach(() => { |
| 22 | + setupFieldTypeTest(); |
| 23 | + }); |
| 24 | + |
| 25 | + it('RichText ↔ Checkbox parses truthy/falsy and preserves original text', () => { |
| 26 | + const testEmail = generateRandomEmail(); |
| 27 | + loginAndCreateGrid(testEmail); |
| 28 | + |
| 29 | + // Add RichText property and wait for it to be ready |
| 30 | + addNewProperty(FieldType.RichText); |
| 31 | + |
| 32 | + // Store field ID in alias for later use |
| 33 | + getLastFieldId().as('textFieldId'); |
| 34 | + |
| 35 | + // Type 'yes' into first DATA cell (eq(0) = first data row, using getDataRowCellsForField) |
| 36 | + cy.get<string>('@textFieldId').then((fieldId) => { |
| 37 | + cy.log('Typing into first cell, fieldId: ' + fieldId); |
| 38 | + return getDataRowCellsForField(fieldId).eq(0).should('exist').scrollIntoView().realClick(); |
| 39 | + }); |
| 40 | + cy.wait(1500); |
| 41 | + cy.get('textarea:visible', { timeout: 5000 }).should('exist').first().clear().type('yes', { delay: 30 }); |
| 42 | + cy.get('body').type('{esc}'); |
| 43 | + cy.wait(500); |
| 44 | + |
| 45 | + // Type 'no' into second DATA cell (eq(1) = second data row) |
| 46 | + cy.get<string>('@textFieldId').then((fieldId) => { |
| 47 | + cy.log('Typing into second cell, fieldId: ' + fieldId); |
| 48 | + return getDataRowCellsForField(fieldId).eq(1).should('exist').scrollIntoView().realClick(); |
| 49 | + }); |
| 50 | + cy.wait(1500); |
| 51 | + cy.get('textarea:visible', { timeout: 5000 }).should('exist').first().clear().type('no', { delay: 30 }); |
| 52 | + cy.get('body').type('{esc}'); |
| 53 | + cy.wait(500); |
| 54 | + |
| 55 | + // Switch to Checkbox |
| 56 | + editLastProperty(FieldType.Checkbox); |
| 57 | + |
| 58 | + // Verify rendering shows checkbox icons - "yes" should be checked, "no" should be unchecked |
| 59 | + // Checkbox cells render as SVG icons, not text, so we check for the icon testids |
| 60 | + cy.get('[data-testid="checkbox-checked-icon"]').should('have.length.at.least', 1); |
| 61 | + cy.get('[data-testid="checkbox-unchecked-icon"]').should('have.length.at.least', 1); |
| 62 | + |
| 63 | + // Switch back to RichText and ensure original raw text survives |
| 64 | + editLastProperty(FieldType.RichText); |
| 65 | + getLastFieldId().then((fieldId) => { |
| 66 | + getCellsForField(fieldId).then(($cells) => { |
| 67 | + const values: string[] = []; |
| 68 | + $cells.each((_i, el) => values.push(el.textContent || '')); |
| 69 | + expect(values.some((v) => v.toLowerCase().includes('yes'))).to.be.true; |
| 70 | + expect(values.some((v) => v.toLowerCase().includes('no'))).to.be.true; |
| 71 | + }); |
| 72 | + }); |
| 73 | + }); |
| 74 | + |
| 75 | + it('RichText ↔ Time parses HH:MM / milliseconds and round-trips', () => { |
| 76 | + const testEmail = generateRandomEmail(); |
| 77 | + loginAndCreateGrid(testEmail); |
| 78 | + |
| 79 | + addNewProperty(FieldType.RichText); |
| 80 | + getLastFieldId().as('timeFieldId'); |
| 81 | + |
| 82 | + cy.get<string>('@timeFieldId').then((fieldId) => { |
| 83 | + typeTextIntoCell(fieldId, 0, '09:30'); |
| 84 | + typeTextIntoCell(fieldId, 1, '34200000'); |
| 85 | + }); |
| 86 | + |
| 87 | + editLastProperty(FieldType.Time); |
| 88 | + |
| 89 | + // Expect parsed milliseconds shown (either raw ms or formatted) |
| 90 | + getLastFieldId().then((fieldId) => { |
| 91 | + getCellsForField(fieldId).then(($cells) => { |
| 92 | + const values: string[] = []; |
| 93 | + $cells.each((_i, el) => values.push((el.textContent || '').trim())); |
| 94 | + expect(values.some((v) => v.includes('34200000') || v.includes('09:30'))).to.be.true; |
| 95 | + }); |
| 96 | + }); |
| 97 | + |
| 98 | + // Round-trip back to RichText |
| 99 | + editLastProperty(FieldType.RichText); |
| 100 | + getLastFieldId().then((fieldId) => { |
| 101 | + getCellsForField(fieldId).then(($cells) => { |
| 102 | + const values: string[] = []; |
| 103 | + $cells.each((_i, el) => values.push((el.textContent || '').trim())); |
| 104 | + expect(values.some((v) => v.includes('09:30') || v.includes('34200000'))).to.be.true; |
| 105 | + }); |
| 106 | + }); |
| 107 | + }); |
| 108 | + |
| 109 | + it('RichText ↔ Checklist handles markdown/plain text and preserves content', () => { |
| 110 | + const testEmail = generateRandomEmail(); |
| 111 | + loginAndCreateGrid(testEmail); |
| 112 | + |
| 113 | + addNewProperty(FieldType.RichText); |
| 114 | + getLastFieldId().as('checklistFieldId'); |
| 115 | + |
| 116 | + cy.get<string>('@checklistFieldId').then((fieldId) => { |
| 117 | + typeTextIntoCell(fieldId, 0, '[x] Done\n[ ] Todo\nPlain line'); |
| 118 | + }); |
| 119 | + |
| 120 | + editLastProperty(FieldType.Checklist); |
| 121 | + |
| 122 | + // Switch back to RichText to view markdown text |
| 123 | + editLastProperty(FieldType.RichText); |
| 124 | + getLastFieldId().then((fieldId) => { |
| 125 | + getCellsForField(fieldId).then(($cells) => { |
| 126 | + const values: string[] = []; |
| 127 | + $cells.each((_i, el) => values.push((el.textContent || '').trim())); |
| 128 | + const allText = values.join('\n'); |
| 129 | + expect(allText).to.match(/Done|Todo|Plain/i); |
| 130 | + }); |
| 131 | + }); |
| 132 | + }); |
| 133 | + |
| 134 | + it('Checkbox click creates checked state that survives type switch', () => { |
| 135 | + const testEmail = generateRandomEmail(); |
| 136 | + loginAndCreateGrid(testEmail); |
| 137 | + |
| 138 | + addNewProperty(FieldType.Checkbox); |
| 139 | + getLastFieldId().as('checkboxFieldId'); |
| 140 | + |
| 141 | + // Click the first checkbox to check it |
| 142 | + cy.get<string>('@checkboxFieldId').then((fieldId) => { |
| 143 | + getCellsForField(fieldId).first().click({ force: true }); |
| 144 | + }); |
| 145 | + waitForReactUpdate(500); |
| 146 | + |
| 147 | + // Verify it's checked |
| 148 | + getLastFieldId().then((fieldId) => { |
| 149 | + getCellsForField(fieldId).first().find('[data-testid="checkbox-checked-icon"]').should('exist'); |
| 150 | + }); |
| 151 | + |
| 152 | + // Switch to SingleSelect - should show "Yes" |
| 153 | + editLastProperty(FieldType.SingleSelect); |
| 154 | + getLastFieldId().then((fieldId) => { |
| 155 | + getCellsForField(fieldId).first().should('contain.text', 'Yes'); |
| 156 | + }); |
| 157 | + |
| 158 | + // Switch back to Checkbox - should still be checked |
| 159 | + editLastProperty(FieldType.Checkbox); |
| 160 | + getLastFieldId().then((fieldId) => { |
| 161 | + getCellsForField(fieldId).first().find('[data-testid="checkbox-checked-icon"]').should('exist'); |
| 162 | + }); |
| 163 | + }); |
| 164 | +}); |
0 commit comments