Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove warning factbox #1268

Merged
merged 3 commits into from
Sep 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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