Skip to content
GSoc Blog [Radis-App]
TwitterGithubProject

Final Blog

final evaluation, testing, 12th week, final blog1 min read

Final Evaluation

In this phase , i am preety much focusing to add the test files for frontend and backend and also setup the pipeline to run tests for the app .

Frontend Tesing

I have added the test files for the frontend . I have used the jest framework for testing the frontend . I have added the test files to cover maxmimum elements possible.

📦 some test fiels :

  • test for tgas [unit test]:
1/* eslint-disable @typescript-eslint/no-empty-function */
2/* eslint-disable react/react-in-jsx-scope */
3import { fireEvent, render, screen, waitFor } from "@testing-library/react";
4import user from "@testing-library/user-event";
5import App from "../../App";
6describe("testing tgas field ", () => {
7 test("testing tgas field render with defaultValue and perfectly visible", () => {
8 render(<App />);
9 const input = screen.getByLabelText("TGas");
10 expect(input).toBeVisible();
11 expect(input).toBeInTheDocument();
12 expect(input).toHaveValue(300);
13 });
14 test("testing tgas field render with user* given value and perfectly visible", () => {
15 render(<App />);
16 const input = screen.getByLabelText("TGas");
17 expect(input).toBeVisible();
18 expect(input).toBeInTheDocument();
19 fireEvent.input(input, {
20 target: { value: 100 },
21 });
22 expect(input).toHaveValue(100);
23 });
24 test("testing tgas field validation for out of range values", async () => {
25 render(<App />);
26 const input = screen.getByLabelText("TGas");
27 const button = screen.getByRole("button", {
28 name: /new plot/i,
29 });
30 fireEvent.input(input, {
31 target: { value: 20000000 },
32 });
33 user.click(button);
34 await waitFor(async () => {
35 expect(
36 screen.getByText("Tgas must be between 1K and 9000K")
37 ).toBeInTheDocument();
38 });
39 });
40 test("testing tgas field validation for undefined fields", async () => {
41 render(<App />);
42 const input = screen.getByLabelText("TGas");
43 const button = screen.getByRole("button", {
44 name: /new plot/i,
45 });
46 user.clear(input);
47 user.click(button);
48 await waitFor(async () => {
49 expect(screen.getByText("Tgas must be defined")).toBeInTheDocument();
50 });
51 });
52});
  • integration testing :
1/* eslint-disable @typescript-eslint/no-empty-function */
2/* eslint-disable react/react-in-jsx-scope */
3import { fireEvent, render, screen } from "@testing-library/react";
4import App from "../App";
5import { Database as TDatabase } from "../components/types";
6describe("testing: rendering slit switch based on mode ", () => {
7 test("testing : when mode is absorbance* the simulate slit switch is not in the DOM", () => {
8 render(<App />);
9 const button = screen.queryByTestId("slit-switch-testid");
10 expect(button).not.toBeInTheDocument();
11 });
12 test("testing : when mode is radiance* the simulate slit switch is in the DOM", () => {
13 render(<App />);
14 const dropdown = screen.getByTestId("mode-testid");
15 fireEvent.change(dropdown, { target: { value: "radiance_noslit" } });
16 const button = screen.getByTestId("slit-switch-testid");
17 expect(button).toBeInTheDocument();
18 });
19 test("testing : when mode is transmittance* the simulate slit switch is in the DOM", () => {
20 render(<App />);
21 const dropdown = screen.getByTestId("mode-testid");
22 fireEvent.change(dropdown, { target: { value: "transmittance_noslit" } });
23 const button = screen.getByTestId("slit-switch-testid");
24 expect(button).toBeInTheDocument();
25 });
26});
27 test("testing : when database is GEISA* the non-equilibrium switch is not in the DOM", () => {
28 render(<App />);
29 const button = screen.getByTestId("non-equilibrium-switch-testid");
30 const dropdown = screen.getByTestId("database-testid");
31 fireEvent.change(dropdown, { target: { value: TDatabase.GEISA } });
32 expect(button).not.toBeInTheDocument();
33 });

Backend Testing

I have added the test files for the backend . I have used the pytest framework for testing the backend .

  • 📦 calculate-spectrum endpoint :
1@pytest.mark.anyio
2async def test_calculate_spectrum():
3 async with AsyncClient(app=app, base_url="https://api.radis.app") as ac:
4 with open('./mocks/request.json', 'r') as f:
5 client_request = json.load(f)
6 request_json = json.dumps(client_request)
7 response = await ac.post("/calculate-spectrum",json=request_json)
8 # open the response.json
9 with open('./mocks/response.json', 'r') as f:
10 server_response = json.load(f)
11 response_json = json.dumps(server_response)
12 assert response.status_code == 200
13 assert response.json() == response_json

Thanks .

© 2022 by GSoc Blog [Radis-App]. All rights reserved.
Theme by LekoArts