diff --git a/packages/dnb-design-system-portal/src/core/jest/jestSetup.js b/packages/dnb-design-system-portal/src/core/jest/jestSetup.js index 745f51a0c7a..8613e2322c9 100644 --- a/packages/dnb-design-system-portal/src/core/jest/jestSetup.js +++ b/packages/dnb-design-system-portal/src/core/jest/jestSetup.js @@ -3,7 +3,6 @@ * */ -// import '@babel/polyfill' // jest v24 may have usage of this import { createSerializer } from 'jest-emotion' import fakeProps from 'react-fake-props' import { mount, render, shallow } from './enzyme' diff --git a/packages/dnb-ui-lib/src/__tests__/assets/images/Logo.test.js b/packages/dnb-ui-lib/src/__tests__/assets/images/Logo.screenshot.test.js similarity index 100% rename from packages/dnb-ui-lib/src/__tests__/assets/images/Logo.test.js rename to packages/dnb-ui-lib/src/__tests__/assets/images/Logo.screenshot.test.js diff --git a/packages/dnb-ui-lib/src/__tests__/assets/images/__snapshots__/logo-test-js-logo-image-have-to-match-image-snapshot-1-37d94.snap.png b/packages/dnb-ui-lib/src/__tests__/assets/images/__snapshots__/logo-screenshot-test-js-logo-image-have-to-match-image-snapshot-1-49ee6.snap.png similarity index 100% rename from packages/dnb-ui-lib/src/__tests__/assets/images/__snapshots__/logo-test-js-logo-image-have-to-match-image-snapshot-1-37d94.snap.png rename to packages/dnb-ui-lib/src/__tests__/assets/images/__snapshots__/logo-screenshot-test-js-logo-image-have-to-match-image-snapshot-1-49ee6.snap.png diff --git a/packages/dnb-ui-lib/src/components/logo/Example.js b/packages/dnb-ui-lib/src/components/logo/Example.js index 5d1717f3acb..f90d30408ab 100644 --- a/packages/dnb-ui-lib/src/components/logo/Example.js +++ b/packages/dnb-ui-lib/src/components/logo/Example.js @@ -4,16 +4,27 @@ */ import React, { PureComponent, Fragment } from 'react' -import Logo from './Logo' +import ComponentBox from '../../../../dnb-design-system-portal/src/shared/inlineTags/ComponentBox' class Example extends PureComponent { render() { return ( -
- -

SVG logo

-
+ + {/* @jsx */ ` + + `} + + + {/* @jsx */ ` +

+ H1 with the DNB Logo +

+

+ Text with the DNB Logo +

+ `} +
) } diff --git a/packages/dnb-ui-lib/src/components/logo/Logo.js b/packages/dnb-ui-lib/src/components/logo/Logo.js index 6a2d844ffd7..fc383d0ec00 100644 --- a/packages/dnb-ui-lib/src/components/logo/Logo.js +++ b/packages/dnb-ui-lib/src/components/logo/Logo.js @@ -58,13 +58,16 @@ export default class Logo extends PureComponent { } = this.props const rootParams = { - className: classnames('dnb-logo', className, _className) + className: classnames('dnb-logo', className, _className), + role: 'img', + alt: 'DNB Logo', + ['data-ratio']: ratio, + ['aria-hidden']: true, + ...rest } const svgParams = { - viewBox: '0 0 93.0362 64', // theese size are set to me assiosated with the svg path point values - alt: 'DNB Logo', - ...rest + viewBox: '0 0 93.0362 64' // theese size are set to me assiosated with the svg path point values } if (parseFloat(size) > -1 && width === null && height === null) { @@ -83,6 +86,7 @@ export default class Logo extends PureComponent { return ( + DNB Logo diff --git a/packages/dnb-ui-lib/src/components/logo/__tests__/Logo.screenshot.test.js b/packages/dnb-ui-lib/src/components/logo/__tests__/Logo.screenshot.test.js new file mode 100644 index 00000000000..21c2319f81f --- /dev/null +++ b/packages/dnb-ui-lib/src/components/logo/__tests__/Logo.screenshot.test.js @@ -0,0 +1,20 @@ +/** + * Screenshot Test + * This file will not run on "test:staged" because we dont require any related files + */ + +import { + setupPageScreenshot, + testPageScreenshot +} from '../../../core/jest/jestSetup' + +describe('Logo screenshot', () => { + setupPageScreenshot() + it('have to match the screenshot snapshot', async () => { + const screenshot = await testPageScreenshot({ + url: '/uilib/components/logo?fullscreen', + selector: '.example-box .dnb-logo:nth-child(1)' + }) + expect(screenshot).toMatchImageSnapshot() + }) +}) diff --git a/packages/dnb-ui-lib/src/components/logo/__tests__/__snapshots__/Logo.test.js.snap b/packages/dnb-ui-lib/src/components/logo/__tests__/__snapshots__/Logo.test.js.snap index 044acf1e7e0..871275f4cba 100644 --- a/packages/dnb-ui-lib/src/components/logo/__tests__/__snapshots__/Logo.test.js.snap +++ b/packages/dnb-ui-lib/src/components/logo/__tests__/__snapshots__/Logo.test.js.snap @@ -11,15 +11,21 @@ exports[`Logo component have to match default logo snapshot 1`] = ` width={1} > + + DNB Logo + @@ -189,12 +195,15 @@ exports[`Logo scss have to match snapshot 1`] = ` */ .dnb-logo { display: inline; - width: auto; - height: 100%; - font-size: 0; - color: var(--color-sea-green); - fill: currentColor; } + vertical-align: baseline; + font-size: inherit; + line-height: 0; + width: calc(1em * attr(data-ratio)); + height: 1em; + color: var(--color-sea-green); } .dnb-logo svg { + fill: currentColor; } + .dnb-logo svg:not([width]):not([height]) { width: inherit; height: inherit; } " diff --git a/packages/dnb-ui-lib/src/components/logo/__tests__/__snapshots__/logo-screenshot-test-js-logo-screenshot-have-to-match-the-screenshot-snapshot-1-4da8b.snap.png b/packages/dnb-ui-lib/src/components/logo/__tests__/__snapshots__/logo-screenshot-test-js-logo-screenshot-have-to-match-the-screenshot-snapshot-1-4da8b.snap.png new file mode 100644 index 00000000000..cf107f538ff Binary files /dev/null and b/packages/dnb-ui-lib/src/components/logo/__tests__/__snapshots__/logo-screenshot-test-js-logo-screenshot-have-to-match-the-screenshot-snapshot-1-4da8b.snap.png differ diff --git a/packages/dnb-ui-lib/src/components/logo/details.md b/packages/dnb-ui-lib/src/components/logo/details.md index 37f2ec2e850..2ef988d8edc 100644 --- a/packages/dnb-ui-lib/src/components/logo/details.md +++ b/packages/dnb-ui-lib/src/components/logo/details.md @@ -1,6 +1,6 @@ -| Properties | Description | -| ---------- | ---------------------------------------------------------------------------------------------------- | -| `size` | _(optional)_ define the size of the logo. Sets the height. The width will be calculated by the ratio | -| `color` | _(optional)_ define the color of the logo | -| `width` | _(optional)_ define either the width of the logo | -| `height` | _(optional)_ or define the height of the logo | +| Properties | Description | +| ---------- | ------------------------------------------------------------------------------------------------------------------------ | +| `size` | _(optional)_ define the size of the logo. Sets the height. The width will be calculated by the ratio. Defaults to `auto` | +| `color` | _(optional)_ define the color of the logo | +| `width` | _(optional)_ define either the width of the logo | +| `height` | _(optional)_ or define the height of the logo | diff --git a/packages/dnb-ui-lib/src/components/logo/style/_logo.scss b/packages/dnb-ui-lib/src/components/logo/style/_logo.scss index 400f72299e5..339f6aba5dc 100644 --- a/packages/dnb-ui-lib/src/components/logo/style/_logo.scss +++ b/packages/dnb-ui-lib/src/components/logo/style/_logo.scss @@ -5,14 +5,19 @@ .dnb-logo { display: inline; - width: auto; - height: 100%; + vertical-align: baseline; + font-size: inherit; + line-height: 0; + + width: calc(1em * attr(data-ratio)); + height: 1em; - font-size: 0; color: var(--color-sea-green); - fill: currentColor; svg { + fill: currentColor; + } + svg:not([width]):not([height]) { width: inherit; height: inherit; } diff --git a/packages/dnb-ui-lib/src/core/jest/jestSetup.js b/packages/dnb-ui-lib/src/core/jest/jestSetup.js index c4c6cc3cf55..719bfeb5fed 100644 --- a/packages/dnb-ui-lib/src/core/jest/jestSetup.js +++ b/packages/dnb-ui-lib/src/core/jest/jestSetup.js @@ -3,12 +3,9 @@ * */ -// import '@babel/polyfill' // jest v24 may have usage of this import { axe, toHaveNoViolations } from 'jest-axe' import fakeProps from 'react-fake-props' import { mount, render, shallow } from './enzyme' - -// import * as reactDocs from 'react-docgen' import ReactDOMServer from 'react-dom/server' import fs from 'fs-extra' import onceImporter from 'node-sass-once-importer' @@ -59,7 +56,11 @@ export const startScreenshotServer = () => // }, 1e3) }) -export const testPageScreenshot = ({ selector, url }) => +export const testPageScreenshot = ({ + selector, + url, + transformElement = null +} = {}) => new Promise(async (resolve, reject) => { try { await startScreenshotServer() @@ -68,6 +69,9 @@ export const testPageScreenshot = ({ selector, url }) => ) await global.page.waitForSelector(selector) const element = await global.page.$(selector) + if (transformElement) { + await transformElement(element) + } const screenshot = await element.screenshot() resolve(screenshot) diff --git a/packages/dnb-ui-lib/stories/componentsStories.js b/packages/dnb-ui-lib/stories/componentsStories.js index 29c46b1d6d9..8c7c70ffc95 100644 --- a/packages/dnb-ui-lib/stories/componentsStories.js +++ b/packages/dnb-ui-lib/stories/componentsStories.js @@ -15,6 +15,7 @@ import { IconPrimary, Modal, Dropdown, + Logo, StepIndicator } from '../src/components' @@ -52,6 +53,25 @@ stories.push([ ) ]) +stories.push([ + 'Logo', + () => ( + + + + + +

+ H1 with the DNB Logo +

+

+ Text with the DNB Logo +

+ + + ) +]) + const tablistDataWithContent = [ { title: 'First', key: 'first', content:

First

}, { title: 'Second', key: 'second', content: () =>

Second

}