Skip to content

Commit

Permalink
eslint/prettier integration
Browse files Browse the repository at this point in the history
  • Loading branch information
chalabi2 committed Aug 31, 2024
1 parent f450bc6 commit 92169f3
Show file tree
Hide file tree
Showing 186 changed files with 4,634 additions and 6,127 deletions.
8 changes: 7 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
{
"extends": "next/core-web-vitals"
"extends": ["next/core-web-vitals", "prettier"],
"plugins": ["prettier"],
"rules": {
"prettier/prettier": "error",
"no-unused-vars": "off",
"@typescript-eslint/no-unused-vars": "off"
}
}
11 changes: 10 additions & 1 deletion .prettierrc
Original file line number Diff line number Diff line change
@@ -1 +1,10 @@
{}
{
"semi": true,
"trailingComma": "es5",
"singleQuote": true,
"printWidth": 100,
"tabWidth": 2,
"useTabs": false,
"bracketSpacing": true,
"arrowParens": "avoid"
}
13 changes: 12 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
{
"typescript.tsdk": "node_modules/typescript/lib"
"editor.formatOnSave": true,
"editor.codeActionsOnSave": {
"source.fixAll.eslint": true
},
"editor.defaultFormatter": "esbenp.prettier-vscode",
"[typescript]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"[typescriptreact]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"eslint.validate": ["typescript", "typescriptreact"]
}
Binary file modified bun.lockb
Binary file not shown.
58 changes: 26 additions & 32 deletions components/admins/components/__tests__/adminOptions.test.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { afterEach, describe, expect, test } from "bun:test";
import React from "react";
import { screen, cleanup, within, fireEvent } from "@testing-library/react";
import AdminOptions from "@/components/admins/components/adminOptions";
import matchers from "@testing-library/jest-dom/matchers";
import { renderWithChainProvider } from "@/tests/render";
import { mockPoaParams, mockGroup } from "@/tests/mock";
import { afterEach, describe, expect, test } from 'bun:test';
import React from 'react';
import { screen, cleanup, within, fireEvent } from '@testing-library/react';
import AdminOptions from '@/components/admins/components/adminOptions';
import matchers from '@testing-library/jest-dom/matchers';
import { renderWithChainProvider } from '@/tests/render';
import { mockPoaParams, mockGroup } from '@/tests/mock';

expect.extend(matchers);

Expand All @@ -13,49 +13,43 @@ const renderWithProps = (props = {}) => {
poaParams: mockPoaParams,
group: mockGroup,
isLoading: false,
address: "test_address",
admin: "admin1",
address: 'test_address',
admin: 'admin1',
};
return renderWithChainProvider(<AdminOptions {...defaultProps} {...props} />);
};

describe("AdminOptions", () => {
describe('AdminOptions', () => {
afterEach(cleanup);

test("renders loading state correctly", () => {
test('renders loading state correctly', () => {
renderWithProps({ isLoading: true });
expect(screen.getByText("Admin")).toBeInTheDocument();
expect(screen.getByText('Admin')).toBeInTheDocument();
});

test("renders admin details correctly when not loading", () => {
test('renders admin details correctly when not loading', () => {
renderWithProps();
expect(screen.getByText("Admin")).toBeInTheDocument();
expect(screen.getByAltText("Profile Avatar")).toBeInTheDocument();
const titleContainer = screen.getByLabelText("title");
expect(within(titleContainer).getByText("title1")).toBeInTheDocument();
const detailsContainer = screen.getByLabelText("details");
expect(within(detailsContainer).getByText("details1")).toBeInTheDocument();
expect(screen.getByText('Admin')).toBeInTheDocument();
expect(screen.getByAltText('Profile Avatar')).toBeInTheDocument();
const titleContainer = screen.getByLabelText('title');
expect(within(titleContainer).getByText('title1')).toBeInTheDocument();
const detailsContainer = screen.getByLabelText('details');
expect(within(detailsContainer).getByText('details1')).toBeInTheDocument();
});

test("opens update modal on button click", () => {
test('opens update modal on button click', () => {
renderWithProps();
const updateAdminButtonContainer = screen.getByLabelText("update admin");
fireEvent.click(
within(updateAdminButtonContainer).getByText("Update Admin"),
);
const modal = document.getElementById(
"update-admin-modal",
) as HTMLDialogElement;
const updateAdminButtonContainer = screen.getByLabelText('update admin');
fireEvent.click(within(updateAdminButtonContainer).getByText('Update Admin'));
const modal = document.getElementById('update-admin-modal') as HTMLDialogElement;
expect(modal).toBeInTheDocument();
expect(modal.open).toBe(true);
});

test("opens description modal on button click", () => {
test('opens description modal on button click', () => {
renderWithProps();
fireEvent.click(screen.getByLabelText("three-dots"));
const modal = document.getElementById(
"description-modal",
) as HTMLDialogElement;
fireEvent.click(screen.getByLabelText('three-dots'));
const modal = document.getElementById('description-modal') as HTMLDialogElement;
expect(modal).toBeInTheDocument();
expect(modal.open).toBe(true);
});
Expand Down
92 changes: 33 additions & 59 deletions components/admins/components/__tests__/stakingParams.test.tsx
Original file line number Diff line number Diff line change
@@ -1,81 +1,55 @@
import { afterEach, describe, expect, test } from "bun:test";
import React from "react";
import { screen, cleanup, within, fireEvent } from "@testing-library/react";
import StakingParams from "@/components/admins/components/stakingParams";
import matchers from "@testing-library/jest-dom/matchers";
import { mockStakingParams } from "@/tests/mock";
import { renderWithChainProvider } from "@/tests/render";
import { afterEach, describe, expect, test } from 'bun:test';
import React from 'react';
import { screen, cleanup, within, fireEvent } from '@testing-library/react';
import StakingParams from '@/components/admins/components/stakingParams';
import matchers from '@testing-library/jest-dom/matchers';
import { mockStakingParams } from '@/tests/mock';
import { renderWithChainProvider } from '@/tests/render';

expect.extend(matchers);

const renderWithProps = (props = {}) => {
const defaultProps = {
stakingParams: mockStakingParams,
isLoading: false,
address: "test_address",
admin: "admin1",
address: 'test_address',
admin: 'admin1',
};
return renderWithChainProvider(
<StakingParams {...defaultProps} {...props} />,
);
return renderWithChainProvider(<StakingParams {...defaultProps} {...props} />);
};

describe("StakingParams", () => {
describe('StakingParams', () => {
afterEach(cleanup);

test("renders correctly when not loading", () => {
test('renders correctly when not loading', () => {
renderWithProps();
const stakingParamsContainer = screen.getByLabelText("Staking Params");
expect(
within(stakingParamsContainer).getByText("UNBONDING TIME"),
).toBeInTheDocument();
expect(within(stakingParamsContainer).getByText("1")).toBeInTheDocument();
expect(
within(stakingParamsContainer).getByText("MAX VALIDATORS"),
).toBeInTheDocument();
expect(within(stakingParamsContainer).getByText("100")).toBeInTheDocument();
expect(
within(stakingParamsContainer).getByText("BOND DENOM"),
).toBeInTheDocument();
expect(
within(stakingParamsContainer).getByText("upoa"),
).toBeInTheDocument();
expect(
within(stakingParamsContainer).getByText("MINIMUM COMMISSION"),
).toBeInTheDocument();
expect(within(stakingParamsContainer).getByText("5 %")).toBeInTheDocument();
expect(
within(stakingParamsContainer).getByText("MAX ENTRIES"),
).toBeInTheDocument();
expect(within(stakingParamsContainer).getByText("7")).toBeInTheDocument();
expect(
within(stakingParamsContainer).getByText("HISTORICAL ENTRIES"),
).toBeInTheDocument();
expect(within(stakingParamsContainer).getByText("200")).toBeInTheDocument();
const stakingParamsContainer = screen.getByLabelText('Staking Params');
expect(within(stakingParamsContainer).getByText('UNBONDING TIME')).toBeInTheDocument();
expect(within(stakingParamsContainer).getByText('1')).toBeInTheDocument();
expect(within(stakingParamsContainer).getByText('MAX VALIDATORS')).toBeInTheDocument();
expect(within(stakingParamsContainer).getByText('100')).toBeInTheDocument();
expect(within(stakingParamsContainer).getByText('BOND DENOM')).toBeInTheDocument();
expect(within(stakingParamsContainer).getByText('upoa')).toBeInTheDocument();
expect(within(stakingParamsContainer).getByText('MINIMUM COMMISSION')).toBeInTheDocument();
expect(within(stakingParamsContainer).getByText('5 %')).toBeInTheDocument();
expect(within(stakingParamsContainer).getByText('MAX ENTRIES')).toBeInTheDocument();
expect(within(stakingParamsContainer).getByText('7')).toBeInTheDocument();
expect(within(stakingParamsContainer).getByText('HISTORICAL ENTRIES')).toBeInTheDocument();
expect(within(stakingParamsContainer).getByText('200')).toBeInTheDocument();
});

test("renders loading state correctly", () => {
test('renders loading state correctly', () => {
renderWithProps({ isLoading: true });
const stakingParamsContainer = screen.getByLabelText(
"Skeleton Staking Params",
);
expect(
within(stakingParamsContainer).getByText("Staking Params"),
).toBeInTheDocument();
expect(
within(stakingParamsContainer).getByText("Update"),
).toBeInTheDocument();
const stakingParamsContainer = screen.getByLabelText('Skeleton Staking Params');
expect(within(stakingParamsContainer).getByText('Staking Params')).toBeInTheDocument();
expect(within(stakingParamsContainer).getByText('Update')).toBeInTheDocument();
});

test("opens update modal on button click", () => {
test('opens update modal on button click', () => {
renderWithProps();
const stakingParamsContainer = screen.getByLabelText(
"Skeleton Staking Params",
);
fireEvent.click(within(stakingParamsContainer).getByText("Update"));
const modal = document.getElementById(
"update-params-modal",
) as HTMLDialogElement;
const stakingParamsContainer = screen.getByLabelText('Skeleton Staking Params');
fireEvent.click(within(stakingParamsContainer).getByText('Update'));
const modal = document.getElementById('update-params-modal') as HTMLDialogElement;
expect(modal).toBeInTheDocument();
expect(modal.open).toBe(true);
});
Expand Down
62 changes: 29 additions & 33 deletions components/admins/components/__tests__/validatorList.test.tsx
Original file line number Diff line number Diff line change
@@ -1,65 +1,61 @@
import { afterEach, describe, expect, test } from "bun:test";
import React from "react";
import ValidatorList from "@/components/admins/components/validatorList";
import { fireEvent, screen, cleanup, waitFor } from "@testing-library/react";
import matchers from "@testing-library/jest-dom/matchers";
import { mockActiveValidators, mockPendingValidators } from "@/tests/mock";
import { renderWithChainProvider } from "@/tests/render";
import { afterEach, describe, expect, test } from 'bun:test';
import React from 'react';
import ValidatorList from '@/components/admins/components/validatorList';
import { fireEvent, screen, cleanup, waitFor } from '@testing-library/react';
import matchers from '@testing-library/jest-dom/matchers';
import { mockActiveValidators, mockPendingValidators } from '@/tests/mock';
import { renderWithChainProvider } from '@/tests/render';

expect.extend(matchers);

const renderWithProps = (props = {}) => {
const defaultProps = {
admin: "admin1",
admin: 'admin1',
activeValidators: mockActiveValidators,
pendingValidators: mockPendingValidators,
isLoading: false,
};
return renderWithChainProvider(
<ValidatorList {...defaultProps} {...props} />,
);
return renderWithChainProvider(<ValidatorList {...defaultProps} {...props} />);
};

describe("ValidatorList", () => {
describe('ValidatorList', () => {
afterEach(cleanup);

test("renders correctly", () => {
test('renders correctly', () => {
renderWithProps();
expect(screen.getByText("Active Validators")).toBeInTheDocument();
expect(screen.getByText("Validator One")).toBeInTheDocument();
expect(screen.getByText("Validator Two")).toBeInTheDocument();
expect(screen.getByText('Active Validators')).toBeInTheDocument();
expect(screen.getByText('Validator One')).toBeInTheDocument();
expect(screen.getByText('Validator Two')).toBeInTheDocument();
});

test("search functionality works", () => {
test('search functionality works', () => {
renderWithProps();
fireEvent.change(screen.getByPlaceholderText("Search for a validator..."), {
target: { value: "Validator One" },
fireEvent.change(screen.getByPlaceholderText('Search for a validator...'), {
target: { value: 'Validator One' },
});
expect(screen.getByText("Validator One")).toBeInTheDocument();
expect(screen.queryByText("Validator Two")).not.toBeInTheDocument();
expect(screen.getByText('Validator One')).toBeInTheDocument();
expect(screen.queryByText('Validator Two')).not.toBeInTheDocument();
});

test("active/pending toggle works", () => {
test('active/pending toggle works', () => {
renderWithProps();
fireEvent.click(screen.getByText("Pending"));
expect(screen.getByText("Pending Validators")).toBeInTheDocument();
expect(screen.getByText("Validator Three")).toBeInTheDocument();
fireEvent.click(screen.getByText('Pending'));
expect(screen.getByText('Pending Validators')).toBeInTheDocument();
expect(screen.getByText('Validator Three')).toBeInTheDocument();
});

test("clicking on a validator row opens the modal", async () => {
test('clicking on a validator row opens the modal', async () => {
renderWithProps();
fireEvent.click(screen.getByText("Validator One"));
await waitFor(() => expect(screen.getByRole("dialog")).toBeInTheDocument());
fireEvent.click(screen.getByText('Validator One'));
await waitFor(() => expect(screen.getByRole('dialog')).toBeInTheDocument());
});

test("remove button works and shows the warning modal", async () => {
test('remove button works and shows the warning modal', async () => {
renderWithProps();
const allRemoveButtons = screen.getAllByText("Remove");
const allRemoveButtons = screen.getAllByText('Remove');
fireEvent.click(allRemoveButtons[0]);
await waitFor(() =>
expect(
screen.getByText("Are you sure you want to remove the validator"),
).toBeInTheDocument(),
expect(screen.getByText('Are you sure you want to remove the validator')).toBeInTheDocument()
);
});
});
Loading

0 comments on commit 92169f3

Please sign in to comment.