Skip to content

Commit

Permalink
FIX ESLint issues
Browse files Browse the repository at this point in the history
  • Loading branch information
Sabina Talipova committed Jun 30, 2023
1 parent c5ca5eb commit 81385a1
Show file tree
Hide file tree
Showing 8 changed files with 58 additions and 55 deletions.
2 changes: 1 addition & 1 deletion client/dist/js/bundle.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 12 additions & 9 deletions client/src/components/LoginSession/LoginSession.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,17 @@ function LoginSession(props) {
i18n._t('Admin.ACTIVITY_TOOLTIP_TEXT', 'Signed in {signedIn}, Last active {lastActive}'),
{
signedIn: created.format(format),
lastActive: lastAccessed.format(format)
}
lastActive: lastAccessed.format(format),
},
);
const lastActiveStr = props.IsCurrent ?
i18n.inject(
i18n._t('SessionManager.AUTHENTICATED', 'authenticated {createdElapsed}...'),
{ createdElapsed }
{ createdElapsed },
)
: i18n.inject(
i18n._t('SessionManager.LAST_ACTIVE', 'last active {lastAccessedElapsed}...'),
{ lastAccessedElapsed }
{ lastAccessedElapsed },
);

return (
Expand All @@ -64,11 +64,14 @@ function LoginSession(props) {
{props.IsCurrent &&
<strong className="text-success">{currentStr}</strong>
}
{!props.IsCurrent && <Button
color="link"
className="login-session__logout"
onClick={() => attemptLogOut()}
>{logOutStr}</Button>}
{!props.IsCurrent &&
<Button
color="link"
className="login-session__logout"
onClick={() => attemptLogOut()}
>{logOutStr}
</Button>
}
</p>
</div>
);
Expand Down
16 changes: 8 additions & 8 deletions client/src/components/LoginSession/LoginSessionContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,18 @@ import React, { useState } from 'react';
import { connect } from 'react-redux';
import backend from 'lib/Backend';
import Config from 'lib/Config'; // eslint-disable-line
import LoginSession from './LoginSession';
import { success, error } from 'state/toasts/ToastsActions';
import i18n from 'i18n';
import LoginSession from './LoginSession';

function createEndpoint(logOutEndpoint) {
return backend.createEndpointFetcher({
url: `${logOutEndpoint}/:id`.replace('//', '/'),
method: 'delete',
payloadSchema: {
id: { urlReplacement: ':id', remove: true },
SecurityID: { querystring: true }
}
SecurityID: { querystring: true },
},
});
}

Expand All @@ -32,14 +32,14 @@ function LoginSessionContainer(props) {
const endpoint = createEndpoint(props.LogOutEndpoint);
return endpoint({
id: props.ID,
SecurityID: Config.get('SecurityID')
SecurityID: Config.get('SecurityID'),
})
.then(response => {
.then((response) => {
props.displayToastSuccess(response.message);
})
.catch(err => {
.catch((err) => {
setFailed(true);
return err.response.text().then(json => {
return err.response.text().then((json) => {
// Try to parse the error response
const response = JSON.parse(json);
if (typeof response !== 'object' || typeof response.message !== 'string') {
Expand All @@ -53,7 +53,7 @@ function LoginSessionContainer(props) {
// Catch all error handler
props.displayToastFailure(i18n._t(
'SessionManager.COULD_NOT_LOGOUT',
'Could not log out of session. Try again later.'
'Could not log out of session. Try again later.',
));
})
.finally(() => {
Expand Down
10 changes: 5 additions & 5 deletions client/src/components/LoginSession/tests/LoginSession-story.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ export default {
parameters: {
docs: {
description: {
component: 'Badge component for displaying a message in a Bootstrap "badge" style.'
component: 'Badge component for displaying a message in a Bootstrap "badge" style.',
},
canvas: {
sourceState: 'shown',
},
controls: { exclude: ['logout'] }
}
controls: { exclude: ['logout'] },
},
},
argTypes: {
IPAddress: {
Expand Down Expand Up @@ -90,7 +90,7 @@ export default {
defaultValue: { summary: 'false' },
},
},
}
},
};

export const _LoginSession = {
Expand All @@ -101,5 +101,5 @@ export const _LoginSession = {
submitting: false,
complete: false,
failed: false,
}
},
};
22 changes: 11 additions & 11 deletions client/src/components/LoginSession/tests/LoginSession-test.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/* global jest, test, describe, it, expect, beforeEach, Event */

import React from 'react';
import LoginSession from '../LoginSession';
import { render } from '@testing-library/react';
import LoginSession from '../LoginSession';

jest.useFakeTimers().setSystemTime(new Date('2021-03-12 03:47:22'));

Expand All @@ -22,7 +22,7 @@ function makeProps(obj = {}) {

test('LoginSession should display details ', () => {
const { container } = render(
<LoginSession {...makeProps()}/>
<LoginSession {...makeProps()} />,
);
expect(container.querySelector('.login-session p').textContent).toBe('Chrome on Mac OS X 10.15.7');
expect(container.querySelector('.login-session .text-muted').firstChild.nodeValue).toBe('127.0.0.1');
Expand All @@ -32,17 +32,17 @@ test('LoginSession should display details ', () => {

test('LoginSession should display a logout button', () => {
const { container } = render(
<LoginSession {...makeProps()}/>
<LoginSession {...makeProps()} />,
);
expect(container.querySelector('.login-session__logout').textContent).toBe('Log out');
});

test('LoginSession should display logging out when submitting', () => {
const { container } = render(
<LoginSession {...makeProps({
submitting: true
submitting: true,
})}
/>
/>,
);
expect(container.querySelector('.login-session__logout').textContent).toBe('Logging out...');
});
Expand All @@ -51,9 +51,9 @@ test('LoginSession should display logging out when complete', () => {
const { container } = render(
<LoginSession {...makeProps({
submitting: false,
complete: true
complete: true,
})}
/>
/>,
);
expect(container.querySelector('.login-session__logout').textContent).toBe('Logging out...');
});
Expand All @@ -62,19 +62,19 @@ test('LoginSession should be hidden when complete', () => {
const { container } = render(
<LoginSession {...makeProps({
submitting: false,
complete: true
complete: true,
})}
/>
/>,
);
expect(container.querySelectorAll('.login-session.hidden')).toHaveLength(1);
});

test('LoginSession should not be hidden when failed', () => {
const { container } = render(
<LoginSession {...makeProps({
failed: true
failed: true,
})}
/>
/>,
);
expect(container.querySelector('.login-session.hidden')).toBeNull();
});
Loading

0 comments on commit 81385a1

Please sign in to comment.