Skip to content

Commit

Permalink
Updates tests to increase code cov
Browse files Browse the repository at this point in the history
Signed-off-by: Darshit Chanpura <dchanp@amazon.com>
  • Loading branch information
DarshitChanpura committed May 28, 2024
1 parent a32a285 commit 7341b54
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ describe('Audit logs', () => {
};

beforeEach(() => {
// jest.spyOn(React, 'useState').mockImplementation((initialValue) => [initialValue, setState]);
jest.spyOn(React, 'useState').mockRestore();
jest
.spyOn(React, 'useState')
Expand Down Expand Up @@ -190,6 +189,9 @@ describe('Audit logs', () => {

it('should load access error component', () => {
const auditLoggingSettings = { enabled: true };
mockAuditLoggingUtils.getAuditLogging = jest
.fn()
.mockRejectedValue({ response: { status: 403 } });
jest
.spyOn(React, 'useState')
.mockImplementationOnce(() => [auditLoggingSettings, setState])
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Permission list page AccessError component should load access error component 1`] = `
<Fragment>
<Memo()
config={Object {}}
coreStart={
Object {
"http": 1,
}
}
dataSourcePickerReadOnly={false}
depsStart={Object {}}
params={Object {}}
selectedDataSource={
Object {
"id": "test",
}
}
setDataSource={[MockFunction]}
/>
<EuiPageHeader>
<EuiTitle
size="l"
>
<h1>
Permissions
</h1>
</EuiTitle>
</EuiPageHeader>
<AccessErrorComponent
loading={false}
/>
<EuiGlobalToastList
dismissToast={[MockFunction]}
side="right"
toastLifeTimeMs={10000}
toasts={Array []}
/>
</Fragment>
`;
Original file line number Diff line number Diff line change
Expand Up @@ -230,4 +230,27 @@ describe('Permission list page ', () => {
expect(component.find('#duplicate').prop('disabled')).toBe(false);
});
});

describe('AccessError component', () => {
const mockCoreStart = {
http: 1,
};
let component;
beforeEach(() => {
fetchActionGroups.mockRejectedValueOnce({ response: { status: 403 } });
jest.spyOn(React, 'useEffect').mockImplementationOnce((f) => f());
component = shallow(
<PermissionList
coreStart={mockCoreStart as any}
depsStart={{} as any}
params={{} as any}
config={{} as any}
/>
);
});

it('should load access error component', () => {
expect(component).toMatchSnapshot();
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ import { EMPTY_FIELD_VALUE } from '../../ui-constants';
import { getUserList, InternalUsersListing } from '../../utils/internal-user-list-utils';
import { dictView, getColumns, ServiceAccountList } from '../service-account-list';

jest.mock('../../utils/internal-user-list-utils');
jest.mock('../../utils/internal-user-list-utils', () => ({
getUserList: jest.fn(),
}));
jest.mock('../../../../utils/auth-info-utils', () => ({
getAuthInfo: jest.fn().mockReturnValue({ user_name: 'user' }),
}));
Expand Down Expand Up @@ -186,6 +188,7 @@ describe('Service Account list', () => {
http: 1,
};
beforeEach(() => {
getUserList.mockRejectedValue({ response: { status: 403 } });
jest.spyOn(React, 'useState').mockRestore();
jest
.spyOn(React, 'useState')
Expand Down

0 comments on commit 7341b54

Please sign in to comment.