Skip to content

Commit

Permalink
1. Applying prettier changes.
Browse files Browse the repository at this point in the history
2. Amending Tooltip function in Dashboard's Chip to disappear when the pulse animation is active.
3. Amending datagrid tooltips to disable interactivity with the text itself, ensuring that user can move from one button to the next without accidentally holding the tooltip open.
  • Loading branch information
siddheshraze committed Aug 5, 2024
1 parent c1127a1 commit f4390e7
Show file tree
Hide file tree
Showing 205 changed files with 4,577 additions and 4,574 deletions.
34 changes: 14 additions & 20 deletions frontend/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,28 +1,22 @@
module.exports = {
parser: "@typescript-eslint/parser",
extends: ["next", "plugin:@typescript-eslint/recommended", "plugin:prettier/recommended"],
parser: '@typescript-eslint/parser',
extends: ['next', 'plugin:@typescript-eslint/recommended', 'plugin:prettier/recommended'],
settings: {
next: {
rootDir: "."
rootDir: '.'
}
},
plugins: ["@typescript-eslint", "unused-imports", "prettier", "import"],
plugins: ['@typescript-eslint', 'unused-imports', 'prettier', 'import'],
rules: {
"react-hooks/exhaustive-deps": "off",
semi: ["error", "always"],
"unused-imports/no-unused-imports": "error",
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/no-unused-vars": "off",
"unused-imports/no-unused-vars": "off",
"react-hooks/rules-of-hooks": "off",
"no-case-declarations": "off",
"prettier/prettier": "error",
"import/order": [
"error",
{
groups: [["builtin", "external", "internal"]],
"newlines-between": "always"
}
]
'react-hooks/exhaustive-deps': 'off',
semi: ['error', 'always'],
'unused-imports/no-unused-imports': 'error',
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/no-unused-vars': 'off',
'@typescript-eslint/no-var-requires': 'off',
'unused-imports/no-unused-vars': 'off',
'react-hooks/rules-of-hooks': 'off',
'no-case-declarations': 'off',
'prettier/prettier': 'error'
}
};
2 changes: 1 addition & 1 deletion frontend/.prettierrc.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"semi": true,
"singleQuote": false,
"singleQuote": true,
"trailingComma": "none",
"bracketSpacing": true,
"jsxBracketSameLine": false,
Expand Down
52 changes: 26 additions & 26 deletions frontend/__tests__/api/cmid.test.tsx
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
import { describe, it, expect, vi } from "vitest";
import { GET } from "@/app/api/details/cmid/route";
import { getConn, runQuery } from "@/components/processors/processormacros";
import { createMocks } from "node-mocks-http";
import { NextRequest } from "next/server";
import { describe, it, expect, vi } from 'vitest';
import { GET } from '@/app/api/details/cmid/route';
import { getConn, runQuery } from '@/components/processors/processormacros';
import { createMocks } from 'node-mocks-http';
import { NextRequest } from 'next/server';

vi.mock("@/components/processors/processormacros", () => ({
vi.mock('@/components/processors/processormacros', () => ({
getConn: vi.fn(),
runQuery: vi.fn()
}));

describe("GET /api/details/cmid", () => {
it("should return 200 and data if query is successful", async () => {
describe('GET /api/details/cmid', () => {
it('should return 200 and data if query is successful', async () => {
const mockData = [
{
CoreMeasurementID: 1,
PlotName: "Plot 1",
QuadratName: "Quadrat 1",
PlotName: 'Plot 1',
QuadratName: 'Quadrat 1',
PlotCensusNumber: 1,
StartDate: "2023-01-01",
EndDate: "2023-01-31",
FirstName: "John",
LastName: "Doe",
SpeciesName: "Species 1"
StartDate: '2023-01-01',
EndDate: '2023-01-31',
FirstName: 'John',
LastName: 'Doe',
SpeciesName: 'Species 1'
}
];

Expand All @@ -34,8 +34,8 @@ describe("GET /api/details/cmid", () => {
(runQuery as jest.Mock).mockResolvedValue(mockData);

const { req, res } = createMocks({
method: "GET",
url: "http://localhost/api/details/cmid?cmid=1&schema=test_schema"
method: 'GET',
url: 'http://localhost/api/details/cmid?cmid=1&schema=test_schema'
});

const mockReq = new NextRequest(req.url);
Expand All @@ -56,27 +56,27 @@ describe("GET /api/details/cmid", () => {
);
});

it("should return 500 if there is a database error", async () => {
(getConn as jest.Mock).mockRejectedValue(new Error("Database error"));
it('should return 500 if there is a database error', async () => {
(getConn as jest.Mock).mockRejectedValue(new Error('Database error'));

const { req, res } = createMocks({
method: "GET",
url: "http://localhost/api/details/cmid?cmid=1&schema=test_schema"
method: 'GET',
url: 'http://localhost/api/details/cmid?cmid=1&schema=test_schema'
});

const mockReq = new NextRequest(req.url);

await expect(GET(mockReq)).rejects.toThrow("Database error");
await expect(GET(mockReq)).rejects.toThrow('Database error');
});

it("should return 400 if schema is not provided", async () => {
it('should return 400 if schema is not provided', async () => {
const { req, res } = createMocks({
method: "GET",
url: "http://localhost/api/details/cmid?cmid=1"
method: 'GET',
url: 'http://localhost/api/details/cmid?cmid=1'
});

const mockReq = new NextRequest(req.url);

await expect(GET(mockReq)).rejects.toThrow("no schema variable provided!");
await expect(GET(mockReq)).rejects.toThrow('no schema variable provided!');
});
});
64 changes: 32 additions & 32 deletions frontend/__tests__/api/cmprevalidation.test.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import { describe, it, expect, vi } from "vitest";
import { GET } from "@/app/api/cmprevalidation/[dataType]/[[...slugs]]/route";
import { createMocks } from "node-mocks-http";
import { getConn, runQuery } from "@/components/processors/processormacros";
import { HTTPResponses } from "@/config/macros";
import { NextRequest } from "next/server";

vi.mock("@/components/processors/processormacros", () => ({
import { describe, it, expect, vi } from 'vitest';
import { GET } from '@/app/api/cmprevalidation/[dataType]/[[...slugs]]/route';
import { createMocks } from 'node-mocks-http';
import { getConn, runQuery } from '@/components/processors/processormacros';
import { HTTPResponses } from '@/config/macros';
import { NextRequest } from 'next/server';

vi.mock('@/components/processors/processormacros', () => ({
getConn: vi.fn(),
runQuery: vi.fn()
}));

describe("GET /api/cmprevalidation/[dataType]/[[...slugs]]", () => {
it("should return 412 if required tables are empty", async () => {
describe('GET /api/cmprevalidation/[dataType]/[[...slugs]]', () => {
it('should return 412 if required tables are empty', async () => {
const conn = {
query: vi.fn().mockResolvedValue([[]]),
release: vi.fn()
Expand All @@ -21,18 +21,18 @@ describe("GET /api/cmprevalidation/[dataType]/[[...slugs]]", () => {
(runQuery as jest.Mock).mockResolvedValue([]);

const { req } = createMocks({
method: "GET",
url: "http://localhost/api/cmprevalidation/attributes/schema/1/1"
method: 'GET',
url: 'http://localhost/api/cmprevalidation/attributes/schema/1/1'
});

const mockReq = new NextRequest(req.url);

const response = await GET(mockReq, { params: { dataType: "attributes", slugs: ["schema", "1", "1"] } });
const response = await GET(mockReq, { params: { dataType: 'attributes', slugs: ['schema', '1', '1'] } });

expect(response.status).toBe(HTTPResponses.PRECONDITION_VALIDATION_FAILURE);
});

it("should return 200 if required tables are populated", async () => {
it('should return 200 if required tables are populated', async () => {
const conn = {
query: vi.fn().mockResolvedValue([[1]]),
release: vi.fn()
Expand All @@ -42,59 +42,59 @@ describe("GET /api/cmprevalidation/[dataType]/[[...slugs]]", () => {
(runQuery as jest.Mock).mockResolvedValue([[1]]);

const { req } = createMocks({
method: "GET",
url: "http://localhost/api/cmprevalidation/attributes/schema/1/1"
method: 'GET',
url: 'http://localhost/api/cmprevalidation/attributes/schema/1/1'
});

const mockReq = new NextRequest(req.url);

const response = await GET(mockReq, { params: { dataType: "attributes", slugs: ["schema", "1", "1"] } });
const response = await GET(mockReq, { params: { dataType: 'attributes', slugs: ['schema', '1', '1'] } });

expect(response.status).toBe(HTTPResponses.OK);
});

it("should return 412 if there is a database error", async () => {
(getConn as jest.Mock).mockRejectedValue(new Error("Database error"));
it('should return 412 if there is a database error', async () => {
(getConn as jest.Mock).mockRejectedValue(new Error('Database error'));

const { req } = createMocks({
method: "GET",
url: "http://localhost/api/cmprevalidation/attributes/schema/1/1"
method: 'GET',
url: 'http://localhost/api/cmprevalidation/attributes/schema/1/1'
});

const mockReq = new NextRequest(req.url);

const response = await GET(mockReq, { params: { dataType: "attributes", slugs: ["schema", "1", "1"] } });
const response = await GET(mockReq, { params: { dataType: 'attributes', slugs: ['schema', '1', '1'] } });

expect(response.status).toBe(HTTPResponses.PRECONDITION_VALIDATION_FAILURE);
});

it("should return 400 if slugs are missing", async () => {
it('should return 400 if slugs are missing', async () => {
const { req } = createMocks({
method: "GET",
url: "http://localhost/api/cmprevalidation/attributes"
method: 'GET',
url: 'http://localhost/api/cmprevalidation/attributes'
});

const mockReq = new NextRequest(req.url);

try {
await GET(mockReq, { params: { dataType: "attributes", slugs: [] } });
await GET(mockReq, { params: { dataType: 'attributes', slugs: [] } });
} catch (e) {
expect((e as Error).message).toBe("incorrect slugs provided");
expect((e as Error).message).toBe('incorrect slugs provided');
}
});

it("should return 400 if slugs are incorrect", async () => {
it('should return 400 if slugs are incorrect', async () => {
const { req } = createMocks({
method: "GET",
url: "http://localhost/api/cmprevalidation/attributes/schema"
method: 'GET',
url: 'http://localhost/api/cmprevalidation/attributes/schema'
});

const mockReq = new NextRequest(req.url);

try {
await GET(mockReq, { params: { dataType: "attributes", slugs: ["schema"] } });
await GET(mockReq, { params: { dataType: 'attributes', slugs: ['schema'] } });
} catch (e) {
expect((e as Error).message).toBe("incorrect slugs provided");
expect((e as Error).message).toBe('incorrect slugs provided');
}
});
});
62 changes: 31 additions & 31 deletions frontend/__tests__/api/fetchall.test.tsx
Original file line number Diff line number Diff line change
@@ -1,94 +1,94 @@
import { describe, it, expect, vi, beforeEach } from "vitest";
import { GET } from "@/app/api/fetchall/[[...slugs]]/route";
import { getConn, runQuery } from "@/components/processors/processormacros";
import MapperFactory, { IDataMapper } from "@/config/datamapper";
import { createMocks } from "node-mocks-http";
import { NextRequest } from "next/server";
import { describe, it, expect, vi, beforeEach } from 'vitest';
import { GET } from '@/app/api/fetchall/[[...slugs]]/route';
import { getConn, runQuery } from '@/components/processors/processormacros';
import MapperFactory, { IDataMapper } from '@/config/datamapper';
import { createMocks } from 'node-mocks-http';
import { NextRequest } from 'next/server';

// Mocking getConn and runQuery functions
vi.mock("@/components/processors/processormacros", () => ({
vi.mock('@/components/processors/processormacros', () => ({
getConn: vi.fn(),
runQuery: vi.fn()
}));

// Mocking MapperFactory
vi.mock("@/config/datamapper", () => ({
vi.mock('@/config/datamapper', () => ({
default: {
getMapper: vi.fn()
}
}));

describe("GET /api/fetchall/[[...slugs]]", () => {
describe('GET /api/fetchall/[[...slugs]]', () => {
beforeEach(() => {
vi.clearAllMocks();
});

it("should return 500 if schema is not provided", async () => {
it('should return 500 if schema is not provided', async () => {
const { req } = createMocks({
method: "GET",
url: "http://localhost/api/fetchall/plots"
method: 'GET',
url: 'http://localhost/api/fetchall/plots'
});

const mockReq = new NextRequest(req.url);

await expect(GET(mockReq, { params: { slugs: ["plots"] } })).rejects.toThrow("Schema selection was not provided to API endpoint");
await expect(GET(mockReq, { params: { slugs: ['plots'] } })).rejects.toThrow('Schema selection was not provided to API endpoint');
});

it("should return 500 if fetchType is not provided", async () => {
it('should return 500 if fetchType is not provided', async () => {
const { req } = createMocks({
method: "GET",
url: "http://localhost/api/fetchall?schema=test_schema"
method: 'GET',
url: 'http://localhost/api/fetchall?schema=test_schema'
});

const mockReq = new NextRequest(req.url);

await expect(GET(mockReq, { params: { slugs: [] } })).rejects.toThrow("fetchType was not correctly provided");
await expect(GET(mockReq, { params: { slugs: [] } })).rejects.toThrow('fetchType was not correctly provided');
});

it("should return 200 and data if query is successful", async () => {
it('should return 200 and data if query is successful', async () => {
const mockConn = { release: vi.fn() };
(getConn as ReturnType<typeof vi.fn>).mockResolvedValue(mockConn);
const mockResults = [{ PlotID: 1, PlotName: "Plot 1" }];
const mockResults = [{ PlotID: 1, PlotName: 'Plot 1' }];
(runQuery as ReturnType<typeof vi.fn>).mockResolvedValue(mockResults);

const mockMapper: IDataMapper<any, any> = {
mapData: vi.fn().mockReturnValue([{ plotID: 1, plotName: "Plot 1" }]),
mapData: vi.fn().mockReturnValue([{ plotID: 1, plotName: 'Plot 1' }]),
demapData: vi.fn()
};
(MapperFactory.getMapper as ReturnType<typeof vi.fn>).mockReturnValue(mockMapper);

const { req } = createMocks({
method: "GET",
url: "http://localhost/api/fetchall/plots?schema=test_schema"
method: 'GET',
url: 'http://localhost/api/fetchall/plots?schema=test_schema'
});

const mockReq = new NextRequest(req.url);
const response = await GET(mockReq, { params: { slugs: ["plots"] } });
const response = await GET(mockReq, { params: { slugs: ['plots'] } });

expect(response.status).toBe(200);
const data = await response.json();
expect(data).toEqual([{ plotID: 1, plotName: "Plot 1" }]);
expect(data).toEqual([{ plotID: 1, plotName: 'Plot 1' }]);
expect(getConn).toHaveBeenCalled();
expect(runQuery).toHaveBeenCalledWith(mockConn, expect.stringContaining("SELECT"));
expect(runQuery).toHaveBeenCalledWith(mockConn, expect.stringContaining('SELECT'));
expect(mockMapper.mapData).toHaveBeenCalledWith(mockResults);
expect(mockConn.release).toHaveBeenCalled();
});

it("should return 500 if there is a database error", async () => {
it('should return 500 if there is a database error', async () => {
const mockConn = { release: vi.fn() };
(getConn as ReturnType<typeof vi.fn>).mockResolvedValue(mockConn);
(runQuery as ReturnType<typeof vi.fn>).mockRejectedValue(new Error("Database error"));
(runQuery as ReturnType<typeof vi.fn>).mockRejectedValue(new Error('Database error'));

const { req } = createMocks({
method: "GET",
url: "http://localhost/api/fetchall/plots?schema=test_schema"
method: 'GET',
url: 'http://localhost/api/fetchall/plots?schema=test_schema'
});

const mockReq = new NextRequest(req.url);

await expect(GET(mockReq, { params: { slugs: ["plots"] } })).rejects.toThrow("Call failed");
await expect(GET(mockReq, { params: { slugs: ['plots'] } })).rejects.toThrow('Call failed');
expect(getConn).toHaveBeenCalled();
expect(runQuery).toHaveBeenCalledWith(mockConn, expect.stringContaining("SELECT"));
expect(runQuery).toHaveBeenCalledWith(mockConn, expect.stringContaining('SELECT'));
expect(mockConn.release).toHaveBeenCalled();
});
});
Loading

0 comments on commit f4390e7

Please sign in to comment.