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

Test/react testing #86

Merged
merged 38 commits into from
Oct 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
3fd125e
fix : modified path of mui imports
AntonioMrtz Oct 10, 2023
f6fd1a6
test : add test StartMenu
AntonioMrtz Oct 11, 2023
6d95d46
chore : add github actions frontend tests
AntonioMrtz Oct 11, 2023
7b9bf73
test : add RegisterMenu tests
AntonioMrtz Oct 12, 2023
98a5221
test : add UserProfile tests
AntonioMrtz Oct 12, 2023
d8c754a
test : add Home tests
AntonioMrtz Oct 12, 2023
59f6aee
test : increase coverage Home test with mock fetchs
AntonioMrtz Oct 12, 2023
306f391
test : increase coverage UserProfile tests
AntonioMrtz Oct 12, 2023
f6e0590
test : add App tests
AntonioMrtz Oct 13, 2023
cc50471
test : add Genre tests
AntonioMrtz Oct 13, 2023
ddcf4af
test : add Explorar tests
AntonioMrtz Oct 13, 2023
b768346
file : move pages tests to their own folder
AntonioMrtz Oct 13, 2023
606ffe9
file : move componentes/ to components/
AntonioMrtz Oct 13, 2023
f6237a7
file : delete tech docs
AntonioMrtz Oct 13, 2023
ac43de7
fix : add mock scrollto in App tests
AntonioMrtz Oct 13, 2023
db47ce5
test : add Playlist tests
AntonioMrtz Oct 13, 2023
feae107
file : move apptest to __tests__/renderer/
AntonioMrtz Oct 13, 2023
664badd
test : add Sticky Header tests
AntonioMrtz Oct 14, 2023
d826c03
chore : fix typo
AntonioMrtz Oct 14, 2023
28ced1d
test : add ItemsAllArtist tests
AntonioMrtz Oct 14, 2023
ed47537
test : add ItemsAllPlaylist test
AntonioMrtz Oct 14, 2023
9e07bcb
fix : typo error add .test to test files
AntonioMrtz Oct 14, 2023
db7e915
test : add ItemsAllSong tests
AntonioMrtz Oct 14, 2023
b23efdb
fix : add expect statement according to Cards content in Items
AntonioMrtz Oct 14, 2023
3066907
fix : test name error
AntonioMrtz Oct 14, 2023
05e94e2
test : add ItemsAllPlaylistFromUser tests
AntonioMrtz Oct 14, 2023
6b689d7
test : add Sidebar tests
AntonioMrtz Oct 16, 2023
14b0809
test : add Sidebaer>Playlist tests
AntonioMrtz Oct 16, 2023
b382cb1
test : add AddSongPlaylistAccordion tests
AntonioMrtz Oct 16, 2023
5752387
test : add Token tests
AntonioMrtz Oct 16, 2023
13d9724
test : add Footer tests
AntonioMrtz Oct 16, 2023
b6bc38a
test : add SongInfo tests
AntonioMrtz Oct 16, 2023
31b48ab
test : add SongConfig & VolumeSlider tests
AntonioMrtz Oct 16, 2023
d71975b
test : add ContextMenuSong
AntonioMrtz Oct 16, 2023
c7cc6e9
test : draft player test
AntonioMrtz Oct 17, 2023
72f2865
test : add Player tests
AntonioMrtz Oct 18, 2023
eb49685
test : add ContextMenuPlaylist tests
AntonioMrtz Oct 18, 2023
c0081f7
Merge branch 'master-streaming' of https://github.com/AntonioMrtz/Spo…
AntonioMrtz Oct 18, 2023
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
27 changes: 27 additions & 0 deletions .github/workflows/frontend-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Frontend Tests

on:
pull_request:
branches:
- 'master'
- 'master-*'

jobs:
build:
runs-on: ubuntu-latest

steps:
- name: Check out code
uses: actions/checkout@v2

- name: Set up Node.js
uses: actions/setup-node@v2
with:
node-version: '16'

- name: Change directory and run commands
working-directory: Electron
run: |
npm install
npm run build
npm test
5 changes: 3 additions & 2 deletions Electron/.vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
".prettierrc": "jsonc",
".eslintignore": "ignore"
},

"eslint.validate": [
"javascript",
"javascriptreact",
Expand All @@ -25,6 +25,7 @@
"npm-debug.log.*": true,
"test/**/__snapshots__": true,
"package-lock.json": true,
"*.{css,sass,scss}.d.ts": true
"*.{css,sass,scss}.d.ts": true,
"coverage/**":true
}
}
9 changes: 0 additions & 9 deletions Electron/src/__tests__/App.test.tsx

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,199 @@
import '@testing-library/jest-dom';
import '@testing-library/jest-dom/extend-expect';
import { act, fireEvent, render } from '@testing-library/react';
import ContextMenuPlaylist from 'components/AdvancedUIComponents/ContextMenu/Playlist/ContextMenuPlaylist';
import Global from 'global/global';
import { BrowserRouter } from 'react-router-dom';
import { UserType } from 'utils/role';
import Token from 'utils/token';
import * as router from 'react-router';

const playlistName = 'playlisttest';
const songName = 'songName';
const userName = 'prueba';
const roleUser = UserType.ARTIST;

const artistMockFetch = {
name: userName,
photo: 'photo',
register_date: 'date',
password: 'hashpassword',
playback_history: [songName],
playlists: [playlistName],
saved_playlists: [playlistName],
uploaded_songs: [songName],
};

const playlistDTOMockFetch = {
name: playlistName,
photo: 'playlist',
description: 'des',
upload_date: 'date',
owner: artistMockFetch,
song_names: [],
};

/* const songMockFetch = {
name: songName,
artist: userName,
photo: 'photo',
duration: '180',
genre: 'Rock',
number_of_plays: 2,
}; */

const navigate = jest.fn();

jest.spyOn(router, 'useNavigate').mockImplementation(() => navigate);
jest.spyOn(Token, 'getTokenUsername').mockReturnValue(userName);
jest.spyOn(Token, 'getTokenRole').mockReturnValue(roleUser);

global.fetch = jest.fn((url: string, options: any) => {
console.log(
'🚀 ~ file: ContextMenuPlaylist.test.tsx:52 ~ global.fetch=jest.fn ~ options:',
options
);
console.log(
'🚀 ~ file: ContextMenuPlaylist.test.tsx:52 ~ global.fetch=jest.fn ~ url:',
url
);
if (
url === `${Global.backendBaseUrl}playlists/dto/${playlistDTOMockFetch.name}`
) {
return Promise.resolve({
json: () => playlistDTOMockFetch,
status: 200,
}).catch((error) => {
console.log(error);
});
}
if (url === `${Global.backendBaseUrl}playlists/multiple/${playlistName}`) {
return Promise.resolve({
json: () =>
Promise.resolve({
playlists: [JSON.stringify(playlistDTOMockFetch)],
}),
status: 200,
}).catch((error) => {
console.log(error);
});
}

if (url === `${Global.backendBaseUrl}artistas/${artistMockFetch.name}`) {
return Promise.resolve({
json: () => artistMockFetch,
status: 200,
}).catch((error) => {
console.log(error);
});
}

if (options && options.method) {
if (options.method === 'DELETE') {
return Promise.resolve({
json: () => {},
status: 202,
}).catch((error) => {
console.log(error);
});
}
if (options.method === 'PUT') {
return Promise.resolve({
json: () => {},
status: 204,
}).catch((error) => {
console.log(error);
});
}

if (options.method === 'POST') {
return Promise.resolve({
json: () => artistMockFetch,
status: 201,
}).catch((error) => {
console.log(error);
});
}
}

// In case the URL doesn't match, return a rejected promise
return Promise.reject(new Error('Unhandled URL in fetch mock'));
}) as jest.Mock;

test('Render ContextMenuPlaylist', async () => {
const component = await act(() => {
return render(
<BrowserRouter>
<ContextMenuPlaylist
playlistName={playlistName}
owner={artistMockFetch.name}
handleCloseParent={jest.fn()}
refreshPlaylistData={jest.fn()}
refreshSidebarData={jest.fn()}
/>
</BrowserRouter>
);
});
expect(component).toBeTruthy();
});

test('ContextMenuPlaylist delete Playlist success', async () => {
const refreshSidebarDataMock = jest.fn();

const component = await act(() => {
return render(
<BrowserRouter>
<ContextMenuPlaylist
playlistName={playlistName}
owner={artistMockFetch.name}
handleCloseParent={jest.fn()}
refreshPlaylistData={jest.fn()}
refreshSidebarData={refreshSidebarDataMock}
/>
</BrowserRouter>
);
});

const deleteButton = component.getByText('Eliminar');
if (deleteButton) {
await act(async () => {
fireEvent.click(deleteButton);
});
}

expect(refreshSidebarDataMock).toHaveBeenCalled();
});

test('ContextMenuPlaylist Add Playlist to Playlist', async () => {
const refreshSidebarDataMock = jest.fn();

const component = await act(() => {
return render(
<BrowserRouter>
<ContextMenuPlaylist
playlistName={playlistName}
owner={artistMockFetch.name}
handleCloseParent={jest.fn()}
refreshPlaylistData={jest.fn()}
refreshSidebarData={refreshSidebarDataMock}
/>
</BrowserRouter>
);
});

const addToOtherPlaylistButton = component.getByText('Añadir a otra lista');
if (addToOtherPlaylistButton) {
await act(async () => {
fireEvent.click(addToOtherPlaylistButton);
});
}

const playlistButton = component.getByText(playlistName);
if (playlistButton) {
await act(async () => {
fireEvent.click(playlistButton);
});
}

expect(component.queryByText('Canciones añadidas')).toBeInTheDocument();
});
Loading
Loading