Skip to content

Commit

Permalink
Some test improvements.
Browse files Browse the repository at this point in the history
  • Loading branch information
jhelmold authored and timopollmeier committed Oct 31, 2023
1 parent 798bd32 commit 48c0733
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 17 deletions.
36 changes: 23 additions & 13 deletions src/web/pages/credentials/__tests__/detailspage.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,14 @@ const credential = Credential.fromElement({
allow_insecure: 1,
creation_time: '2020-12-16T15:23:59Z',
comment: 'blah',
full_type: 'username + password',
full_type: 'Username + SSH Key',
in_use: 0,
login: '',
modification_time: '2021-03-02T10:28:15Z',
name: 'credential 1',
owner: {name: 'admin'},
permissions: {permission: {name: 'Everything'}},
type: 'up',
type: 'usk',
writable: 1,
});

Expand All @@ -92,14 +92,14 @@ const noPermCredential = Credential.fromElement({
allow_insecure: 1,
creation_time: '2020-12-16T15:23:59Z',
comment: 'blah',
full_type: 'username + password',
full_type: 'Username + SSH Key',
in_use: 0,
login: '',
modification_time: '2021-03-02T10:28:15Z',
name: 'credential 1',
owner: {name: 'admin'},
permissions: {permission: {name: 'get_credentials'}},
type: 'up',
type: 'usk',
writable: 1,
});

Expand All @@ -108,14 +108,14 @@ const credentialInUse = Credential.fromElement({
allow_insecure: 1,
creation_time: '2020-12-16T15:23:59Z',
comment: 'blah',
full_type: 'username + password',
full_type: 'Username + SSH Key',
in_use: 1,
login: '',
modification_time: '2021-03-02T10:28:15Z',
name: 'credential 1',
owner: {name: 'admin'},
permissions: {permission: {name: 'Everything'}},
type: 'up',
type: 'usk',
writable: 1,
});

Expand Down Expand Up @@ -165,17 +165,19 @@ describe('Credential Detailspage tests', () => {
expect(element).toHaveTextContent('Owner:admin');

const spans = baseElement.querySelectorAll('span');
expect(spans[10]).toHaveTextContent('User Tags');
expect(spans[12]).toHaveTextContent('Permissions');
expect(spans[12]).toHaveTextContent('User Tags');
expect(spans[14]).toHaveTextContent('Permissions');

expect(element).toHaveTextContent('Comment');
expect(element).toHaveTextContent('blah');

expect(element).toHaveTextContent('Type');
expect(element).toHaveTextContent('Username + Password');
expect(element).toHaveTextContent('Username + SSH Key');

expect(element).toHaveTextContent('Allow Insecure Use');
expect(element).toHaveTextContent('Yes');

expect(element).toHaveTextContent('Login');
});

test('should render user tags tab', () => {
Expand Down Expand Up @@ -208,9 +210,9 @@ describe('Credential Detailspage tests', () => {
const {baseElement} = render(<Detailspage id="6575" />);

const spans = baseElement.querySelectorAll('span');
expect(spans[10]).toHaveTextContent('User Tags');
expect(spans[12]).toHaveTextContent('User Tags');

fireEvent.click(spans[10]);
fireEvent.click(spans[12]);

expect(baseElement).toHaveTextContent('No user tags available');
});
Expand Down Expand Up @@ -245,9 +247,9 @@ describe('Credential Detailspage tests', () => {
const {baseElement} = render(<Detailspage id="6575" />);

const spans = baseElement.querySelectorAll('span');
expect(spans[12]).toHaveTextContent('Permissions');
expect(spans[14]).toHaveTextContent('Permissions');

fireEvent.click(spans[12]);
fireEvent.click(spans[14]);

expect(baseElement).toHaveTextContent('No permissions available');
});
Expand Down Expand Up @@ -393,6 +395,7 @@ describe('Credential ToolBarIcons tests', () => {
const editIcon = screen.getAllByTitle('Edit Credential');
const deleteIcon = screen.getAllByTitle('Move Credential to trashcan');
const exportIcon = screen.getAllByTitle('Export Credential as XML');
const downloadPublicKeyIcon = screen.getAllByTitle('Download Public Key');

expect(cloneIcon[0]).toBeInTheDocument();
fireEvent.click(cloneIcon[0]);
Expand All @@ -409,6 +412,13 @@ describe('Credential ToolBarIcons tests', () => {
expect(exportIcon[0]).toBeInTheDocument();
fireEvent.click(exportIcon[0]);
expect(handleCredentialDownloadClick).toHaveBeenCalledWith(credential);

expect(downloadPublicKeyIcon[0]).toBeInTheDocument();
fireEvent.click(downloadPublicKeyIcon[0]);
expect(handleCredentialInstallerDownloadClick).toHaveBeenCalledWith(
credential,
'key',
);
});

test('should not call click handlers without permission', () => {
Expand Down
4 changes: 2 additions & 2 deletions src/web/pages/credentials/__tests__/dialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,14 @@ const credential = Credential.fromElement({
creation_time: '2020-12-16T15:23:59Z',
comment: 'blah',
formats: {format: 'pem'},
full_type: 'username + password',
full_type: 'Username + SSH Key',
in_use: 0,
login: '',
modification_time: '2021-03-02T10:28:15Z',
name: 'credential 1',
owner: {name: 'admin'},
permissions: {permission: {name: 'Everything'}},
type: 'up',
type: 'usk',
writable: 1,
});

Expand Down
5 changes: 3 additions & 2 deletions src/web/pages/credentials/__tests__/listpage.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,14 @@ const credential = Credential.fromElement({
creation_time: '2020-12-16T15:23:59Z',
comment: 'blah',
formats: {format: 'pem'},
full_type: 'client certificate',
full_type: 'Username + SSH Key',
in_use: 0,
login: '',
modification_time: '2021-03-02T10:28:15Z',
name: 'credential 1',
owner: {name: 'admin'},
permissions: {permission: {name: 'Everything'}},
type: 'cc',
type: 'usk',
writable: 1,
certificate_info: {
activation_time: '2018-10-10T11:41:23.022Z',
Expand Down Expand Up @@ -174,6 +174,7 @@ describe('CredentialPage tests', () => {
expect(screen.getAllByTitle('Edit Credential')[0]).toBeInTheDocument();
expect(screen.getAllByTitle('Clone Credential')[0]).toBeInTheDocument();
expect(screen.getAllByTitle('Export Credential')[0]).toBeInTheDocument();
expect(screen.getAllByTitle('Download Public Key')[0]).toBeInTheDocument();
});

test('should allow to bulk action on page contents', async () => {
Expand Down

0 comments on commit 48c0733

Please sign in to comment.