tests unitaires + vue matchmaking moche

Persistance
Mathilde JEAN 2 years ago
parent e37f2a0335
commit 3f5ab45877

@ -0,0 +1,39 @@
import { FC, ReactNode, useCallback } from "react"
import { Pressable, Image, ImageStyle, Text, View, Alert, ImageSourcePropType, TextStyle } from "react-native"
import React from "react"
import { trace } from "console"
import { Game } from "../core/game"
/*
Importing the correct stylesheet
*/
import styles from './style/Game.style';
import LobbySolo from "../screens/LobbySolo"
import ManagerMatch from "../services/matchServices/managerMatch"
import MatchCreator from "../core/Match/matchCreator"
import { useMatchStore } from "../context/matchContext"
import { MANAGER_MATCH, MANAGER_USER } from "../../appManagers"
import { Match } from "../core/Match/match"
import { User } from "../core/User/user"
export const PlayerBox :
/*
* match : match that must be displayed
* nav : tool needed to allow the navigation between the screens
*/
FC<{user: User}> =
({user}) =>
{
return (
<View>
<Image
style={styles.image}
source={{uri: user.getCurrentSkin().getSkinSource()}}
/>
<Text style={styles.name}>{user.getUsername()}</Text>
</View>
)
}

@ -1,5 +1,4 @@
import MatchSolo from '../Match/matchSolo';
import { Conversation } from '../Conversation';
import { Skin } from '../Skin';
import { User } from '../User/user';
import { GameSolo } from '../GameSolo';
@ -21,10 +20,12 @@ let myMap = new Map<number, number>([
[100, 5],
[150, 6]
]);
let game=new GameSolo(1, "bo jeu", img, "super jeu", 1, 1, myMap);
let match = new MatchSolo(1, false, tabU, game);
let tabU2:User[] = [];
let game=new GameSolo(1, "bo jeu", img, "super jeu", 1, 1, myMap);
let game2 = new GameSolo(2, "jeu magnifique", img, "wow jeu", 1, 1, myMap)
let match = new MatchSolo(1, false, tabU, game);
let match2 = new MatchSolo(1, false, tabU2, game2);
let match3 = new MatchSolo(1, false, tabU, game);
// Get tests
@ -36,50 +37,47 @@ describe('Match get tests', () => {
expect(match.getInGame()).toBe(false);
})
it('should return tabU [usr] (users)', () => {
expect(match.getTabUsers()).toBe(tabU);
expect(match.getTabUsers()).toEqual(match3.getTabUsers());
})
it('should return game', () => {
expect(match.getGame).toBe(game);
expect(match.getGame()).toEqual(match3.getGame());
})
})
// Setting new values
match.setGame(game2);
match.setInGame(true);
match.setTabUser(tabU2);
// Set tests
describe('Match set tests', () => {
it('should return tabU2 [] (users)', () => {
expect(match.getTabUsers()).toBe(tabU2);
match.setTabUser(tabU2);
expect(match.getTabUsers()).toEqual(match2.getTabUsers());
})
it('should return true', () => {
match.setInGame(true);
expect(match.getInGame()).toBe(true);
})
it('should return game2', () => {
expect(match.getGame).toBe(game2);
match.setGame(game2);
expect(match.getGame()).toEqual(match2.getGame());
})
})
// Update Post-Match tests
describe('Update post-match tests', () => {
it('should return 3', () => {
match.updatePostMatch(tabU[0],50);
expect(tabU[0].getCurrentCoins()).toBe(3);
it('should return 50', () => {
match.updatePostMatch(tabU[0],3);
expect(tabU[0].getCurrentCoins()).toBe(50);
})
it('should return 8', () => {
match.updatePostMatch(tabU[0],100);
expect(tabU[0].getCurrentCoins()).toBe(8);
it('should return 75', () => {
match.updatePostMatch(usr2,4);
expect(usr2.getCurrentCoins()).toBe(75);
})
it('should return 4', () => {
match.updatePostMatch(usr2,75);
expect(usr2.getCurrentCoins()).toBe(4);
it('should return 150', () => {
match.updatePostMatch(tabU[0],5);
expect(tabU[0].getCurrentCoins()).toBe(150);
})
it('should return 10', () => {
match.updatePostMatch(usr2,150);
expect(usr2.getCurrentCoins()).toBe(10);
it('should return 225', () => {
match.updatePostMatch(usr2,6);
expect(usr2.getCurrentCoins()).toBe(225);
})
})

@ -14,6 +14,7 @@ import SignIn from '../screens/SignIn'
import SignUp from '../screens/SignUp'
import LobbySolo from '../screens/LobbySolo'
import CookieClicker from '../Games/CookieClicker/cookieClicker'
import MatchMaking from '../screens/MatchMaking'
const HomeStack = createStackNavigator();
@ -93,7 +94,7 @@ const GameSoloStack = createStackNavigator();
function GameSoloStackScreen() {
return (
<GameSoloStack.Navigator screenOptions={{headerShown: false}}>
<GameSoloStack.Screen name='LobbySolo' component={LobbySolo} options={{animationEnabled: false,}}/>
<GameSoloStack.Screen name='MatchMaking' component={MatchMaking} options={{animationEnabled: false,}}/>
<GameSoloStack.Screen name='CookieClicker' component={CookieClicker} />
</GameSoloStack.Navigator>
);

@ -0,0 +1,47 @@
import { StatusBar } from 'expo-status-bar'
import { View, Image, Text, Button} from 'react-native'
import React from 'react';
import stylesScreen from './style/screens.style';
import styles from './style/Settings.style';
import { TopBar } from '../components/TopBar';
import { BotBar } from '../components/BotBar';
import { Conversation } from '../core/conversation';
import { ButtonGameTypeChoice } from '../components/ButtonGameTypeChoice';
import { useMatchStore } from '../context/matchContext';
import { FlatList, TextInput } from 'react-native-gesture-handler';
import { PlayerBox } from '../components/PlayerBox';
function MatchMaking(props: { navigation: any; }) {
const { navigation } = props
const match = useMatchStore().match;
return (
<View style={stylesScreen.container}>
<TopBar
nav={navigation}
state='matchmacking'
/>
<FlatList
data={match?.getTabUsers()}
keyExtractor={usr =>usr.getUsername()}
renderItem={({item}) => <PlayerBox user={item}/>}
/>
<View style={stylesScreen.bodyCenter}>
<Button
title='Lancer la partie'
onPress={() => navigation.navigate(match?.getGame().getName().replace(/\s/g, ''))}
/>
</View>
<Image
style={{width:100, height:100}}
source={{uri: match?.getGame().getImageSource()}}
/>
</View>
);
}
export default MatchMaking

@ -1,62 +0,0 @@
import LoaderUserApi from '../userServices/loaderUserApi';
import ILoaderUser from '../userServices/ILoaderUser';
import { Match } from '../../core/Match/match';
import MatchSolo from '../../core/Match/matchSolo';
import { GameSolo } from '../../core/gameSolo';
import tabUS from '../../constUser';
import { Conversation } from '../../core/conversation';
// Instances
const img = "";
let loader:ILoaderUser = new LoaderUserApi();
let map = new Map<number, number>([
[50, 3],
[75, 4],
[100, 5],
[150, 6]
]);
let game:GameSolo = new GameSolo(1, 'SuperJeu', img, 'source', 1, 1, map);
let match:Match = new MatchSolo(1, false, tabUS, game);
let convo:Conversation = new Conversation(1, tabUS, [], 'superConvo');
// Tests
describe('LoaderUserApi tests', () => {
describe('loadById tests', () => {
it('should return UserTest (id: 48)', () => {
expect(loader.loadByID(48)).toEqual(tabUS[0]);
})
it('should return null', () => {
expect(loader.loadByID(99999999999)).toBe(null);
})
})
describe('loadByUserName tests', () => {
it('should return USerTest (name: WeshWesh)', () => {
expect(loader.loadByUsername('WeshWesh')).toEqual(tabUS[0]);
})
it('should return null', () => {
expect(loader.loadByUsername('jExistePas')).toBe(null);
})
})
describe('loadByUserNamePassword tests', () => {
it('should return UserTest (name: WeshWesh, password: MdpDeOuf)', () => {
expect(loader.loadByUsernamePassword('WeshWesh', 'MdpDeOuf')).toEqual(tabUS[0]);
})
it('should return null', () => {
expect(loader.loadByUsernamePassword('jExistePas', 'jExistePas')).toBe(null);
})
})
describe('loadUserByMatch tests', () => {
it('should return tabUS', () => {
expect(loader.loadUserByMatch(match)).toEqual(tabUS);
})
it('should return null', () => {
expect(loader.loadByUsernamePassword('jExistePas', 'jExistePas')).toEqual(null);
})
})
describe('loadUserByConversation tests', () => {
it('should return tabUS', () => {
expect(loader.loadUserByConversation(convo)).toEqual(tabUS);
})
})
})

@ -1,21 +0,0 @@
/*
import LoaderUserApi from '../userServices/loaderUserApi';
import SaverUserApi from '../userServices/saverUserApi';
// Instances
let saver:SaverUserApi = new SaverUserApi();
let loader = new LoaderUserApi();
// Tests
describe('SaverUserApi tests', () => {
describe('saverUser tests', () => {
})
})
*/
it('should return true', () => {
expect(1+1).toBe(2);
})

@ -1,78 +0,0 @@
import StubUser from '../userServices/stub';
import { User } from '../../core/User/user';
import { Skin } from '../../core/skin';
import { GameSolo } from '../../core/gameSolo';
import MatchSolo from '../../core/Match/matchSolo';
import { Match } from '../../core/Match/match';
import { Conversation } from '../../core/conversation';
// Instances
const img = "";
let stub:StubUser = new StubUser();
let map = new Map<number, number>([
[50, 3],
[75, 4],
[100, 5],
[150, 6]
]);
let tabUS:User[] = [
new User(1, "WeshWesh", "MdpDeOuf", "ouioui", "grand", new Date(2022,12,12), 12222, 123324, 12, new Skin(1, "Bob", img, 0), [new Skin(1, "Bob", img, 0)]),
new User(2, "leBg", "MdpDeOuf", "ouioui", "grand", new Date(2022,12,12), 12222, 123324, 12, new Skin(1, "Bob", img, 0), [new Skin(1, "Bob", img, 0)]),
new User(3, "Alban", "oui", "ouioui", "homme", new Date(2022,12,12), 555, 667, 12, new Skin(1, "Bob", img, 0), [new Skin(1, "Bob", img, 0)],),
new User(4, "Fefe63", "jesuishm", "ouioui", "homme", new Date(2022,12,12), 12222, 123324, 12, new Skin(1, "Bob", img, 0), [new Skin(1, "Bob", img, 0)]),
];
let game:GameSolo = new GameSolo(1, 'SuperJeu', img, 'source', 1, 1, map);
let match:Match = new MatchSolo(1, false, tabUS, game);
let convo:Conversation = new Conversation(1, tabUS, [], 'superConvo');
// Tests
describe('StubUser tests', () => {
describe('loadAllUser tests', () => {
it('should return tabUS', () => {
expect(stub.loadAllUser()).toEqual(tabUS);
})
})
describe('loadById tests', () => {
it('should return UserTest (id: 48)', () => {
expect(stub.loadByID(48)).toEqual(tabUS[0]);
})
it('should return null', () => {
expect(stub.loadByID(999999999999)).toBe(null);
})
})
describe('loadByUserName tests', () => {
it('should return USerTest (name: WeshWesh)', () => {
expect(stub.loadByUsername('WeshWesh')).toEqual(tabUS[0]);
})
it('should return null', () => {
expect(stub.loadByUsername('jExistePas')).toBe(null);
})
})
describe('loadByUserNamePassword tests', () => {
it('should return UserTest (name: WeshWesh, password: MdpDeOuf)', () => {
expect(stub.loadByUsernamePassword('WeshWesh', 'MdpDeOuf')).toEqual(tabUS[0]);
})
it('should return null', () => {
expect(stub.loadByUsernamePassword('jExistePas', 'jExistePas')).toBe(null);
})
})
describe('loadUserByMatch tests', () => {
it('should return tabUS', () => {
expect(stub.loadUserByMatch(match)).toEqual(tabUS);
})
it('should return null', () => {
expect(stub.loadByUsernamePassword('jExistePas', 'jExistePas')).toEqual(null);
})
})
describe('loadUserByConversation tests', () => {
it('should return tabUS', () => {
expect(stub.loadUserByConversation(convo)).toEqual(tabUS);
})
})
describe('loadLastId', () => {
it('should return U0005', () => {
expect(stub.loadLastId()).toBe('U0005');
})
})
})

@ -43,10 +43,4 @@ export default interface ILoaderUser{
* return an array of User
*/
loadUserByConversation(c:Conversation): Promise<User[]>;
/**
* loadLastId methode that load the last id used to create a user
* return a String
*/
loadLastId(): Promise<number>;
}

@ -129,8 +129,4 @@ export default class LoaderUserApi implements ILoaderUser{
}
return 1;
}
}

@ -1,5 +1,7 @@
import { Conversation } from "../../core/conversation";
import { GameSolo } from "../../core/gameSolo";
import { Match } from "../../core/Match/match";
import MatchSolo from "../../core/Match/matchSolo";
import { Skin } from "../../core/skin";
import { User } from "../../core/User/user";
import ILoaderUser from "./ILoaderUser";
@ -8,12 +10,24 @@ export default class StubUser implements ILoaderUser{
skin:Skin=new Skin(1, "Bob","https://codefirst.iut.uca.fr/git/BOB_PARTEAM/BOB_PARTY/raw/branch/typescript/bob_party/assets/BobsSkins/BobClassic.png", 0);
tabUS:User[]=[
new User(1, "leBg", "MdpDeOuf", "ouioui", "grand", new Date(2022,12,12), 12222, 123324, 12, this.skin, [this.skin]),
new User(2, "WeshWesh", "MdpDeOuf", "ouioui", "grand", new Date(2022,12,12), 12222, 123324, 12, this.skin, [this.skin]),
];
convo:Conversation = new Conversation(1, this.tabUS, [], 'superConvo');
map = new Map<number, number>([
[50, 3],
[75, 4],
[100, 5],
[150, 6]
]);
game:GameSolo = new GameSolo(1, 'SuperJeu', "", 'source', 1, 1, this.map);
match:Match = new MatchSolo(1, false, this.tabUS, this.game);
async loadAllUser(): Promise<User[]> {
return this.tabUS;
}
@ -58,8 +72,4 @@ export default class StubUser implements ILoaderUser{
return tabUser;
}
async loadLastId(): Promise<number> {
throw new Error("Method not implemented.");
}
}
Loading…
Cancel
Save