|
| 1 | +jest.dontMock('../../components/BrowserRow/BrowserRow.react'); |
| 2 | +jest.mock('idb-keyval'); |
| 3 | + |
| 4 | +import React from 'react'; |
| 5 | +import renderer from 'react-test-renderer'; |
| 6 | +const BrowserRow = require('../../components/BrowserRow/BrowserRow.react').default; |
| 7 | + |
| 8 | +const defaultProps = { |
| 9 | + className: 'TestClass', |
| 10 | + columns: { |
| 11 | + objectId: { type: 'String' }, |
| 12 | + name: { type: 'String' }, |
| 13 | + }, |
| 14 | + currentCol: undefined, |
| 15 | + isUnique: false, |
| 16 | + obj: { |
| 17 | + id: 'abc123', |
| 18 | + className: 'TestClass', |
| 19 | + attributes: { objectId: 'abc123', name: 'Test' }, |
| 20 | + get: function(key) { return this.attributes[key]; }, |
| 21 | + }, |
| 22 | + order: [ |
| 23 | + { name: 'objectId', width: 150, visible: true }, |
| 24 | + { name: 'name', width: 150, visible: true }, |
| 25 | + ], |
| 26 | + readOnlyFields: ['objectId'], |
| 27 | + row: 0, |
| 28 | + rowWidth: 330, |
| 29 | + showRowNumber: true, |
| 30 | + rowNumberWidth: 30, |
| 31 | + skip: 0, |
| 32 | + selection: {}, |
| 33 | + selectRow: () => {}, |
| 34 | + setCopyableValue: () => {}, |
| 35 | + selectedObjectId: undefined, |
| 36 | + setSelectedObjectId: () => {}, |
| 37 | + callCloudFunction: () => {}, |
| 38 | + isPanelVisible: false, |
| 39 | + setCurrent: () => {}, |
| 40 | + setEditing: () => {}, |
| 41 | + setRelation: () => {}, |
| 42 | + onEditSelectedRow: () => {}, |
| 43 | + setContextMenu: () => {}, |
| 44 | + onFilterChange: () => {}, |
| 45 | + markRequiredFieldRow: undefined, |
| 46 | + onMouseDownRowCheckBox: () => {}, |
| 47 | + onMouseUpRowCheckBox: () => {}, |
| 48 | + onMouseOverRowCheckBox: () => {}, |
| 49 | + onMouseOverRow: () => {}, |
| 50 | + onPointerClick: () => {}, |
| 51 | + onPointerCmdClick: () => {}, |
| 52 | + rowValue: undefined, |
| 53 | + stickyLefts: [], |
| 54 | + freezeIndex: -1, |
| 55 | +}; |
| 56 | + |
| 57 | +describe('BrowserRow', () => { |
| 58 | + describe('Row highlight', () => { |
| 59 | + it('should not apply highlight styles when isHighlighted is false', () => { |
| 60 | + const component = renderer |
| 61 | + .create(<BrowserRow {...defaultProps} isHighlighted={false} />) |
| 62 | + .toJSON(); |
| 63 | + // Row div should not have highlight background |
| 64 | + expect(component.props.style.background).toBeUndefined(); |
| 65 | + }); |
| 66 | + |
| 67 | + it('should not apply highlight styles when isHighlighted is undefined', () => { |
| 68 | + const component = renderer |
| 69 | + .create(<BrowserRow {...defaultProps} />) |
| 70 | + .toJSON(); |
| 71 | + expect(component.props.style.background).toBeUndefined(); |
| 72 | + }); |
| 73 | + |
| 74 | + it('should apply subtle blue tint to row div when isHighlighted is true', () => { |
| 75 | + const component = renderer |
| 76 | + .create(<BrowserRow {...defaultProps} isHighlighted={true} />) |
| 77 | + .toJSON(); |
| 78 | + expect(component.props.style.background).toBe('#eef4fb'); |
| 79 | + }); |
| 80 | + |
| 81 | + it('should apply stronger blue to checkbox cell when isHighlighted is true', () => { |
| 82 | + const component = renderer |
| 83 | + .create(<BrowserRow {...defaultProps} isHighlighted={true} />) |
| 84 | + .toJSON(); |
| 85 | + // First child is the checkbox span |
| 86 | + const checkboxCell = component.children[0]; |
| 87 | + expect(checkboxCell.props.style.background).toBe('#d6e4f0'); |
| 88 | + }); |
| 89 | + |
| 90 | + it('should apply stronger blue to row number cell when isHighlighted is true', () => { |
| 91 | + const component = renderer |
| 92 | + .create(<BrowserRow {...defaultProps} isHighlighted={true} showRowNumber={true} />) |
| 93 | + .toJSON(); |
| 94 | + // Second child is the row number span (when showRowNumber is true) |
| 95 | + const rowNumberCell = component.children[1]; |
| 96 | + expect(rowNumberCell.props.style.background).toBe('#d6e4f0'); |
| 97 | + }); |
| 98 | + |
| 99 | + it('should use default background on checkbox cell when not highlighted', () => { |
| 100 | + const component = renderer |
| 101 | + .create(<BrowserRow {...defaultProps} row={1} isHighlighted={false} />) |
| 102 | + .toJSON(); |
| 103 | + const checkboxCell = component.children[0]; |
| 104 | + expect(checkboxCell.props.style.background).toBe('#ffffff'); |
| 105 | + }); |
| 106 | + }); |
| 107 | +}); |
0 commit comments