Skip to content

Commit

Permalink
Remove warning factbox (#1268)
Browse files Browse the repository at this point in the history
* Change warning Factbox

* bumped version

* version package-lock
  • Loading branch information
ssb-cgn authored Sep 3, 2024
1 parent a6ccc1c commit ded988f
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 12 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@statisticsnorway/ssb-component-library",
"version": "2.2.13",
"version": "2.2.14",
"description": "Component library for SSB (Statistics Norway)",
"main": "lib/bundle.js",
"scripts": {
Expand Down
10 changes: 10 additions & 0 deletions src/components/FactBox/factbox.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,23 @@ import { screen, render } from '../../utils/test'
import FactBox from './index'

describe('FactBox component', () => {
let warnSpy

beforeEach(() => {
warnSpy = jest.spyOn(console, 'warn').mockImplementation(() => {})
})

afterEach(() => {
warnSpy.mockRestore()
})
test('Matches the snapshot', () => {
const { asFragment } = render(<FactBox header='fact box header' text='fact box Text' />)
expect(asFragment()).toMatchSnapshot()
})
test('set openByDefault', async () => {
const text = 'fact box Text'
render(<FactBox header='fact box header' text={text} openByDefault />)
expect(warnSpy).toHaveBeenCalled()

expect(await screen.findByText(text)).toBeVisible()
})
Expand Down
24 changes: 15 additions & 9 deletions src/components/FactBox/index.jsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,22 @@
import React from 'react'
import React, { useEffect } from 'react'
import PropTypes from 'prop-types'
import Accordion from '../Accordion'

console.warn('Warning: FactBox is deprecated and will be removed in a future release. Please use ExpansionBox instead.')
const FactBox = ({ className, header, openByDefault = false, text }) => {
useEffect(() => {
console.warn(
'Warning: FactBox is deprecated and will be removed in a future release. Please use ExpansionBox instead.'
)
}, [])

const FactBox = ({ className, header, openByDefault = false, text }) => (
<div className={`ssb-fact-box${className ? ` ${className}` : ''}`}>
<Accordion header={header} openByDefault={openByDefault} withoutBorders>
{text}
</Accordion>
</div>
)
return (
<div className={`ssb-fact-box${className ? ` ${className}` : ''}`}>
<Accordion header={header} openByDefault={openByDefault} withoutBorders>
{text}
</Accordion>
</div>
)
}

FactBox.propTypes = {
className: PropTypes.string,
Expand Down

0 comments on commit ded988f

Please sign in to comment.