Skip to content
This repository was archived by the owner on Oct 1, 2024. It is now read-only.

Commit 4eecab7

Browse files
author
george
committed
simplify Undernet calls in Article component
1 parent e48e43e commit 4eecab7

File tree

3 files changed

+14
-14
lines changed

3 files changed

+14
-14
lines changed

app/components/Article/Article.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,19 @@ import Prism from "prismjs"
44
import classNames from "classnames"
55
import PropTypes from "prop-types"
66

7-
import Undernet from "undernet"
87
import { COMPONENTS } from "./constants"
98
import ScrollUpOnMount from "app/components/ScrollUpOnMount"
109

1110
export default function Article(props) {
1211
const [domIsLoaded, setDomIsLoaded] = useState(false)
1312

1413
const componentUnmountFunction = () => {
15-
COMPONENTS.forEach(component => Undernet[component].stop())
14+
COMPONENTS.forEach(Component => Component.stop())
1615
}
1716

1817
useEffect(() => {
1918
Prism.highlightAll()
20-
COMPONENTS.forEach(component => Undernet[component].start())
19+
COMPONENTS.forEach(Component => Component.start())
2120
setDomIsLoaded(true)
2221

2322
return componentUnmountFunction

app/components/Article/__tests__/Article.spec.js

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
11
import React from "react"
22
import Article from "../Article"
3-
import Undernet from "undernet"
43
import Prism from "prismjs"
54
import { COMPONENTS } from "../constants"
65

76
jest.mock("app/components/ScrollUpOnMount", () => global.simpleMock("ScrollUpOnMount"))
87

98
global.scrollTo = jest.fn()
109

11-
COMPONENTS.forEach(component => {
12-
Undernet[component].start = jest.fn()
13-
Undernet[component].stop = jest.fn()
10+
COMPONENTS.forEach(Component => {
11+
Component.start = jest.fn()
12+
Component.stop = jest.fn()
1413
})
1514

1615
jest.mock("prismjs", () => ({
@@ -51,25 +50,25 @@ describe("<Article />", () => {
5150
expect(Prism.highlightAll).toHaveBeenCalled()
5251
})
5352

54-
COMPONENTS.forEach(component => {
55-
it(`calls Undernet.${component}.start`, () => {
53+
COMPONENTS.forEach(Component => {
54+
it(`calls ${Component}.start`, () => {
5655
// Given
5756
mountComponent()
5857
// Then
59-
expect(Undernet[component].start).toHaveBeenCalled()
58+
expect(Component.start).toHaveBeenCalled()
6059
})
6160
})
6261
})
6362

6463
describe("#componentWillUnmount", () => {
65-
COMPONENTS.forEach(component => {
66-
it(`calls Undernet.${component}.stop`, () => {
64+
COMPONENTS.forEach(Component => {
65+
it(`calls ${Component}.stop`, () => {
6766
// Given
6867
const wrapper = mountComponent()
6968
// When
7069
wrapper.unmount()
7170
// Then
72-
expect(Undernet[component].stop).toHaveBeenCalled()
71+
expect(Component.stop).toHaveBeenCalled()
7372
})
7473
})
7574
})
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1-
export const COMPONENTS = ["Tooltips", "Accordions", "Modals", "Dropdowns"]
1+
import { Tooltips, Accordions, Modals, Dropdowns } from "undernet"
2+
3+
export const COMPONENTS = [Tooltips, Accordions, Modals, Dropdowns]

0 commit comments

Comments
 (0)