mirror of
https://github.com/Foundry376/Mailspring.git
synced 2025-01-18 05:58:11 +08:00
149b389508
* Switch to using Typescript instead of Babel * Switch all es6 / jsx file extensions to ts / tsx * Convert Utils to a TS module from module.exports style module * Move everything from module.exports to typescript exports * Define .d.ts files for mailspring-exports and component kit… Yes it seems this is the best option :( * Load up on those @types * Synthesize TS types from PropTypes for standard components * Add types to Model classes and move constructor constants to instance vars * 9800 => 7700 TS errors * 7700 => 5600 TS errors * 5600 => 5330 TS errors * 5330 => 4866 TS errors * 4866 => 4426 TS errors * 4426 => 2411 TS errors * 2411 > 1598 TS errors * 1598 > 769 TS errors * 769 > 129 TS errors * 129 > 22 TS errors * Fix runtime errors * More runtime error fixes * Remove support for custom .es6 file extension * Remove a few odd remaining references to Nylas * Don’t ship Typescript support in the compiled app for now * Fix issues in compiled app - module resolution in TS is case sensitive? * README updates * Fix a few more TS errors * Make “No Signature” option clickable + selectable * Remove flicker when saving file and reloading keymaps * Fix mail rule item height in preferences * Fix missing spacing in thread sharing popover * Fix scrollbar ticks being nested incorrectly * Add Japanese as a manually reviewed language * Prevent the thread list from “sticking” * Re-use Sheet when switching root tabs, prevent sidebar from resetting * Ensure specs run * Update package configuration to avoid shpping types * Turn eslint back on - we will opt-in to the TS rules one by one
257 lines
8.9 KiB
TypeScript
257 lines
8.9 KiB
TypeScript
import React from 'react'
|
|
import {mount, shallow} from 'enzyme'
|
|
import {Table, SelectableTableCell, SelectableTableRow, SelectableTable} from 'mailspring-component-kit'
|
|
import {selection, cellProps, rowProps, tableProps, testDataSource} from '../fixtures/table-data'
|
|
|
|
|
|
describe('SelectableTable Components', function describeBlock() {
|
|
describe('SelectableTableCell', () => {
|
|
function renderCell(props) {
|
|
return shallow(
|
|
<SelectableTableCell
|
|
{...cellProps}
|
|
{...props}
|
|
/>
|
|
)
|
|
}
|
|
|
|
describe('shouldComponentUpdate', () => {
|
|
it('should update if selection status for cell has changed', () => {
|
|
const nextSelection = {colIdx: 0, rowIdx: 2}
|
|
const cell = renderCell()
|
|
const nextProps = {...cellProps, selection: nextSelection}
|
|
const shouldUpdate = cell.instance().shouldComponentUpdate(nextProps)
|
|
expect(shouldUpdate).toBe(true)
|
|
});
|
|
|
|
it('should update if data for cell has changed', () => {
|
|
const nextRows = testDataSource.rows().slice()
|
|
nextRows[0] = ['something else', 2]
|
|
const nextDataSource = testDataSource.setRows(nextRows)
|
|
const cell = renderCell()
|
|
const nextProps = {...cellProps, tableDataSource: nextDataSource}
|
|
const shouldUpdate = cell.instance().shouldComponentUpdate(nextProps)
|
|
expect(shouldUpdate).toBe(true)
|
|
});
|
|
|
|
it('should not update otherwise', () => {
|
|
const nextRows = testDataSource.rows().slice()
|
|
nextRows[0] = nextRows[0].slice()
|
|
const nextDataSource = testDataSource.setRows(nextRows)
|
|
const nextSelection = {...selection}
|
|
const cell = renderCell()
|
|
const nextProps = {...cellProps, selection: nextSelection, tableDataSource: nextDataSource}
|
|
const shouldUpdate = cell.instance().shouldComponentUpdate(nextProps)
|
|
expect(shouldUpdate).toBe(false)
|
|
});
|
|
});
|
|
|
|
describe('isSelected', () => {
|
|
it('returns true if selection matches props', () => {
|
|
const cell = renderCell()
|
|
expect(cell.instance().isSelected(cellProps)).toBe(true)
|
|
});
|
|
|
|
it('returns false otherwise', () => {
|
|
const cell = renderCell()
|
|
expect(cell.instance().isSelected({
|
|
...cellProps,
|
|
selection: {rowIdx: 1, colIdx: 2},
|
|
})).toBe(false)
|
|
});
|
|
});
|
|
|
|
describe('isSelectedUsingKey', () => {
|
|
it('returns true if cell was selected using the provided key', () => {
|
|
const cell = renderCell({selection: {...selection, key: 'Enter'}})
|
|
expect(cell.instance().isSelectedUsingKey('Enter')).toBe(true)
|
|
});
|
|
|
|
it('returns false if cell was not selected using the provided key', () => {
|
|
const cell = renderCell()
|
|
expect(cell.instance().isSelectedUsingKey('Enter')).toBe(false)
|
|
});
|
|
});
|
|
|
|
describe('isInLastRow', () => {
|
|
it('returns true if cell is in last row', () => {
|
|
const cell = renderCell({rowIdx: 2})
|
|
expect(cell.instance().isInLastRow()).toBe(true)
|
|
});
|
|
|
|
it('returns true if cell is not in last row', () => {
|
|
const cell = renderCell()
|
|
expect(cell.instance().isInLastRow()).toBe(false)
|
|
});
|
|
});
|
|
|
|
it('renders with the appropriate className when selected', () => {
|
|
const cell = renderCell()
|
|
expect(cell.hasClass('selected')).toBe(true)
|
|
});
|
|
|
|
it('renders with the appropriate className when not selected', () => {
|
|
const cell = renderCell({rowIdx: 2, colIdx: 1})
|
|
expect(cell.hasClass('selected')).toBe(false)
|
|
});
|
|
|
|
it('renders any extra classNames', () => {
|
|
const cell = renderCell({className: 'my-cell'})
|
|
expect(cell.hasClass('my-cell')).toBe(true)
|
|
});
|
|
});
|
|
|
|
describe('SelectableTableRow', () => {
|
|
function renderRow(props) {
|
|
return shallow(
|
|
<SelectableTableRow
|
|
{...rowProps}
|
|
{...props}
|
|
/>
|
|
)
|
|
}
|
|
|
|
describe('shouldComponentUpdate', () => {
|
|
it('should update if the row data has changed', () => {
|
|
const nextRows = testDataSource.rows().slice()
|
|
nextRows[0] = ['new', 'row']
|
|
const nextDataSource = testDataSource.setRows(nextRows)
|
|
const row = renderRow()
|
|
const shouldUpdate = row.instance().shouldComponentUpdate({...rowProps, tableDataSource: nextDataSource})
|
|
expect(shouldUpdate).toBe(true)
|
|
});
|
|
|
|
it('should update if selection status for row has changed', () => {
|
|
const nextSelection = {rowIdx: 2, colIdx: 0}
|
|
const row = renderRow()
|
|
const shouldUpdate = row.instance().shouldComponentUpdate({...rowProps, selection: nextSelection})
|
|
expect(shouldUpdate).toBe(true)
|
|
});
|
|
|
|
it('should update even if row is still selected but selected cell has changed', () => {
|
|
const nextSelection = {rowIdx: 1, colIdx: 1}
|
|
const row = renderRow()
|
|
const shouldUpdate = row.instance().shouldComponentUpdate({...rowProps, selection: nextSelection})
|
|
expect(shouldUpdate).toBe(true)
|
|
});
|
|
|
|
it('should not update otherwise', () => {
|
|
const nextRows = testDataSource.rows().slice()
|
|
const nextDataSource = testDataSource.setRows(nextRows)
|
|
const nextSelection = {...selection}
|
|
const row = renderRow()
|
|
const nextProps = {...rowProps, selection: nextSelection, tableDataSource: nextDataSource}
|
|
const shouldUpdate = row.instance().shouldComponentUpdate(nextProps)
|
|
expect(shouldUpdate).toBe(false)
|
|
});
|
|
});
|
|
|
|
describe('isSelected', () => {
|
|
it('returns true when selection matches props', () => {
|
|
const row = renderRow()
|
|
expect(row.instance().isSelected({
|
|
selection: {rowIdx: 1},
|
|
rowIdx: 1,
|
|
})).toBe(true)
|
|
});
|
|
|
|
it('returns false otherwise', () => {
|
|
const row = renderRow()
|
|
expect(row.instance().isSelected({
|
|
selection: {rowIdx: 2},
|
|
rowIdx: 1,
|
|
})).toBe(false)
|
|
});
|
|
});
|
|
|
|
it('renders with the appropriate className when selected', () => {
|
|
const row = renderRow()
|
|
expect(row.hasClass('selected')).toBe(true)
|
|
});
|
|
|
|
it('renders with the appropriate className when not selected', () => {
|
|
const row = renderRow({selection: {rowIdx: 2, colIdx: 0}})
|
|
expect(row.hasClass('selected')).toBe(false)
|
|
});
|
|
|
|
it('renders any extra classNames', () => {
|
|
const row = renderRow({className: 'my-row'})
|
|
expect(row.hasClass('my-row')).toBe(true)
|
|
});
|
|
});
|
|
|
|
describe('SelectableTable', () => {
|
|
function renderTable(props) {
|
|
return mount(
|
|
<SelectableTable
|
|
{...tableProps}
|
|
{...props}
|
|
/>
|
|
)
|
|
}
|
|
|
|
describe('onTab', () => {
|
|
it('shifts selection to the next row if last column is selected', () => {
|
|
const onShiftSelection = jasmine.createSpy('onShiftSelection')
|
|
const table = renderTable({selection: {colIdx: 2, rowIdx: 1}, onShiftSelection})
|
|
table.instance().onTab({key: 'Tab'})
|
|
expect(onShiftSelection).toHaveBeenCalledWith({
|
|
row: 1, col: -2, key: 'Tab',
|
|
})
|
|
});
|
|
|
|
it('shifts selection to the next col otherwise', () => {
|
|
const onShiftSelection = jasmine.createSpy('onShiftSelection')
|
|
const table = renderTable({selection: {colIdx: 0, rowIdx: 1}, onShiftSelection})
|
|
table.instance().onTab({key: 'Tab'})
|
|
expect(onShiftSelection).toHaveBeenCalledWith({
|
|
col: 1, key: 'Tab',
|
|
})
|
|
});
|
|
});
|
|
|
|
describe('onShiftTab', () => {
|
|
it('shifts selection to the previous row if first column is selected', () => {
|
|
const onShiftSelection = jasmine.createSpy('onShiftSelection')
|
|
const table = renderTable({selection: {colIdx: 0, rowIdx: 2}, onShiftSelection})
|
|
table.instance().onShiftTab({key: 'Tab'})
|
|
expect(onShiftSelection).toHaveBeenCalledWith({
|
|
row: -1, col: 2, key: 'Tab',
|
|
})
|
|
});
|
|
|
|
it('shifts selection to the previous col otherwise', () => {
|
|
const onShiftSelection = jasmine.createSpy('onShiftSelection')
|
|
const table = renderTable({selection: {colIdx: 1, rowIdx: 1}, onShiftSelection})
|
|
table.instance().onShiftTab({key: 'Tab'})
|
|
expect(onShiftSelection).toHaveBeenCalledWith({
|
|
col: -1, key: 'Tab',
|
|
})
|
|
});
|
|
});
|
|
|
|
it('renders with the correct props', () => {
|
|
const RowRenderer = () => <tr />
|
|
const CellRenderer = () => <td />
|
|
const onSetSelection = () => {}
|
|
const onShiftSelection = () => {}
|
|
const extraProps = {p1: 'p1'}
|
|
const table = renderTable({
|
|
extraProps,
|
|
onSetSelection,
|
|
onShiftSelection,
|
|
RowRenderer,
|
|
CellRenderer,
|
|
}).find(Table)
|
|
expect(table.prop('extraProps')).toEqual({
|
|
p1: 'p1',
|
|
selection,
|
|
onSetSelection,
|
|
onShiftSelection,
|
|
})
|
|
expect(table.prop('tableDataSource')).toBe(testDataSource)
|
|
expect(table.prop('RowRenderer')).toBe(RowRenderer)
|
|
expect(table.prop('CellRenderer')).toBe(CellRenderer)
|
|
});
|
|
});
|
|
});
|