-
-
Notifications
You must be signed in to change notification settings - Fork 333
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Touch events take Regex for ignoreNames & add tests (#973)
- Loading branch information
Showing
6 changed files
with
3,087 additions
and
73 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module.exports = { | ||
presets: ["module:metro-react-native-babel-preset"], | ||
}; |
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,187 @@ | ||
import * as core from "@sentry/core"; | ||
import { Severity } from "@sentry/types"; | ||
|
||
import { TouchEventBoundary } from "../src/js/touchevents"; | ||
|
||
const addBreadcrumb = jest.spyOn(core, "addBreadcrumb"); | ||
|
||
afterEach(() => { | ||
jest.resetAllMocks(); | ||
}); | ||
|
||
describe("TouchEventBoundary._onTouchStart", () => { | ||
it("tree without displayName", () => { | ||
const { defaultProps } = TouchEventBoundary; | ||
const boundary = new TouchEventBoundary(defaultProps); | ||
|
||
const event = { | ||
_targetInst: { | ||
elementType: { | ||
name: "View", | ||
}, | ||
return: { | ||
elementType: { | ||
name: "Text", | ||
}, | ||
return: { | ||
elementType: { | ||
name: "CoolComponent", | ||
}, | ||
return: { | ||
elementType: { | ||
name: "Screen", | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}; | ||
|
||
// @ts-ignore | ||
boundary._onTouchStart(event); | ||
|
||
expect(addBreadcrumb).toBeCalledWith({ | ||
category: defaultProps.breadcrumbCategory, | ||
data: { | ||
componentTree: ["View", "Text", "CoolComponent", "Screen"], | ||
}, | ||
level: Severity.Info, | ||
message: "Touch event within component tree", | ||
type: defaultProps.breadcrumbType, | ||
}); | ||
}); | ||
|
||
it("displayName is displayed", () => { | ||
const { defaultProps } = TouchEventBoundary; | ||
const boundary = new TouchEventBoundary(defaultProps); | ||
|
||
const event = { | ||
_targetInst: { | ||
elementType: { | ||
name: "View", | ||
}, | ||
return: { | ||
elementType: { | ||
name: "Text", | ||
}, | ||
return: { | ||
elementType: { | ||
displayName: "Connect(View)", | ||
}, | ||
}, | ||
}, | ||
}, | ||
}; | ||
|
||
// @ts-ignore | ||
boundary._onTouchStart(event); | ||
|
||
expect(addBreadcrumb).toBeCalledWith({ | ||
category: defaultProps.breadcrumbCategory, | ||
data: { | ||
componentTree: ["View", "Text", "Connect(View)"], | ||
}, | ||
level: Severity.Info, | ||
message: "Touch event within element: Connect(View)", | ||
type: defaultProps.breadcrumbType, | ||
}); | ||
}); | ||
|
||
it("ignoreNames", () => { | ||
const { defaultProps } = TouchEventBoundary; | ||
const boundary = new TouchEventBoundary({ | ||
...defaultProps, | ||
ignoreNames: ["View", /^Connect\(/, new RegExp("^Happy\\(")], | ||
}); | ||
|
||
const event = { | ||
_targetInst: { | ||
elementType: { | ||
name: "View", | ||
}, | ||
return: { | ||
elementType: { | ||
name: "Text", | ||
}, | ||
return: { | ||
elementType: { | ||
displayName: "Connect(View)", | ||
}, | ||
return: { | ||
elementType: { | ||
displayName: "Styled(View)", | ||
}, | ||
return: { | ||
elementType: { | ||
displayName: "Happy(View)", | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}; | ||
|
||
// @ts-ignore | ||
boundary._onTouchStart(event); | ||
|
||
expect(addBreadcrumb).toBeCalledWith({ | ||
category: defaultProps.breadcrumbCategory, | ||
data: { | ||
componentTree: ["Text", "Styled(View)"], | ||
}, | ||
level: Severity.Info, | ||
message: "Touch event within element: Styled(View)", | ||
type: defaultProps.breadcrumbType, | ||
}); | ||
}); | ||
|
||
it("maxComponentTreeSize", () => { | ||
const { defaultProps } = TouchEventBoundary; | ||
const boundary = new TouchEventBoundary({ | ||
...defaultProps, | ||
maxComponentTreeSize: 3, | ||
}); | ||
|
||
const event = { | ||
_targetInst: { | ||
elementType: { | ||
name: "View", | ||
}, | ||
return: { | ||
elementType: { | ||
name: "Text", | ||
}, | ||
return: { | ||
elementType: { | ||
displayName: "Connect(View)", | ||
}, | ||
return: { | ||
elementType: { | ||
displayName: "Styled(View)", | ||
}, | ||
return: { | ||
elementType: { | ||
displayName: "Happy(View)", | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}; | ||
|
||
// @ts-ignore | ||
boundary._onTouchStart(event); | ||
|
||
expect(addBreadcrumb).toBeCalledWith({ | ||
category: defaultProps.breadcrumbCategory, | ||
data: { | ||
componentTree: ["View", "Text", "Connect(View)"], | ||
}, | ||
level: Severity.Info, | ||
message: "Touch event within element: Connect(View)", | ||
type: defaultProps.breadcrumbType, | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.