Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Redefine galleryApi endpoint by introducing library for SignalR testing #107

Open
wants to merge 43 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
3973745
Set up unit tests for gallery ui - app
JanSafronov May 17, 2024
ae20628
Merge pull request #1 from Olszewskidev/main
JanSafronov May 17, 2024
d9bf86c
Setup gallery-ui middleware unit tests
JanSafronov May 18, 2024
6357247
Write one LoginPage unit test
JanSafronov May 18, 2024
f12c618
Merge pull request #5 from Olszewskidev/main
JanSafronov May 18, 2024
76a4279
Set form submit handling unit tests
JanSafronov May 18, 2024
8207e01
Start gallery unit tests
JanSafronov May 18, 2024
08b4398
Fix imports in unit tests
JanSafronov May 18, 2024
7c6a133
Commit last Jest usage
JanSafronov May 20, 2024
95e2900
Replace Jest testing with Vitest and setup unit tests for gallery-ui …
JanSafronov May 21, 2024
4f74c36
Configure a few login tests
JanSafronov May 21, 2024
020fc4c
Fix one unit test
JanSafronov May 23, 2024
3389ccb
Commit a few test fixes
JanSafronov May 23, 2024
4651b18
Fix router home testing
JanSafronov May 24, 2024
f6de966
Merge pull request #10 from Olszewskidev/main
JanSafronov May 24, 2024
9e2b39b
Commit few routing test elements
JanSafronov May 24, 2024
7cce06f
Commit routing test
JanSafronov May 25, 2024
04a0562
Fix router tests
JanSafronov May 25, 2024
b1bd1e6
Merge pull request #16 from Olszewskidev/main
JanSafronov May 25, 2024
82ff47a
Merge pull request #17 from Olszewskidev/main
JanSafronov May 25, 2024
b49e51f
Merge pull request #19 from JanSafronov/feature-1.1
JanSafronov May 25, 2024
bde4a0a
Merge pull request #19 from JanSafronov/feature-1.1
JanSafronov May 25, 2024
47daeb7
Merge branch 'feature-1' of https://github.com/JanSafronov/lens-up in…
JanSafronov May 25, 2024
de9e45f
Fix testing and setup a few Home tests
JanSafronov May 26, 2024
8720cbc
Fix pages tests
JanSafronov May 27, 2024
292cbdf
Fix ui gallery tests
JanSafronov May 27, 2024
5e99606
Fix gallery ui tests and start setting photo collector ui
JanSafronov May 30, 2024
36e5344
Merge branch 'main' of https://github.com/Olszewskidev/lens-up into O…
JanSafronov May 30, 2024
fba4e07
Merge branch 'Olszewskidev-main' into feature-1
JanSafronov May 30, 2024
3992308
Merge pull request #24 from Olszewskidev/main
JanSafronov Jun 1, 2024
0ce7d26
fix photo addition form testing
JanSafronov Jun 1, 2024
1ca5002
Fix photo addition form tests
JanSafronov Jun 1, 2024
44771d5
Fix collector api tests
JanSafronov Jun 1, 2024
ef1f6ed
Fix tests and prepare hub integration test for home page
JanSafronov Jun 2, 2024
36f77e0
Start hub mock
JanSafronov Jun 2, 2024
4aedfa3
Merge pull request #28 from Olszewskidev/main
JanSafronov Jun 3, 2024
aa124f1
Set home tests without Cypress hub mocking
JanSafronov Jun 3, 2024
75fe3a5
Redefine getGalleryPhotos endpoint to mock SignalR hub with Cypress d…
JanSafronov Jun 3, 2024
5f28c1c
Merge branch 'main' of https://github.com/Olszewskidev/lens-up into O…
JanSafronov Jun 3, 2024
8c86add
Merge branch 'Olszewskidev-main' into feature-1.1
JanSafronov Jun 3, 2024
cd7fdfc
Redefine getGalleryPhotos endpoint by applying Cypress library for Si…
JanSafronov Jun 4, 2024
506d7dc
Cleanup a bit home tests
JanSafronov Jun 4, 2024
d06df15
Remove unnecessary image
JanSafronov Jun 4, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix gallery ui tests and start setting photo collector ui
  • Loading branch information
JanSafronov committed May 30, 2024
commit 5e996066352d0516b9fa76e3a3cf30d458a7726f
87 changes: 81 additions & 6 deletions ui-applications/package-lock.json

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion ui-applications/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
"eslint": "^8.57.0",
"eslint-plugin-react-hooks": "^4.6.0",
"eslint-plugin-react-refresh": "^0.4.6",
"jest": "^29.7.0",
"jest-environment-jsdom": "^29.7.0",
"lerna": "^8.1.2",
"msw": "^2.3.0",
Expand Down
2 changes: 0 additions & 2 deletions ui-applications/packages/gallery-ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
"@typescript-eslint/eslint-plugin": "^7.2.0",
"@typescript-eslint/parser": "^7.2.0",
"@vitejs/plugin-react-swc": "^3.5.0",
"babel-jest": "^29.7.0",
"chai": "^5.1.1",
"eslint": "^8.57.0",
"eslint-plugin-react-hooks": "^4.6.0",
Expand All @@ -50,7 +49,6 @@
"target": "",
"esModuleInterop": true,
"types": [
"jest",
"vitest/globals"
]
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { Middleware, isRejected } from '@reduxjs/toolkit';

export const galleryApiMiddleware: Middleware = () => (next) => (action) => {
const hrefe = global.window.location.href;
if (isRejected(action)) {
console.error("API Failed!")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import LoginForm from "./components/LoginForm"
import { useLoginToGalleryMutation } from "../../services/GalleryApi";
import { useNavigate } from "react-router-dom";
import { saveQRCode } from "../../utils/qRCodeHelper";
import { handleLoginToGallery } from "../../utils/login";

export const LoginPage = () => {
const navigate = useNavigate();
Expand Down
Empty file.
6 changes: 0 additions & 6 deletions ui-applications/packages/gallery-ui/tests/AppMock.tsx

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { cleanup, fireEvent, getAllByAltText, getByAltText, getByText, render, screen, waitFor } from '@testing-library/react'
import { expect, test, describe, beforeAll, beforeEach ,afterEach, afterAll } from 'vitest';
import { setupServer } from 'msw/node';
import { loginSubmit } from '../Login/Login.tsx';
import { loginSubmit } from '../../utils/LoginEvents.tsx';
import { getQRCodeUrl } from '../../../src/utils/qRCodeHelper.ts';
import { HttpResponse, http as mswhttp } from 'msw';
import { LoginToGalleryResponse } from '../../../src/types/GalleryApiTypes.ts';
Expand Down Expand Up @@ -54,7 +54,7 @@ describe("Home page with no photos", async () => {
expect(firstRender).toMatchSnapshot();
});

test("No photo hub must have qr-code url in image source", async () => {
test("No photo hub must have qr code url in image source", async () => {
const firstRender = asFragment();

expect(getByAltText(baseElement, "QR code").getAttribute("src")).toEqual(getQRCodeUrl());
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1,51 @@
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html

exports[`Home page with no photos > No photo hub must have qr-code url in image source 1`] = `
<DocumentFragment>
<div
class="min-h-screen bg-black"
>
<div
class="absolute top-1/2 left-1/2 transform -translate-x-1/2"
>
<figure>
<img
alt="QR code"
class="rounded-lg w-64 h-64"
src="QRCodeUrl"
/>
<figcaption
class="font-bold text-base mb-2 text-center text-white"
>
Scan this and join.
</figcaption>
</figure>
</div>
</div>
</DocumentFragment>
`;

exports[`Home page with no photos > No photo hub must show qr code card in home page 1`] = `
<DocumentFragment>
<div
class="min-h-screen bg-black"
>
<div
class="absolute top-1/2 left-1/2 transform -translate-x-1/2"
>
<figure>
<img
alt="QR code"
class="rounded-lg w-64 h-64"
src="QRCodeUrl"
/>
<figcaption
class="font-bold text-base mb-2 text-center text-white"
>
Scan this and join.
</figcaption>
</figure>
</div>
</div>
</DocumentFragment>
`;
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@ import { fireEvent, getByText, render, screen } from '@testing-library/react'
import { expect, test, describe } from 'vitest';
import { LoginPage } from '../../../src/pages/Login/LoginPage';
import { Provider } from 'react-redux'
import { loginSubmit } from './Login.tsx';
import { loginSubmit } from '../../utils/LoginEvents.tsx';
import { BrowserRouter } from 'react-router-dom';
import { JSX } from 'react/jsx-runtime';
import { store } from '../../../src/app/store/store.ts';

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { render, waitFor, cleanup } from "@testing-library/react"
import { expect, test, describe, vi, beforeAll, afterAll, afterEach } from 'vitest';
import App from "../../src/App";
import { loginSubmit } from "./Login/Login";
import { loginSubmit } from '../utils/LoginEvents';
import { HttpResponse, http } from "msw";
import { setupServer } from "msw/node";
import { LoginToGalleryResponse } from '../../src/types/GalleryApiTypes';

/**
* @vitest-environment jsdom
*/
describe("Router test", () => {
describe("Router path tests", () => {
const server = setupServer(...handlers);

beforeAll(() => {
Expand Down
106 changes: 79 additions & 27 deletions ui-applications/packages/gallery-ui/tests/services/Gallery.test.tsx
Original file line number Diff line number Diff line change
@@ -1,41 +1,93 @@
import { fireEvent, render } from '@testing-library/react'
import { expect, test } from 'vitest';
import { waitFor, cleanup, fireEvent, getByTestId, render, screen } from '@testing-library/react';
import { BrowserRouter, useNavigate } from 'react-router-dom';
import { Provider } from 'react-redux';
import { expect, test, beforeAll, afterEach, afterAll } from 'vitest';
import { LoginPage } from '../../src/pages/Login/LoginPage';
import { galleryApi } from '../../src/services/GalleryApi';
import { LoginToGalleryPayload } from '../../src/types/GalleryApiTypes';
import { galleryApi, useLoginToGalleryMutation } from '../../src/services/GalleryApi';
import { LoginToGalleryPayload, LoginToGalleryResponse, PhotoItem } from '../../src/types/GalleryApiTypes';
import { store } from '../../src/app/store/store';
import { createAsyncThunk } from '@reduxjs/toolkit';
import { HttpResponse, http } from 'msw';
import { setupServer } from 'msw/node';
import { loginSubmit } from '../utils/LoginEvents';

/**
* @vitest-environment jsdom
*/
test("Login must be accepted for the gallery", () => {
const {getByText, asFragment} = render(
<LoginPage />,
);
let response: LoginToGalleryResponse = { enterCode: '0', galleryId: '0', qrCodeUrl: 'QRCodeUrl' };
let actual: LoginToGalleryResponse;

const handlers = [
http.post(`${import.meta.env.VITE_GALLERY_SERVICE_URL}/login`, async () => {
let res = await HttpResponse.json(response);
return res;
}),
http.post(`${import.meta.env.VITE_GALLERY_SERVICE_URL}/gallery/0`, () => {
let photo: PhotoItem[] = [{ id: "0", url: "url", authorName: "Author", wishesText: "Best wishes"}];
return HttpResponse.json(photo);
} )
]

const LoginComponent = () => {
const [loginToGallery, { isLoading }] = useLoginToGalleryMutation();

const handleLoginTest = () => {
loginToGallery({ enterCode: '0' })
.unwrap()
.then((payload) => {
actual = payload;
});
}

let payload = { enterCode: "BCD" } as LoginToGalleryPayload;
return (
<div data-testid="test-component" onClick={(e) => { e.preventDefault(); handleLoginTest() }} />
)
}

galleryApi.endpoints.loginToGallery.initiate(payload);
const server = setupServer(...handlers);

const firstRender = asFragment();
beforeAll(() => {
server.listen()
})
afterEach(cleanup);
afterAll(() => {
server.close()
})

fireEvent.change(getByText("Login to your gallery"));
/**
* @vitest-environment jsdom
*/
test("Login muttation must match login api request", async () => {
const {getByTestId} = render(
<Provider store={store}>
<BrowserRouter>
<LoginComponent />
</BrowserRouter>
</Provider>
);

expect(firstRender).toMatchSnapshot(asFragment());
fireEvent.click(getByTestId("test-component"));
await waitFor(() => {
expect(actual).toEqual(response);
});
});

/**
* @jest-environment jsdom
*/
test("Gallery should show photos", () => {
const {getByText, asFragment} = render(
<LoginPage />,
);

galleryApi.endpoints.getGalleryPhotos.initiate("test");
test("Gallery should show photos", async () => {
/*const { asFragment, baseElement } = */await loginSubmit();

/*const { getByText, asFragment } = render(
<Provider store={store}>
<BrowserRouter>
<LoginPage />
</BrowserRouter>
</Provider>
);*/

const firstRender = asFragment();
//galleryApi.endpoints.getGalleryPhotos.initiate("test");

fireEvent.change(getByText("Login to your gallery"));

expect(firstRender).toMatchSnapshot(asFragment());
});
//fireEvent.change(getByText("Login to your gallery"));

await waitFor(() => {
expect(0).toEqual(2);
})
});
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { fireEvent, getByText, render, screen } from '@testing-library/react'
import App from '../../../src/App.tsx';
import App from '../../src/App';
import userEvent from '@testing-library/user-event';

export const loginInput = () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import http, { IncomingMessage, ServerResponse } from "http";
import createWebSocketServer from "./creteWebSocketServer";
import createWebSocketServer from "./createWebSocketServer";

function startServer(port: any): Promise<http.Server<typeof IncomingMessage, typeof ServerResponse>> {
const server = http.createServer();
Expand Down
23 changes: 0 additions & 23 deletions ui-applications/packages/gallery-ui/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,29 +1,6 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"target": "es2020",
"useDefineForClassFields": true,
"lib": ["es2020", "DOM", "DOM.Iterable"],
"module": "esnext",
"skipLibCheck": true,

/* Bundler mode */
"moduleResolution": "bundler",
"allowImportingTsExtensions": true,
"resolveJsonModule": true,
"isolatedModules": true,
"noEmit": true,
"jsx": "react-jsx",

/* Linting */
"strict": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"noFallthroughCasesInSwitch": true,
"esModuleInterop": true,
"types": [
"jest", "vitest/globals"
]
},
"include": ["vite-env.d.ts", "src/**/*", "src/**/*.vue", "tests", "**/*", "gallery-ui", "gallery-ui/tests", "gallery-ui/tests/app", "src/**/*", "src/**/*.vue", "src/**/*"],
"exclude": ["node_modules"],
Expand Down
8 changes: 7 additions & 1 deletion ui-applications/packages/photo-collector-ui/.eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
module.exports = {
extends: '../../eslint.cjs',
extends: ["react-app", "react-app/jest", '../../eslint.cjs'],
rules: {
},
module: "esnext",
globals: {
"ts-jest": {
"useESM": true
}
}
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import { render, waitFor, cleanup, screen, getByText, getByLabelText, fireEvent, getByPlaceholderText } from "@testing-library/react"
import { expect, test, describe, vi, beforeAll, afterAll, afterEach } from 'vitest';
import { HttpResponse, http } from "msw";
import { setupServer } from "msw/node";
import AddPhotoToGalleryPage from "../src/pages/AddPhotoToGallery/AddPhotoToGalleryPage"
import { store } from "../src/app/store";
import { Provider } from "react-redux";
import { BrowserRouter, Navigate, Route, RouterProvider, Routes } from "react-router-dom";
import userEvent from '@testing-library/user-event'
import App from "../src/App";
import AppRouter from "../src/pages/AppRouter";

/**
* @vitest-environment jsdom
*/
describe("Add photo to gallery page tests", () => {
//const server = setupServer(...handlers);

let file = new File(["happy"], "./happy.png", { type: "image/png" });

beforeAll(() => {
//server.listen()
})
afterEach(cleanup);
afterAll(() => {
//server.close()
})

test("Photo form should be uninitialized", async () => {
const { asFragment } = render(
<Provider store={store}>
<BrowserRouter>
<AddPhotoToGalleryPage />
</BrowserRouter>
</Provider>);

expect(asFragment()).toMatchSnapshot();
})

test("Photo must upload", async () => {

const { container, baseElement, asFragment } = render(
<Provider store={store}>
<BrowserRouter>
<Routes>
<Route path="/upload-photo/:enterCode" element={<AddPhotoToGalleryPage />} />
</Routes>
<Navigate to="/upload-photo/0" replace={true} />
</BrowserRouter>
</Provider>
);

const element = container.querySelector("#dropzone-file") as HTMLElement;

fireEvent.change(element, { target: { files: [file] } });

fireEvent.change(screen.getByPlaceholderText("Your name"), { target: { value: "author" } });

fireEvent.change(screen.getByPlaceholderText("..."), { target: { value: "happy" } });

fireEvent.submit(screen.getByRole('button'));

await waitFor(() => {
expect(asFragment()).toMatchSnapshot();
});
})
});
Loading