-
-
Notifications
You must be signed in to change notification settings - Fork 240
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: MessageRow click won't trigger rowClick event
- Loading branch information
Showing
9 changed files
with
152 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
packages/gridjs/tests/view/table/__snapshots__/message-row.test.tsx.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`MessageRow component should match the snapshot 1`] = `"<tr class=\\"gridjs-tr\\"><td role=\\"alert\\" class=\\"gridjs-td gridjs-message\\">boo</td></tr>"`; |
3 changes: 3 additions & 0 deletions
3
packages/gridjs/tests/view/table/__snapshots__/tr.test.tsx.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`TR component should match the snapshot 1`] = `"<tr class=\\"gridjs-tr\\"><td class=\\"gridjs-td\\">boo</td></tr>"`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { mount } from 'enzyme'; | ||
import { createContext, h } from 'preact'; | ||
import { Config } from '../../../src/config'; | ||
import { EventEmitter } from '../../../src/util/eventEmitter'; | ||
import { TableEvents } from '../../../src/view/table/events'; | ||
import { MessageRow } from '../../../src/view/table/messageRow'; | ||
|
||
describe('MessageRow component', () => { | ||
let config: Config; | ||
const configContext = createContext(null); | ||
|
||
beforeEach(() => { | ||
config = new Config(); | ||
}); | ||
|
||
it('should match the snapshot', () => { | ||
const td = mount( | ||
<configContext.Provider value={config}> | ||
<MessageRow message="boo" /> | ||
</configContext.Provider>, | ||
); | ||
expect(td.html()).toMatchSnapshot(); | ||
}); | ||
|
||
it('should prevent emit rowClick', async () => { | ||
config.eventEmitter = new EventEmitter<TableEvents>(); | ||
const onClick = jest.fn(); | ||
|
||
const rows = mount( | ||
<configContext.Provider value={config}> | ||
<MessageRow message="boo" /> | ||
</configContext.Provider>, | ||
).find('tr'); | ||
|
||
config.eventEmitter.on('rowClick', onClick) | ||
rows.map(tr => tr.simulate('click')); | ||
|
||
expect(rows.length).toEqual(1); | ||
expect(onClick).toHaveBeenCalledTimes(0); | ||
}); | ||
}); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
|
||
import { mount } from 'enzyme'; | ||
import { createContext, h } from 'preact'; | ||
import { Cell } from '../../..'; | ||
import { Config } from '../../../src/config'; | ||
import { EventEmitter } from '../../../src/util/eventEmitter'; | ||
import { TableEvents } from '../../../src/view/table/events'; | ||
import { TD } from '../../../src/view/table/td'; | ||
import { TR } from '../../../src/view/table/tr'; | ||
|
||
describe('TR component', () => { | ||
let config: Config; | ||
const configContext = createContext(null); | ||
|
||
beforeEach(() => { | ||
config = new Config(); | ||
}); | ||
|
||
it('should match the snapshot', () => { | ||
const tr = mount( | ||
<configContext.Provider value={config}> | ||
<TR > | ||
<TD cell={new Cell('boo')} /> | ||
</TR> | ||
</configContext.Provider>, | ||
); | ||
expect(tr.html()).toMatchSnapshot(); | ||
}); | ||
|
||
it('should emit rowClick', async () => { | ||
config.eventEmitter = new EventEmitter<TableEvents>(); | ||
const onClick = jest.fn(); | ||
|
||
const rows = mount( | ||
<configContext.Provider value={config}> | ||
<TR > | ||
<TD cell={new Cell('boo')} /> | ||
</TR> | ||
</configContext.Provider>, | ||
).find('tr'); | ||
|
||
config.eventEmitter.on('rowClick', onClick) | ||
rows.map(tr => tr.simulate('click')); | ||
|
||
expect(rows.length).toEqual(1); | ||
expect(onClick).toHaveBeenCalledTimes(1); | ||
}); | ||
}); |