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

Add e2e testing #22

Merged
merged 3 commits into from
Sep 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,6 @@ jobs:
node-version: '18.x'
cache: 'npm'
- run: npm install
- run: npm run test
- run: npm run lint
- run: npm run test

10 changes: 8 additions & 2 deletions ui/.eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,12 @@
"prettier",
"plugin:prettier/recommended"
],
"plugins": ["react", "react-hooks", "@typescript-eslint", "import"],
"plugins": [
"react",
"react-hooks",
"@typescript-eslint",
"import"
],
"env": {
"browser": true,
"es6": true
Expand All @@ -39,7 +44,8 @@
"**/*.stories.*",
"**/.storybook/**/*.*",
"**/.jest-canvas-mock/**/*.*",
"**/*.d.ts"
"**/*.d.ts",
"**/*.spec.*"
],
"peerDependencies": true
}
Expand Down
4 changes: 4 additions & 0 deletions ui/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,7 @@
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# playwright
/playwright-report
/test-results
49 changes: 49 additions & 0 deletions ui/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
"docker": "vite --host",
"preview": "vite preview",
"test": "vitest",
"test:e2e": "playwright test ./src/__tests__/e2e",
"test:e2e:debug": "playwright test ./src/__tests__/e2e --debug",
"coverage": "vitest run --coverage",
"lint": "eslint src",
"lint:fix": "eslint src --fix",
Expand All @@ -28,6 +30,7 @@
"styled-components": "^5.2.1"
},
"devDependencies": {
"@playwright/test": "^1.37.1",
"@storybook/addon-essentials": "^7.1.1",
"@storybook/addon-interactions": "^7.1.1",
"@storybook/addon-links": "^7.1.1",
Expand Down Expand Up @@ -56,6 +59,7 @@
"eslint-plugin-react": "^7.32.2",
"eslint-plugin-react-hooks": "^4.6.0",
"jsdom": "^21.1.1",
"playwright": "^1.37.1",
"prettier": "^2.8.4",
"prop-types": "^15.8.1",
"storybook": "^7.1.1",
Expand Down
30 changes: 30 additions & 0 deletions ui/playwright.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { defineConfig, devices } from '@playwright/test';

export default defineConfig({
timeout: 5000,
testDir: 'src/__tests__',

reporter: 'html',
/* Configure projects for major browsers */
projects: [
{
name: 'chromium',
use: { ...devices['Desktop Chrome'] }
}
],
webServer: [
{
command: 'cd ../api && npm run dev',
port: 4000,
timeout: 120 * 1000
},
{
command: 'npm run dev',
port: 5173,
timeout: 120 * 1000
}
],
use: {
baseURL: 'http://localhost:5173'
}
});
31 changes: 31 additions & 0 deletions ui/src/__tests__/e2e/UserFlow.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { test, expect } from '@playwright/test';

// Test Landing Page and Nav Bar
test('Landing page', async ({ page }) => {
// Check that the page title is correct
await expect(page).toHaveTitle('Portfolio');
// Check that the page header is correct
await expect(page.locator('h1')).toHaveText('Welcome to my Portfolio');
// Check that the page has a nav bar
await expect(page.getByTestId('navbar')).toBeVisible();
// Check that the nav bar has the correct links
await expect(page.getByRole('link', { name: 'Home' })).toBeVisible();
await expect(page.getByRole('link', { name: 'Dashboard' })).toBeVisible();
await expect(page.getByRole('link', { name: 'Admin' })).toBeVisible();
});

// Test Dashboard Page
test('Dashboard page', async ({ page }) => {
await page.goto('/dashboard');

// Check that component with test id aboutme-card is visible
await expect(page.getByTestId('aboutme-card')).toBeVisible();
});

// Test Login Page
test('Admin page', async ({ page }) => {
await page.goto('/login');

// Check that the page header is correct
await expect(page.locator('h1')).toHaveText('Login Panel');
});
2 changes: 1 addition & 1 deletion ui/src/components/cards/AboutMeCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const AboutMeCard = (props: AboutMeCardProps) => {
const { t } = useTranslation();

return (
<Wrapper>
<Wrapper data-testid="aboutme-card">
<ImageWrapper src={avatarCard} data-testid="aboutImg" />
<InfoWrapper>
<InfoSection>
Expand Down
2 changes: 1 addition & 1 deletion ui/src/components/layout/__tests__/HeaderTest.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ vi.mock('react-i18next', () => ({
test('check exact three links', () => {
render(
<MemoryRouter>
<Header />
<Header user={undefined} logout={() => {}} />
</MemoryRouter>
);
expect(screen.getAllByRole('link').length).toEqual(3);
Expand Down
2 changes: 1 addition & 1 deletion ui/src/components/layout/header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ const Header = ({ user, logout }: HeaderProps) => {
const [isVisible, toggle] = useToggle(false);

return (
<Wrapper>
<Wrapper data-testid="navbar">
<Link to={home.link}>
<LinkButton>{t(home.title)}</LinkButton>
</Link>
Expand Down
2 changes: 1 addition & 1 deletion ui/src/locales/en-us.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"description": "Personal Portfolio Webpage"
},
"app": {
"title": "Welcome to my Portfolio Webpage"
"title": "Welcome to my Portfolio Webpagesss"
},
"landing": {
"title": "Welcome to my Portfolio"
Expand Down
20 changes: 13 additions & 7 deletions ui/vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/// <reference types="vitest" />
import { defineConfig, loadEnv } from 'vite';
import type { UserConfig as VitestUserConfigInterface } from 'vitest/config';
import react from '@vitejs/plugin-react'
import react from '@vitejs/plugin-react';

const vitestConfig: VitestUserConfigInterface = {
test: {
Expand All @@ -10,11 +10,18 @@ const vitestConfig: VitestUserConfigInterface = {
},
setupFiles: ['src/setupTest.ts'],
environment: 'jsdom',
exclude: [
'**/node_modules/**',
'**/dist/**',
'**/cypress/**',
'**/.{idea,git,cache,output,temp}/**',
'./src/__tests__/e2e/**'
]
}
};

export default ({ mode }) => {
process.env = {...process.env, ...loadEnv(mode, process.cwd())};
process.env = { ...process.env, ...loadEnv(mode, process.cwd()) };

return defineConfig({
test: vitestConfig.test,
Expand All @@ -24,9 +31,8 @@ export default ({ mode }) => {
// string shorthand: http://localhost:5173/auth -> http://localhost:4000/auth
'/auth': process.env.VITE_PROXY_HOST,
// string shorthand: http://localhost:5173/v1 -> http://localhost:4000/v1
'/v1': process.env.VITE_PROXY_HOST,
},
},
'/v1': process.env.VITE_PROXY_HOST
}
}
});
}

};