Compare commits
4 Commits
Author | SHA1 | Date |
---|---|---|
|
85041cf3fa | 1 year ago |
|
567aac667c | 1 year ago |
|
3579dd752d | 1 year ago |
|
9354634b6d | 1 year ago |
@ -0,0 +1,31 @@
|
|||||||
|
import React from 'react';
|
||||||
|
import { render } from '@testing-library/react-native';
|
||||||
|
import JokeHomeSquare from './JokeHomeSquare';
|
||||||
|
import { SampleJoke } from '../model/SampleJoke';
|
||||||
|
import { CustomJoke } from '../model/CustomJoke';
|
||||||
|
import {describe, expect, it} from "@jest/globals";
|
||||||
|
|
||||||
|
const sampleJoke = new SampleJoke(1, 'Type', 'Setup', 'Image', 'Punchline');
|
||||||
|
const customJoke = new CustomJoke('ID', 'Type', 'Setup', 'Image', 'Punchline');
|
||||||
|
|
||||||
|
describe('JokeHomeSquare Component', () => {
|
||||||
|
it('renders correctly with SampleJoke', () => {
|
||||||
|
const { getByText, getByTestId } = render(<JokeHomeSquare joke={sampleJoke} />);
|
||||||
|
|
||||||
|
expect(getByTestId('topBackground')).toBeTruthy();
|
||||||
|
expect(getByTestId('bottomBackground')).toBeTruthy();
|
||||||
|
expect(getByTestId('jokeImage')).toBeTruthy();
|
||||||
|
expect(getByText('Résumé de la blague')).toBeTruthy();
|
||||||
|
expect(getByText('Type, Punchline')).toBeTruthy();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('renders correctly with CustomJoke', () => {
|
||||||
|
const { getByText, getByTestId } = render(<JokeHomeSquare joke={customJoke} />);
|
||||||
|
|
||||||
|
expect(getByTestId('topBackground')).toBeTruthy();
|
||||||
|
expect(getByTestId('bottomBackground')).toBeTruthy();
|
||||||
|
expect(getByTestId('jokeImage')).toBeTruthy();
|
||||||
|
expect(getByText('Résumé de la blague')).toBeTruthy();
|
||||||
|
expect(getByText('Type, Punchline')).toBeTruthy();
|
||||||
|
});
|
||||||
|
});
|
@ -0,0 +1,31 @@
|
|||||||
|
import React from 'react';
|
||||||
|
import { render } from '@testing-library/react-native';
|
||||||
|
import JokeItem from './JokeItem';
|
||||||
|
import { SampleJoke } from '../model/SampleJoke';
|
||||||
|
import { CustomJoke } from '../model/CustomJoke';
|
||||||
|
import {describe, expect, it} from "@jest/globals";
|
||||||
|
|
||||||
|
const sampleJoke = new SampleJoke(1, 'Type', 'Setup', 'Image', 'Punchline');
|
||||||
|
const customJoke = new CustomJoke('ID', 'Type', 'Setup', 'Image', 'Punchline');
|
||||||
|
|
||||||
|
describe('JokeItem Component', () => {
|
||||||
|
it('renders correctly with SampleJoke', () => {
|
||||||
|
const { getByText, getByTestId } = render(<JokeItem joke={sampleJoke} />);
|
||||||
|
|
||||||
|
expect(getByTestId('color')).toBeTruthy();
|
||||||
|
expect(getByTestId('jokeImage')).toBeTruthy();
|
||||||
|
expect(getByText('Résumé de la blague')).toBeTruthy();
|
||||||
|
expect(getByText('Type, Punchline')).toBeTruthy();
|
||||||
|
expect(getByText('Type')).toBeTruthy();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('renders correctly with CustomJoke', () => {
|
||||||
|
const { getByText, getByTestId } = render(<JokeItem joke={customJoke} />);
|
||||||
|
|
||||||
|
expect(getByTestId('color')).toBeTruthy();
|
||||||
|
expect(getByTestId('jokeImage')).toBeTruthy();
|
||||||
|
expect(getByText('Résumé de la blague')).toBeTruthy();
|
||||||
|
expect(getByText('Type, Punchline')).toBeTruthy();
|
||||||
|
expect(getByText('Type')).toBeTruthy();
|
||||||
|
});
|
||||||
|
});
|
@ -0,0 +1,29 @@
|
|||||||
|
import React from 'react';
|
||||||
|
import { render } from '@testing-library/react-native';
|
||||||
|
import JokesHomeSquare from './JokesHomeSquare';
|
||||||
|
import { SampleJoke } from '../model/SampleJoke';
|
||||||
|
import { CustomJoke } from '../model/CustomJoke';
|
||||||
|
import {describe, expect, it} from "@jest/globals";
|
||||||
|
|
||||||
|
const sampleJokes = [
|
||||||
|
new SampleJoke(1, 'Type1', 'Setup1', 'Image1', 'Punchline1'),
|
||||||
|
new SampleJoke(2, 'Type2', 'Setup2', 'Image2', 'Punchline2'),
|
||||||
|
];
|
||||||
|
const customJokes = [
|
||||||
|
new CustomJoke('ID1', 'Type1', 'Setup1', 'Image1', 'Punchline1'),
|
||||||
|
new CustomJoke('ID2', 'Type2', 'Setup2', 'Image2', 'Punchline2'),
|
||||||
|
];
|
||||||
|
|
||||||
|
describe('JokesHomeSquare Component', () => {
|
||||||
|
it('renders correctly with SampleJokes', () => {
|
||||||
|
const { getAllByTestId } = render(<JokesHomeSquare jokes={sampleJokes} />);
|
||||||
|
|
||||||
|
expect(getAllByTestId('jokeHomeSquare')).toHaveLength(sampleJokes.length);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('renders correctly with CustomJokes', () => {
|
||||||
|
const { getAllByTestId } = render(<JokesHomeSquare jokes={customJokes} />);
|
||||||
|
|
||||||
|
expect(getAllByTestId('jokeHomeSquare')).toHaveLength(customJokes.length);
|
||||||
|
});
|
||||||
|
});
|
@ -0,0 +1,29 @@
|
|||||||
|
import React from 'react';
|
||||||
|
import { render } from '@testing-library/react-native';
|
||||||
|
import JokeItems from './JokeItems';
|
||||||
|
import { SampleJoke } from '../model/SampleJoke';
|
||||||
|
import { CustomJoke } from '../model/CustomJoke';
|
||||||
|
import {describe, expect, it} from "@jest/globals";
|
||||||
|
|
||||||
|
const sampleJokes = [
|
||||||
|
new SampleJoke(1, 'Type1', 'Setup1', 'Image1', 'Punchline1'),
|
||||||
|
new SampleJoke(2, 'Type2', 'Setup2', 'Image2', 'Punchline2'),
|
||||||
|
];
|
||||||
|
const customJokes = [
|
||||||
|
new CustomJoke('ID1', 'Type1', 'Setup1', 'Image1', 'Punchline1'),
|
||||||
|
new CustomJoke('ID2', 'Type2', 'Setup2', 'Image2', 'Punchline2'),
|
||||||
|
];
|
||||||
|
|
||||||
|
describe('JokeItems Component', () => {
|
||||||
|
it('renders correctly with SampleJokes', () => {
|
||||||
|
const { getAllByTestId } = render(<JokeItems jokes={sampleJokes} />);
|
||||||
|
|
||||||
|
expect(getAllByTestId('jokeItem')).toHaveLength(sampleJokes.length);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('renders correctly with CustomJokes', () => {
|
||||||
|
const { getAllByTestId } = render(<JokeItems jokes={customJokes} />);
|
||||||
|
|
||||||
|
expect(getAllByTestId('jokeItem')).toHaveLength(customJokes.length);
|
||||||
|
});
|
||||||
|
});
|
@ -0,0 +1,44 @@
|
|||||||
|
import { JokeFactory } from './JokeFactory';
|
||||||
|
import { CustomJoke } from './CustomJoke';
|
||||||
|
import { SampleJoke } from './SampleJoke';
|
||||||
|
import {describe, expect, it} from "@jest/globals";
|
||||||
|
|
||||||
|
describe('JokeFactory', () => {
|
||||||
|
describe('createCustomJokes', () => {
|
||||||
|
it('should create CustomJoke instances from JSON array', () => {
|
||||||
|
const jsonArray = '[{"id": "1", "type": "Type1", "setup": "Setup1", "punchline": "Punchline1", "image": "Image1"}, {"id": "2", "type": "Type2", "setup": "Setup2", "punchline": "Punchline2", "image": "Image2"}]';
|
||||||
|
const customJokes: CustomJoke[] = JokeFactory.createCustomJokes(jsonArray);
|
||||||
|
|
||||||
|
expect(customJokes).toHaveLength(2);
|
||||||
|
expect(customJokes[0]).toBeInstanceOf(CustomJoke);
|
||||||
|
expect(customJokes[0].id).toBe('1');
|
||||||
|
expect(customJokes[0].type).toBe('Type1');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return an empty array if JSON array is empty', () => {
|
||||||
|
const jsonArray = '[]';
|
||||||
|
const customJokes: CustomJoke[] = JokeFactory.createCustomJokes(jsonArray);
|
||||||
|
|
||||||
|
expect(customJokes).toHaveLength(0);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('createSampleJokes', () => {
|
||||||
|
it('should create SampleJoke instances from JSON array', () => {
|
||||||
|
const jsonArray = '[{"id": 1, "type": "Type1", "setup": "Setup1", "punchline": "Punchline1", "image": "Image1"}, {"id": 2, "type": "Type2", "setup": "Setup2", "punchline": "Punchline2", "image": "Image2"}]';
|
||||||
|
const sampleJokes: SampleJoke[] = JokeFactory.createSampleJokes(jsonArray);
|
||||||
|
|
||||||
|
expect(sampleJokes).toHaveLength(2);
|
||||||
|
expect(sampleJokes[0]).toBeInstanceOf(SampleJoke);
|
||||||
|
expect(sampleJokes[0].id).toBe(1);
|
||||||
|
expect(sampleJokes[0].type).toBe('Type1');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return an empty array if JSON array is empty', () => {
|
||||||
|
const jsonArray = '[]';
|
||||||
|
const sampleJokes: SampleJoke[] = JokeFactory.createSampleJokes(jsonArray);
|
||||||
|
|
||||||
|
expect(sampleJokes).toHaveLength(0);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
@ -0,0 +1,47 @@
|
|||||||
|
import { SampleJoke } from './SampleJoke';
|
||||||
|
import {describe, expect, it} from "@jest/globals";
|
||||||
|
|
||||||
|
describe('SampleJoke', () => {
|
||||||
|
it('should create a SampleJoke instance with provided values', () => {
|
||||||
|
const id = 1;
|
||||||
|
const type = 'Type';
|
||||||
|
const setup = 'Setup';
|
||||||
|
const image = 'Image';
|
||||||
|
const punchline = 'Punchline';
|
||||||
|
|
||||||
|
const sampleJoke = new SampleJoke(id, type, setup, image, punchline);
|
||||||
|
|
||||||
|
expect(sampleJoke).toBeInstanceOf(SampleJoke);
|
||||||
|
expect(sampleJoke.id).toBe(id);
|
||||||
|
expect(sampleJoke.type).toBe(type);
|
||||||
|
expect(sampleJoke.setup).toBe(setup);
|
||||||
|
expect(sampleJoke.image).toBe(image);
|
||||||
|
expect(sampleJoke.punchline).toBe(punchline);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should create a SampleJoke instance with default punchline if not provided', () => {
|
||||||
|
const id = 1;
|
||||||
|
const type = 'Type';
|
||||||
|
const setup = 'Setup';
|
||||||
|
const image = 'Image';
|
||||||
|
|
||||||
|
const sampleJoke = new SampleJoke(id, type, setup, image);
|
||||||
|
|
||||||
|
expect(sampleJoke).toBeInstanceOf(SampleJoke);
|
||||||
|
expect(sampleJoke.id).toBe(id);
|
||||||
|
expect(sampleJoke.type).toBe(type);
|
||||||
|
expect(sampleJoke.setup).toBe(setup);
|
||||||
|
expect(sampleJoke.image).toBe(image);
|
||||||
|
expect(sampleJoke.punchline).toBe('');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should correctly modify the id', () => {
|
||||||
|
const sampleJoke = new SampleJoke(1, 'Type', 'Setup', 'Image');
|
||||||
|
|
||||||
|
expect(sampleJoke.id).toBe(1);
|
||||||
|
|
||||||
|
sampleJoke.id = 2;
|
||||||
|
|
||||||
|
expect(sampleJoke.id).toBe(2);
|
||||||
|
});
|
||||||
|
});
|
@ -0,0 +1,22 @@
|
|||||||
|
import React from 'react';
|
||||||
|
import { render } from '@testing-library/react-native';
|
||||||
|
import NavigationBar from './NavigationBar';
|
||||||
|
import {describe, expect, it} from "@jest/globals";
|
||||||
|
|
||||||
|
describe('<NavigationBar />', () => {
|
||||||
|
it('renders correctly', () => {
|
||||||
|
const { getByText, getByA11yLabel } = render(<NavigationBar />);
|
||||||
|
|
||||||
|
expect(getByText('Accueil')).toBeTruthy();
|
||||||
|
expect(getByText('Catalogue')).toBeTruthy();
|
||||||
|
expect(getByText("Ajout d'une blague")).toBeTruthy();
|
||||||
|
expect(getByText('Favoris')).toBeTruthy();
|
||||||
|
expect(getByText('Parametres')).toBeTruthy();
|
||||||
|
|
||||||
|
expect(getByA11yLabel('Accueil icon')).toBeTruthy();
|
||||||
|
expect(getByA11yLabel('Catalogue icon')).toBeTruthy();
|
||||||
|
expect(getByA11yLabel('Ajout d\'une blague icon')).toBeTruthy();
|
||||||
|
expect(getByA11yLabel('Favoris icon')).toBeTruthy();
|
||||||
|
expect(getByA11yLabel('Parametres icon')).toBeTruthy();
|
||||||
|
});
|
||||||
|
});
|
@ -0,0 +1,26 @@
|
|||||||
|
import React from 'react';
|
||||||
|
import { render } from '@testing-library/react-native';
|
||||||
|
import StackNavigation from './StackNavigation';
|
||||||
|
import {describe, expect, it} from "@jest/globals";
|
||||||
|
|
||||||
|
describe('<StackNavigation />', () => {
|
||||||
|
it('renders correctly', () => {
|
||||||
|
const { getByText } = render(<StackNavigation />);
|
||||||
|
|
||||||
|
expect(getByText('catalogue')).toBeTruthy();
|
||||||
|
expect(getByText('JokeDetails')).toBeTruthy();
|
||||||
|
|
||||||
|
const header = getByText('catalogue').parentNode;
|
||||||
|
expect(header).toHaveStyle({
|
||||||
|
backgroundColor: 'indigo',
|
||||||
|
});
|
||||||
|
|
||||||
|
const headerTitle = getByText('catalogue');
|
||||||
|
expect(headerTitle).toHaveStyle({
|
||||||
|
color: 'darksalmon',
|
||||||
|
fontSize: 24,
|
||||||
|
textAlign: 'center',
|
||||||
|
paddingBottom: 30,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,66 @@
|
|||||||
|
import React from 'react';
|
||||||
|
import { render, fireEvent } from '@testing-library/react-native';
|
||||||
|
import AddScreen, { themeSettings } from './AddScreen';
|
||||||
|
import { Provider } from 'react-redux';
|
||||||
|
import store from '../redux/store';
|
||||||
|
import {describe, expect, it} from "@jest/globals";
|
||||||
|
|
||||||
|
describe('<AddScreen />', () => {
|
||||||
|
it('renders correctly', () => {
|
||||||
|
const { getByText, getByPlaceholderText } = render(
|
||||||
|
<Provider store={store}>
|
||||||
|
<AddScreen />
|
||||||
|
</Provider>
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(getByText('Blague')).toBeTruthy();
|
||||||
|
expect(getByPlaceholderText('Inserez votre blague')).toBeTruthy();
|
||||||
|
expect(getByText('Chute de la blague')).toBeTruthy();
|
||||||
|
expect(getByPlaceholderText('Inserez votre blague')).toBeTruthy();
|
||||||
|
expect(getByText('Catégorie')).toBeTruthy();
|
||||||
|
expect(getByPlaceholderText('Inserez votre blague')).toBeTruthy();
|
||||||
|
expect(getByText('CRÉER')).toBeTruthy();
|
||||||
|
expect(getByText('EFFACER')).toBeTruthy();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('handles text input correctly', () => {
|
||||||
|
const { getByPlaceholderText } = render(
|
||||||
|
<Provider store={store}>
|
||||||
|
<AddScreen />
|
||||||
|
</Provider>
|
||||||
|
);
|
||||||
|
|
||||||
|
const jokeInput = getByPlaceholderText('Inserez votre blague');
|
||||||
|
const downgradeInput = getByPlaceholderText('Inserez votre blague');
|
||||||
|
const categoryInput = getByPlaceholderText('Inserez votre blague');
|
||||||
|
|
||||||
|
fireEvent.changeText(jokeInput, 'This is a joke');
|
||||||
|
fireEvent.changeText(downgradeInput, 'This is a downgrade');
|
||||||
|
fireEvent.changeText(categoryInput, 'Funny');
|
||||||
|
|
||||||
|
expect(jokeInput.props.value).toBe('This is a joke');
|
||||||
|
expect(downgradeInput.props.value).toBe('This is a downgrade');
|
||||||
|
expect(categoryInput.props.value).toBe('Funny');
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('themeSettings()', () => {
|
||||||
|
it('returns correct styles for light theme', () => {
|
||||||
|
const theme = {
|
||||||
|
colors: {
|
||||||
|
background: 'white',
|
||||||
|
card: 'lightgrey',
|
||||||
|
text: 'black',
|
||||||
|
primary: 'blue',
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
const styles = themeSettings(theme);
|
||||||
|
expect(styles.container.backgroundColor).toBe('white');
|
||||||
|
expect(styles.textInput.backgroundColor).toBe('lightgrey');
|
||||||
|
expect(styles.text.color).toBe('black');
|
||||||
|
expect(styles.eraseButton.backgroundColor).toBe('blue');
|
||||||
|
expect(styles.createButton.backgroundColor).toBe('blue');
|
||||||
|
});
|
||||||
|
});
|
@ -0,0 +1,58 @@
|
|||||||
|
import React from 'react';
|
||||||
|
import { render, fireEvent } from '@testing-library/react-native';
|
||||||
|
import Catalogue, { themeSettings } from './Catalogue';
|
||||||
|
import { Provider } from 'react-redux';
|
||||||
|
import store from '../redux/store';
|
||||||
|
import {describe, expect, it} from "@jest/globals";
|
||||||
|
|
||||||
|
describe('<Catalogue />', () => {
|
||||||
|
it('renders correctly', () => {
|
||||||
|
const { getByText, getByTestId } = render(
|
||||||
|
<Provider store={store}>
|
||||||
|
<Catalogue />
|
||||||
|
</Provider>
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(getByText('Afficher les exemples')).toBeTruthy();
|
||||||
|
expect(getByTestId('toggle-button')).toBeTruthy();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('toggles jokes display correctly', () => {
|
||||||
|
const { getByTestId } = render(
|
||||||
|
<Provider store={store}>
|
||||||
|
<Catalogue />
|
||||||
|
</Provider>
|
||||||
|
);
|
||||||
|
|
||||||
|
const toggleButton = getByTestId('toggle-button');
|
||||||
|
|
||||||
|
fireEvent.press(toggleButton);
|
||||||
|
|
||||||
|
expect(toggleButton.props.children.props.source).toEqual(hideEye);
|
||||||
|
|
||||||
|
fireEvent.press(toggleButton);
|
||||||
|
|
||||||
|
expect(toggleButton.props.children.props.source).toEqual(eye);
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('themeSettings()', () => {
|
||||||
|
it('returns correct styles for light theme', () => {
|
||||||
|
const theme = {
|
||||||
|
colors: {
|
||||||
|
background: 'white',
|
||||||
|
primary: 'blue',
|
||||||
|
text: 'black',
|
||||||
|
notification: 'grey',
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
const styles = themeSettings(theme);
|
||||||
|
expect(styles.container.backgroundColor).toBe('white');
|
||||||
|
expect(styles.Button.backgroundColor).toBe('blue');
|
||||||
|
expect(styles.TextButton.color).toBe('black');
|
||||||
|
expect(styles.imageButton.tintColor).toBe('grey');
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
@ -0,0 +1,57 @@
|
|||||||
|
import React from 'react';
|
||||||
|
import { render, fireEvent } from '@testing-library/react-native';
|
||||||
|
import Favorites, { themeSettings } from './Favorites';
|
||||||
|
import { Provider } from 'react-redux';
|
||||||
|
import store from '../redux/store';
|
||||||
|
import {describe, expect, it} from "@jest/globals"; // Assuming you have a configured Redux store
|
||||||
|
|
||||||
|
describe('<Favorites />', () => {
|
||||||
|
it('renders correctly', () => {
|
||||||
|
const { getByText, getByTestId } = render(
|
||||||
|
<Provider store={store}>
|
||||||
|
<Favorites />
|
||||||
|
</Provider>
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(getByText('Afficher les exemples')).toBeTruthy();
|
||||||
|
expect(getByTestId('toggle-button')).toBeTruthy();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('toggles jokes display correctly', () => {
|
||||||
|
const { getByTestId } = render(
|
||||||
|
<Provider store={store}>
|
||||||
|
<Favorites />
|
||||||
|
</Provider>
|
||||||
|
);
|
||||||
|
|
||||||
|
const toggleButton = getByTestId('toggle-button');
|
||||||
|
|
||||||
|
fireEvent.press(toggleButton);
|
||||||
|
|
||||||
|
expect(toggleButton.props.children.props.source).toEqual(hideEye);
|
||||||
|
|
||||||
|
fireEvent.press(toggleButton);
|
||||||
|
|
||||||
|
expect(toggleButton.props.children.props.source).toEqual(eye);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('themeSettings()', () => {
|
||||||
|
it('returns correct styles for light theme', () => {
|
||||||
|
const theme = {
|
||||||
|
colors: {
|
||||||
|
background: 'white',
|
||||||
|
primary: 'blue',
|
||||||
|
text: 'black',
|
||||||
|
notification: 'grey',
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
const styles = themeSettings(theme);
|
||||||
|
expect(styles.container.backgroundColor).toBe('white');
|
||||||
|
expect(styles.Button.backgroundColor).toBe('white');
|
||||||
|
expect(styles.TextButton.color).toBe('grey');
|
||||||
|
expect(styles.imageButton.tintColor).toBe('grey');
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
@ -0,0 +1,41 @@
|
|||||||
|
import React from 'react';
|
||||||
|
import { render } from '@testing-library/react-native';
|
||||||
|
import HomeScreen, { themeSettings } from './HomeScreen';
|
||||||
|
import { Provider } from 'react-redux';
|
||||||
|
import store from '../redux/store';
|
||||||
|
import {describe, expect, it} from "@jest/globals";
|
||||||
|
|
||||||
|
describe('<HomeScreen />', () => {
|
||||||
|
it('renders correctly', () => {
|
||||||
|
const { getByText, getByTestId } = render(
|
||||||
|
<Provider store={store}>
|
||||||
|
<HomeScreen />
|
||||||
|
</Provider>
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(getByText('Chat C\'est Drole')).toBeTruthy();
|
||||||
|
expect(getByText('Dernières blagues')).toBeTruthy();
|
||||||
|
expect(getByText('Top Categories')).toBeTruthy();
|
||||||
|
expect(getByTestId('jokes-home-square')).toBeTruthy();
|
||||||
|
expect(getByTestId('categs')).toBeTruthy();
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('themeSettings()', () => {
|
||||||
|
it('returns correct styles for light theme', () => {
|
||||||
|
const theme = {
|
||||||
|
colors: {
|
||||||
|
background: 'white',
|
||||||
|
text: 'black',
|
||||||
|
border: 'grey',
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
const styles = themeSettings(theme);
|
||||||
|
expect(styles.container.backgroundColor).toBe('white');
|
||||||
|
expect(styles.textAccueil.color).toBe('black');
|
||||||
|
expect(styles.textLastJokes.color).toBe('grey');
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
@ -0,0 +1,55 @@
|
|||||||
|
import React from 'react';
|
||||||
|
import { render } from '@testing-library/react-native';
|
||||||
|
import JokeDetailsScreen, { themeSettings } from './JokeDetailsScreen';
|
||||||
|
import { Provider } from 'react-redux';
|
||||||
|
import store from '../redux/store';
|
||||||
|
import {describe, expect, it} from "@jest/globals";
|
||||||
|
|
||||||
|
describe('<JokeDetailsScreen />', () => {
|
||||||
|
it('renders correctly for sample joke', () => {
|
||||||
|
const mockRoute = {
|
||||||
|
params: {
|
||||||
|
idJoke: 1,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
const { getByTestId } = render(
|
||||||
|
<Provider store={store}>
|
||||||
|
<JokeDetailsScreen route={mockRoute} />
|
||||||
|
</Provider>
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(getByTestId('joke-detail')).toBeTruthy();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('renders correctly for custom joke', () => {
|
||||||
|
const mockRoute = {
|
||||||
|
params: {
|
||||||
|
idJoke: 1,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
const { getByTestId } = render(
|
||||||
|
<Provider store={store}>
|
||||||
|
<JokeDetailsScreen route={mockRoute} />
|
||||||
|
</Provider>
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(getByTestId('joke-detail')).toBeTruthy();
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('themeSettings()', () => {
|
||||||
|
it('returns correct styles', () => {
|
||||||
|
const theme = {
|
||||||
|
colors: {
|
||||||
|
background: 'white',
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
const styles = themeSettings(theme);
|
||||||
|
expect(styles.container.backgroundColor).toBe('white');
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
@ -0,0 +1,53 @@
|
|||||||
|
import React from 'react';
|
||||||
|
import { render, fireEvent } from '@testing-library/react-native';
|
||||||
|
import Settings, { themeSettings } from './Settings';
|
||||||
|
import { Provider } from 'react-redux';
|
||||||
|
import store from '../redux/store';
|
||||||
|
import {describe, expect, it} from "@jest/globals";
|
||||||
|
|
||||||
|
describe('<Settings />', () => {
|
||||||
|
it('renders correctly', () => {
|
||||||
|
const { getByTestId } = render(
|
||||||
|
<Provider store={store}>
|
||||||
|
<Settings />
|
||||||
|
</Provider>
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(getByTestId('settings-title')).toBeTruthy();
|
||||||
|
expect(getByTestId('settings-switch')).toBeTruthy();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('switches between light and dark mode', () => {
|
||||||
|
const { getByTestId } = render(
|
||||||
|
<Provider store={store}>
|
||||||
|
<Settings />
|
||||||
|
</Provider>
|
||||||
|
);
|
||||||
|
|
||||||
|
const switchElement = getByTestId('settings-switch');
|
||||||
|
|
||||||
|
expect(switchElement.props.value).toBeFalsy();
|
||||||
|
|
||||||
|
fireEvent(switchElement, 'onValueChange', true);
|
||||||
|
|
||||||
|
expect(switchElement.props.value).toBeTruthy();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('themeSettings()', () => {
|
||||||
|
it('returns correct styles', () => {
|
||||||
|
const theme = {
|
||||||
|
colors: {
|
||||||
|
background: 'white',
|
||||||
|
text: 'black',
|
||||||
|
primary: 'blue',
|
||||||
|
card: 'gray',
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
const styles = themeSettings(theme);
|
||||||
|
expect(styles.container.backgroundColor).toBe('white');
|
||||||
|
expect(styles.title.color).toBe('black');
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in new issue