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(idlelogoutconfirmationmodal): Fixing an issue in the idle timer logic when query parameters are appended to the page #3750

Merged
merged 3 commits into from
Mar 22, 2023
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
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,10 @@ const IdleLogoutConfirmationModal = ({
try {
const url = new URL(routes.logout);
if (window.location.href) {
url.searchParams.append('originHref', window.location.href);
url.searchParams.append(
'originHref',
[window.location.protocol, '//', window.location.host, window.location.pathname].join('')
Copy link
Collaborator

Choose a reason for hiding this comment

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

In the future I would prefer a template literal here.

Suggested change
[window.location.protocol, '//', window.location.host, window.location.pathname].join('')
`${window.location.protocol}//${window.location.host}${window.location.pathname}`

);
}
if (appId) {
url.searchParams.append('originAppId', appId);
Expand All @@ -119,7 +122,10 @@ const IdleLogoutConfirmationModal = ({
try {
const url = new URL(routes.logoutInactivity);
if (window.location.href) {
url.searchParams.append('originHref', window.location.href);
url.searchParams.append(
'originHref',
[window.location.protocol, '//', window.location.host, window.location.pathname].join('')
);
}
if (appId) {
url.searchParams.append('originAppId', appId);
Expand Down Expand Up @@ -179,6 +185,7 @@ const IdleLogoutConfirmationModal = ({
});

return () => {
setLogoutConfirmationCountdown(0);
timer.cleanUp();
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const commonProps = {
const TIME_INTERVAL = 1000;

describe('IdleLogoutConfirmationModal', () => {
const originHref = 'https://ibm.com';
const originHref = 'https://ibm.com/';
const expectedWorkspaceBasedPageLogoutRoute = `${
commonProps.routes.logout
}?originHref=${encodeURIComponent(
Expand All @@ -50,7 +50,12 @@ describe('IdleLogoutConfirmationModal', () => {
originalWindowLocation = { ...window.location };
originalWindowDocumentCookie = window.document.cookie;
delete window.location;
window.location = { href: 'https://ibm.com' };
window.location = {
href: 'https://ibm.com/',
protocol: 'https:',
host: 'ibm.com',
pathname: '/',
};
window.open = jest.fn();
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ const idleTimeoutDataProp = {
};

describe('SuiteHeader', () => {
const originHref = 'https://ibm.com';
const originHref = 'https://ibm.com/';
const expectedAdminPageLogoutRoute = `${
adminPageCommonProps.routes.logout
}?originHref=${encodeURIComponent(originHref)}&originIsAdmin=true`;
Expand All @@ -184,7 +184,12 @@ describe('SuiteHeader', () => {
originalWindowLocation = { ...window.location };
originalWindowDocumentCookie = window.document.cookie;
delete window.location;
window.location = { href: 'https://ibm.com' };
window.location = {
href: 'https://ibm.com/',
protocol: 'https:',
host: 'ibm.com',
pathname: '/',
};
window.open = jest.fn();
});

Expand Down
7 changes: 5 additions & 2 deletions packages/react/src/components/SuiteHeader/SuiteHeader.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,10 @@ const SuiteHeader = ({
try {
const url = new URL(routes.logout);
if (window.location.href) {
url.searchParams.append('originHref', window.location.href);
url.searchParams.append(
'originHref',
[window.location.protocol, '//', window.location.host, window.location.pathname].join('')
);
}
if (appId) {
url.searchParams.append('originAppId', appId);
Expand Down Expand Up @@ -247,7 +250,7 @@ const SuiteHeader = ({
return (
<>
{walkmePath ? <Walkme path={walkmePath} lang={walkmeLang} /> : null}
{showToast ? (
{showToast && surveyData ? (
<ToastNotification
data-testid={`${testId}-notification`}
className={`${settings.iotPrefix}--suite-header-survey-toast`}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ const idleTimeoutDataProp = {
};

describe('SuiteHeader', () => {
const originHref = 'https://ibm.com';
const originHref = 'https://ibm.com/';
const expectedAppPageLogoutRoute = `${commonProps.routes.logout}?originHref=${encodeURIComponent(
originHref
)}&originAppId=${appId}`;
Expand All @@ -87,7 +87,12 @@ describe('SuiteHeader', () => {
originalWindowLocation = { ...window.location };
originalWindowDocumentCookie = window.document.cookie;
delete window.location;
window.location = { href: originHref };
window.location = {
href: 'https://ibm.com/',
protocol: 'https:',
host: 'ibm.com',
pathname: '/',
};
window.open = jest.fn();
});

Expand Down