-
-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Changed Portal Button to be off by default and hidden on mobile (#21983)
Ref https://linear.app/ghost/issue/DES-1074/change-portal-button-defaults-and-hide-on-mobile - These days, themes have subscribe and account buttons built in. The Portal Button should be opt-in rather than opt-out. - On mobile devices, the Portal Button takes up too much valuable real estate.
- Loading branch information
Showing
5 changed files
with
76 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,68 @@ | ||
import {render} from '../utils/test-utils'; | ||
import TriggerButton from './TriggerButton'; | ||
|
||
const setup = () => { | ||
const {mockOnActionFn, ...utils} = render( | ||
<TriggerButton /> | ||
const setup = (customProps = {}) => { | ||
const utils = render( | ||
<TriggerButton {...customProps} /> | ||
); | ||
|
||
const triggerFrame = utils.getByTitle('portal-trigger'); | ||
return { | ||
mockOnActionFn, | ||
triggerFrame, | ||
triggerFrame: utils.queryByTitle('portal-trigger'), | ||
rerender: utils.rerender, | ||
...utils | ||
}; | ||
}; | ||
|
||
describe('Trigger Button', () => { | ||
test('renders', () => { | ||
const {triggerFrame} = setup(); | ||
let originalInnerWidth; | ||
|
||
beforeEach(() => { | ||
originalInnerWidth = window.innerWidth; | ||
window.resizeTo = function (width) { | ||
Object.defineProperty(window, 'innerWidth', { | ||
configurable: true, | ||
value: width | ||
}); | ||
window.dispatchEvent(new Event('resize')); | ||
}; | ||
}); | ||
|
||
afterEach(() => { | ||
Object.defineProperty(window, 'innerWidth', { | ||
configurable: true, | ||
value: originalInnerWidth | ||
}); | ||
}); | ||
|
||
test('renders when viewport is desktop size', () => { | ||
window.resizeTo(1024); | ||
const {triggerFrame} = setup(); | ||
expect(triggerFrame).toBeInTheDocument(); | ||
}); | ||
|
||
test('does not render when viewport is mobile size', () => { | ||
window.resizeTo(375); | ||
const {triggerFrame} = setup(); | ||
expect(triggerFrame).not.toBeInTheDocument(); | ||
}); | ||
|
||
test('removes itself when window is resized to mobile', () => { | ||
window.resizeTo(1024); | ||
const {rerender, queryByTitle} = setup(); | ||
expect(queryByTitle('portal-trigger')).toBeInTheDocument(); | ||
|
||
window.resizeTo(375); | ||
rerender(<TriggerButton />); | ||
expect(queryByTitle('portal-trigger')).not.toBeInTheDocument(); | ||
}); | ||
|
||
test('shows itself when window is resized to desktop', () => { | ||
window.resizeTo(375); | ||
const {rerender, queryByTitle} = setup(); | ||
expect(queryByTitle('portal-trigger')).not.toBeInTheDocument(); | ||
|
||
window.resizeTo(1024); | ||
rerender(<TriggerButton />); | ||
expect(queryByTitle('portal-trigger')).toBeInTheDocument(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters