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

Fix header height calculation for large titles #1859

Merged
merged 4 commits into from
May 7, 2020
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
1 change: 1 addition & 0 deletions css/index.styl
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ loadingSize = 30px

.auth0-lock-content-body-wrapper
padding-top 10px
margin-top: var(--header-height, 100px)

.auth0-lock-close-button, .auth0-lock-back-button
-webkit-box-sizing content-box !important
Expand Down
34 changes: 13 additions & 21 deletions src/__tests__/testUtils.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import React from 'react'; // eslint-disable-line
import renderer from 'react-test-renderer';

export const expectComponent = children => {
const component = renderer.create(children);
export const expectComponent = (children, opts) => {
const component = renderer.create(children, opts);
return expect(component);
};

Expand Down Expand Up @@ -40,26 +40,18 @@ export const extractPropsFromWrapper = (wrapper, index = 0) =>
export const setURL = (url, options = {}) => {
const parser = document.createElement('a');
parser.href = url;
[
'href',
'protocol',
'host',
'hostname',
'origin',
'port',
'pathname',
'search',
'hash'
].forEach(prop => {
let value = parser[prop];
if (prop === 'origin' && options.noOrigin) {
value = null;
['href', 'protocol', 'host', 'hostname', 'origin', 'port', 'pathname', 'search', 'hash'].forEach(
prop => {
let value = parser[prop];
if (prop === 'origin' && options.noOrigin) {
value = null;
}
Object.defineProperty(window.location, prop, {
value,
writable: true
});
Comment on lines +43 to +52
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is just formatting, nothing changed here.

}
Object.defineProperty(window.location, prop, {
value,
writable: true
});
});
);
};

export const expectMockToMatch = ({ mock }, numberOfCalls) => {
Expand Down
25 changes: 0 additions & 25 deletions src/__tests__/ui/box/__snapshots__/chrome.test.jsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,6 @@ exports[`Chrome can dislay all global messages together 1`] = `
/>
<div
className="auth0-lock-content-body-wrapper"
style={
Object {
"marginTop": 200,
}
}
>
<div>
<div>
Expand Down Expand Up @@ -175,11 +170,6 @@ exports[`Chrome renders correctly when there is a global information message 1`]
/>
<div
className="auth0-lock-content-body-wrapper"
style={
Object {
"marginTop": 200,
}
}
>
<div>
<div>
Expand Down Expand Up @@ -301,11 +291,6 @@ exports[`Chrome renders correctly when there is a global message 1`] = `
/>
<div
className="auth0-lock-content-body-wrapper"
style={
Object {
"marginTop": 200,
}
}
>
<div>
<div>
Expand Down Expand Up @@ -427,11 +412,6 @@ exports[`Chrome renders correctly when there is a global success message 1`] = `
/>
<div
className="auth0-lock-content-body-wrapper"
style={
Object {
"marginTop": 200,
}
}
>
<div>
<div>
Expand Down Expand Up @@ -553,11 +533,6 @@ exports[`Chrome renders correctly with basic props 1`] = `
/>
<div
className="auth0-lock-content-body-wrapper"
style={
Object {
"marginTop": 200,
}
}
>
<div>
<div />
Expand Down
168 changes: 168 additions & 0 deletions src/__tests__/ui/box/__snapshots__/header.test.jsx.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,168 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Header renders correctly with basic props 1`] = `
<div
className="auth0-lock-header"
>
<div
className="auth0-lock-header-bg auth0-lock-blur-support"
>
<div
className="auth0-lock-header-bg-blur auth0-lock-no-grayscale"
style={
Object {
"backgroundImage": "url('some-image.png')",
}
}
/>
<div
className="auth0-lock-header-bg-solid"
style={
Object {
"backgroundColor": "red",
}
}
/>
</div>
<div
className="auth0-lock-header-welcome"
>
<div
className="auth0-lock-firstname"
title="Header"
>
Header
</div>
</div>
</div>
`;

exports[`Header sets the header size property on the document element 1`] = `
<div
className="auth0-lock-header"
>
<div
className="auth0-lock-header-bg auth0-lock-blur-support"
>
<div
className="auth0-lock-header-bg-blur auth0-lock-no-grayscale"
style={
Object {
"backgroundImage": "url('some-image.png')",
}
}
/>
<div
className="auth0-lock-header-bg-solid"
style={
Object {
"backgroundColor": "red",
}
}
/>
</div>
<div
className="auth0-lock-header-welcome"
>
<div
className="auth0-lock-firstname"
title="Header"
>
Header
</div>
</div>
</div>
`;

exports[`Header shows the back button when there is a handler 1`] = `
<div
className="auth0-lock-header"
>
<span
aria-label="back"
className="auth0-lock-back-button"
dangerouslySetInnerHTML={
Object {
"__html": "<svg aria-hidden=\\"true\\" focusable=\\"false\\" enable-background=\\"new 0 0 24 24\\" version=\\"1.0\\" viewBox=\\"0 0 24 24\\" xml:space=\\"preserve\\" xmlns=\\"http://www.w3.org/2000/svg\\" xmlns:xlink=\\"http://www.w3.org/1999/xlink\\"> <polyline fill=\\"none\\" points=\\"12.5,21 3.5,12 12.5,3 \\" stroke=\\"#000000\\" stroke-miterlimit=\\"10\\" stroke-width=\\"2\\"></polyline> <line fill=\\"none\\" stroke=\\"#000000\\" stroke-miterlimit=\\"10\\" stroke-width=\\"2\\" x1=\\"22\\" x2=\\"3.5\\" y1=\\"12\\" y2=\\"12\\"></line> </svg>",
}
}
id="undefined-back-button"
onClick={[Function]}
onKeyPress={[Function]}
role="button"
tabIndex={0}
/>
<div
className="auth0-lock-header-bg auth0-lock-blur-support"
>
<div
className="auth0-lock-header-bg-blur auth0-lock-no-grayscale"
style={
Object {
"backgroundImage": "url('some-image.png')",
}
}
/>
<div
className="auth0-lock-header-bg-solid"
style={
Object {
"backgroundColor": "red",
}
}
/>
</div>
<div
className="auth0-lock-header-welcome"
>
<div
className="auth0-lock-firstname"
title="Header"
>
Header
</div>
</div>
</div>
`;

exports[`Header shows the logoUrl when there is no name 1`] = `
<div
className="auth0-lock-header"
>
<div
className="auth0-lock-header-bg auth0-lock-blur-support"
>
<div
className="auth0-lock-header-bg-blur"
style={
Object {
"backgroundImage": "url('some-image.png')",
}
}
/>
<div
className="auth0-lock-header-bg-solid"
style={
Object {
"backgroundColor": "red",
}
}
/>
</div>
<div
className="auth0-lock-header-welcome"
>
<img
alt=""
className="auth0-lock-header-logo"
src="some-logo.png"
/>
<div
className="auth0-lock-name"
title="This is the header"
>
This is the header
</div>
</div>
</div>
`;
1 change: 0 additions & 1 deletion src/__tests__/ui/box/chrome.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ describe('Chrome', () => {

beforeEach(() => {
Chrome = getComponent();
Chrome.prototype.getHeaderSize = jest.fn(() => 200);
});

it('renders correctly with basic props', () => {
Expand Down
66 changes: 66 additions & 0 deletions src/__tests__/ui/box/header.test.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import React from 'react';
import { expectComponent } from 'testUtils';

const getComponent = () => require('ui/box/header').default;

describe('Header', () => {
let Header;

beforeEach(() => {
Header = getComponent();
});

it('renders correctly with basic props', () => {
const props = {
title: 'This is the header',
name: 'Header',
logoUrl: 'some-logo.png',
backgroundUrl: 'some-image.png',
backgroundColor: 'red'
};

expectComponent(<Header {...props} />).toMatchSnapshot();
});

it('shows the back button when there is a handler', () => {
const props = {
title: 'This is the header',
name: 'Header',
logoUrl: 'some-logo.png',
backgroundUrl: 'some-image.png',
backgroundColor: 'red',
backHandler: () => jest.fn()
};

expectComponent(<Header {...props} />).toMatchSnapshot();
});

it('shows the logoUrl when there is no name', () => {
const props = {
title: 'This is the header',
backgroundUrl: 'some-image.png',
logoUrl: 'some-logo.png',
backgroundColor: 'red'
};

expectComponent(<Header {...props} />).toMatchSnapshot();
});

it('sets the header size property on the document element', () => {
const spy = jest.spyOn(document.documentElement.style, 'setProperty');

const props = {
title: 'This is the header',
name: 'Header',
logoUrl: 'some-logo.png',
backgroundUrl: 'some-image.png',
backgroundColor: 'red'
};

expectComponent(<Header {...props} />, {
createNodeMock: () => ({ clientHeight: 100 })
}).toMatchSnapshot();

expect(spy).toHaveBeenCalledWith('--header-height', '100px');
});
});
Loading