-
Notifications
You must be signed in to change notification settings - Fork 0
ETT-1141: role switch modal should appear after login #140
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
Changes from all commits
6a36be6
8d487fc
3db9330
4497b1a
bd76287
e296e41
cb3c829
b6c9502
6d6f0b6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,6 +2,7 @@ | |
| import { onMount } from 'svelte'; | ||
|
|
||
| import dialogPolyfill from 'dialog-polyfill'; | ||
| import docCookies from '../../lib/cookies.svelte'; | ||
|
|
||
| /** | ||
| * @typedef {Object} Props | ||
|
|
@@ -12,6 +13,7 @@ | |
| * @property {boolean} [scrollable] | ||
| * @property {string} [mode] | ||
| * @property {boolean} [modalLarge] | ||
| * @property {boolean} [setPromptCookie] | ||
| * @property {boolean} [fullscreenOnMobile] | ||
| * @property {boolean} [focusHelpOnClose] | ||
| * @property {boolean} [focusMyAccountOnClose] | ||
|
|
@@ -36,6 +38,8 @@ | |
| focusMyAccountOnClose = false, | ||
| focusButtonOnClose = false, | ||
| focusDownloadOnClose = false, | ||
| setPromptCookie = false, | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We don't normally want a modal to set this cookie, but if we pass the |
||
| checkForNotifications, | ||
| title, | ||
| body, | ||
| footer, | ||
|
|
@@ -78,6 +82,9 @@ | |
| window.removeEventListener('keydown', logKeys); | ||
| console.log('-- dialog is closed'); | ||
|
|
||
| if (setPromptCookie) { | ||
| docCookies.setItem('HT-role-prompt', 'true', 4, 'hours'); | ||
| } | ||
| if (focusHelpOnClose) { | ||
| document.getElementById('get-help').focus(); | ||
| } | ||
|
|
@@ -97,10 +104,6 @@ | |
| console.log('-- polyfilling dialog'); | ||
| dialogPolyfill.registerDialog(dialog); | ||
| } | ||
|
|
||
| if (isOpen) { | ||
| openModal(); | ||
| } | ||
| }); | ||
|
|
||
| $effect(() => { | ||
|
|
@@ -131,6 +134,9 @@ | |
| data-bs-dismiss="modal" | ||
| onclick={() => { | ||
| hide(); | ||
| if (setPromptCookie) { | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A roundabout way of telling the modal that we only want to check for notifications if this button is clicked from the RoleSwitchModal (the only modal component that passes in the |
||
| checkForNotifications() | ||
| } | ||
| }} | ||
| ><span class="close-icon"> | ||
| <i class="fa-solid fa-xmark icon-default" aria-hidden="true"></i><span class="fa-sr-only" | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,7 @@ | ||
| import Navbar from './index.svelte'; | ||
| import PingCallbackDecorator from '../../decorators/PingCallbackDecorator'; | ||
| import { userEvent, within } from 'storybook/test'; | ||
| import { expect } from 'storybook/test'; | ||
| import { userEvent, within, waitFor, expect } from 'storybook/test'; | ||
| // import { expect } from 'storybook/test'; | ||
|
|
||
| export default { | ||
| title: 'Navbar', | ||
|
|
@@ -24,7 +24,7 @@ export const Default = { | |
| play: async ({ canvasElement }) => { | ||
| const canvas = within(canvasElement); | ||
| //sanity check | ||
| expect(await canvas.getByTitle('HathiTrust Home')).toBeInTheDocument(); | ||
| expect(canvas.getByTitle('HathiTrust Home')).toBeInTheDocument(); | ||
| }, | ||
| globals: { | ||
| viewport: { | ||
|
|
@@ -44,7 +44,7 @@ export const DesktopDropdownMenuSelected = { | |
| play: async ({ canvasElement }) => { | ||
| const canvas = within(canvasElement); | ||
|
|
||
| const mainMenu = await canvas.getByText(/member libraries/i); | ||
| const mainMenu = canvas.getByText(/member libraries/i); | ||
| await userEvent.click(mainMenu); | ||
| }, | ||
| }; | ||
|
|
@@ -99,6 +99,25 @@ export const DesktopLoggedInResourceSharingRole = { | |
| await userEvent.click(accountButton); | ||
| }, | ||
| }; | ||
| export const DesktopLoggedInResourceSharingRolePromptDismissed = { | ||
| parameters: { ...Default.parameters }, | ||
| args: { | ||
| loggedIn: true, | ||
| }, | ||
| decorators: [ | ||
| () => ({ | ||
| Component: PingCallbackDecorator, | ||
| props: { loggedIn: true, role: 'resourceSharing', hasActivatedRole: false }, | ||
| }), | ||
| ], | ||
| play: async ({ canvas }) => { | ||
| const closeModal = canvas.getByRole('button', { name: 'Cancel' }); | ||
| await userEvent.click(closeModal); | ||
|
|
||
| const accountButton = canvas.getByLabelText(/My Account/); | ||
| await userEvent.click(accountButton); | ||
| }, | ||
| }; | ||
| export const DesktopLoggedInResourceSharingRoleActivated = { | ||
| parameters: { ...Default.parameters }, | ||
| args: { | ||
|
|
@@ -108,7 +127,14 @@ export const DesktopLoggedInResourceSharingRoleActivated = { | |
| decorators: [ | ||
| () => ({ | ||
| Component: PingCallbackDecorator, | ||
| props: { loggedIn: true, role: 'resourceSharing', hasActivatedRole: true }, | ||
| props: { | ||
| loggedIn: true, | ||
| role: 'resourceSharing', | ||
| hasActivatedRole: true, | ||
| cookieData: { | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Because we're mocking the cookie, the role switch modal does not appear during this story. |
||
| 'HT-role-prompt': 'true', | ||
| }, | ||
| }, | ||
| }), | ||
| ], | ||
| play: async ({ canvasElement }) => { | ||
|
|
@@ -140,6 +166,61 @@ export const DesktopLoggedInWithNotifications = { | |
| }), | ||
| ], | ||
| }; | ||
| export const DesktopLoggedInResourceSharingRoleAndNotification = { | ||
| parameters: { ...Default.parameters }, | ||
| args: { | ||
| loggedIn: true, | ||
| hasNotification: true, | ||
| }, | ||
| decorators: [ | ||
| () => ({ | ||
| Component: PingCallbackDecorator, | ||
| props: { | ||
| loggedIn: true, | ||
| role: 'resourceSharing', | ||
| hasActivatedRole: false, | ||
| cookieData: {}, | ||
| notificationData: [{ title: 'What happens with two modals?', message: 'Hopefully these are not overlapping!' }], | ||
| }, | ||
| }), | ||
| ], | ||
| play: async ({ canvas, userEvent }) => { | ||
| const rolePromptCancelButton = canvas.getByRole('button', { name: 'Cancel' }); | ||
| await userEvent.click(rolePromptCancelButton); | ||
| }, | ||
| }; | ||
| export const DesktopLoggedInRoleSwitchClosed = { | ||
| parameters: { ...Default.parameters }, | ||
| args: { | ||
| loggedIn: true, | ||
| hasNotification: true, | ||
| }, | ||
| decorators: [ | ||
| () => ({ | ||
| Component: PingCallbackDecorator, | ||
| props: { | ||
| loggedIn: true, | ||
| role: 'resourceSharing', | ||
| hasActivatedRole: false, | ||
| cookieData: {}, | ||
| notificationData: [ | ||
| { | ||
| title: 'Closed role switch modal', | ||
| message: | ||
| 'User closed role switch modal using the X icon. Cookie was set, notifications should still appear.', | ||
| }, | ||
| ], | ||
| }, | ||
| }), | ||
| ], | ||
| play: async ({ canvas, userEvent }) => { | ||
| await waitFor(() => { | ||
| expect(canvas.getByRole('heading', { name: 'Choose a role' })).toBeVisible(); | ||
| }); | ||
| const rolePromptCloseButton = canvas.getByRole('button', { name: 'Close modal' }); | ||
| await userEvent.click(rolePromptCloseButton); | ||
| }, | ||
| }; | ||
| export const Mobile = { | ||
| decorators: [ | ||
| () => ({ | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Most of the changes in this file are linting, but this is the important change here. Changing how this decorator is instantiated is what fixed the mysterious failing tests.