Skip to content

Commit

Permalink
wip on PublicKeys tests
Browse files Browse the repository at this point in the history
  • Loading branch information
alessandrogelmi committed Feb 24, 2025
1 parent da945b5 commit 5a748d5
Showing 1 changed file with 55 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { vi } from 'vitest';

import { render } from '../../../__test__/test-utils';
import { publicKeys } from '../../../__mocks__/ApiKeys.mock';
import { fireEvent, render } from '../../../__test__/test-utils';
import { PublicKeyStatus } from '../../../generated-client/pg-apikeys';
import PublicKeys from '../PublicKeys';

describe('Public Keys', () => {
Expand All @@ -15,4 +17,56 @@ describe('Public Keys', () => {
const button = getByTestId('generatePublicKey');
expect(button).toBeInTheDocument();
});

it('render component with public key list and not show button if there is an active key', async () => {
const keys = {
...publicKeys,
items: [
{
...publicKeys.items[0],
status: PublicKeyStatus.Active,
},
],
};

const { container, getByTestId, queryByTestId } = render(<PublicKeys />, {
preloadedState: {
apiKeysState: {
publicKeys: keys,
},
},
});
expect(container).not.toHaveTextContent(/empty-state/i);

const table = getByTestId('publicKeysTableDesktop');
expect(table).toBeInTheDocument();
const button = queryByTestId('generatePublicKey');
expect(button).not.toBeInTheDocument();
});

it('check view code modal', async () => {
const { getByTestId, getAllByTestId } = render(<PublicKeys />, {
preloadedState: {
apiKeysState: {
publicKeys,
},
},
});

const contextMenuButton = getAllByTestId('contextMenuButton')[0];
fireEvent.click(contextMenuButton);
const viewCodeButton = getByTestId('buttonView');
fireEvent.click(viewCodeButton);

const dialog = getByTestId('dialog');
expect(dialog).toBeInTheDocument();

expect(dialog).toHaveTextContent(/view-title/i);
expect(dialog).toHaveTextContent(/view-subtitle/i);

const closeButton = getByTestId('close-modal-button');
fireEvent.click(closeButton);

expect(dialog).not.toBeInTheDocument();
});
});

0 comments on commit 5a748d5

Please sign in to comment.