diff --git a/__tests__/context/MessagesContext.test.tsx b/__tests__/context/MessagesContext.test.tsx index 37b6ad7e..1c6d7a38 100644 --- a/__tests__/context/MessagesContext.test.tsx +++ b/__tests__/context/MessagesContext.test.tsx @@ -1,4 +1,5 @@ import React from 'react' + import { expect } from '@jest/globals' import { act, render, screen } from '@testing-library/react' import '@testing-library/jest-dom/jest-globals' diff --git a/__tests__/context/PathsContext.test.tsx b/__tests__/context/PathsContext.test.tsx index 269603a1..2000ba2c 100644 --- a/__tests__/context/PathsContext.test.tsx +++ b/__tests__/context/PathsContext.test.tsx @@ -1,4 +1,5 @@ import React from 'react' + import { expect } from '@jest/globals' import { act, render, screen } from '@testing-library/react' import '@testing-library/jest-dom/jest-globals' diff --git a/__tests__/context/StylesContext.test.tsx b/__tests__/context/StylesContext.test.tsx new file mode 100644 index 00000000..e58909dd --- /dev/null +++ b/__tests__/context/StylesContext.test.tsx @@ -0,0 +1,61 @@ +import React from 'react'; + +import { render, screen, act } from '@testing-library/react'; +import { StylesProvider, useStylesContext } from '../../src/context/StylesContext'; +import { DefaultStyles } from "../../src/constants/internal/DefaultStyles"; +import '@testing-library/jest-dom'; + + +// Mocking a child component to test context +const MockChild = () => { + const { styles, setStyles } = useStylesContext(); + + return ( +
+

Current Styles: {JSON.stringify(styles)}

+ +
+ ); +}; + +// Test suite for StylesProvider +describe('StylesProvider', () => { + beforeEach(() => { + jest.clearAllMocks(); + }); + + test('provides default styles', () => { + render( + + + + ); + + // Check if the default styles are provided + const stylesElement = screen.getByText(`Current Styles: ${JSON.stringify(DefaultStyles)}`); + expect(stylesElement).toBeInTheDocument(); + }); + + test('allows updating styles through setStyles', () => { + const setStylesMock = jest.fn(); + render( + + + + ); + + // Click the button to change styles + const button = screen.getByText('Change Chat Window Style'); + act(() => { + button.click(); + }); + + // Verify that setStyles was called with the updated styles + expect(setStylesMock).toHaveBeenCalledWith({ + ...DefaultStyles, + chatWindowStyle: { backgroundColor: 'blue' }, + }); + }); +}); diff --git a/package-lock.json b/package-lock.json index 5dc41652..7bc6276a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,12 +9,13 @@ "version": "2.0.0-beta.21", "license": "MIT", "devDependencies": { - "@testing-library/jest-dom": "^6.5.0", + "@testing-library/jest-dom": "^6.6.2", "@testing-library/react": "^16.0.1", "@types/dom-speech-recognition": "^0.0.4", "@types/jest": "^29.5.13", "@types/react": "^18.3.6", "@types/react-dom": "^18.3.0", + "@types/testing-library__react-hooks": "^3.4.1", "@typescript-eslint/eslint-plugin": "^5.60.1", "@vitejs/plugin-react": "^4.0.4", "cypress": "^13.14.2", @@ -2095,9 +2096,9 @@ } }, "node_modules/@testing-library/jest-dom": { - "version": "6.5.0", - "resolved": "https://registry.npmjs.org/@testing-library/jest-dom/-/jest-dom-6.5.0.tgz", - "integrity": "sha512-xGGHpBXYSHUUr6XsKBfs85TWlYKpTc37cSBBVrXcib2MkHLboWlkClhWF37JKlDb9KEq3dHs+f2xR7XJEWGBxA==", + "version": "6.6.2", + "resolved": "https://registry.npmjs.org/@testing-library/jest-dom/-/jest-dom-6.6.2.tgz", + "integrity": "sha512-P6GJD4yqc9jZLbe98j/EkyQDTPgqftohZF5FBkHY5BUERZmcf4HeO2k0XaefEg329ux2p21i1A1DmyQ1kKw2Jw==", "dev": true, "license": "MIT", "dependencies": { @@ -2339,6 +2340,7 @@ "resolved": "https://registry.npmjs.org/@types/jest/-/jest-29.5.13.tgz", "integrity": "sha512-wd+MVEZCHt23V0/L642O5APvspWply/rGY5BcW4SUETo2UzPU3Z26qr8jC2qxpimI2jjx9h7+2cj2FwIr01bXg==", "dev": true, + "license": "MIT", "dependencies": { "expect": "^29.0.0", "pretty-format": "^29.0.0" @@ -2397,6 +2399,16 @@ "@types/react": "*" } }, + "node_modules/@types/react-test-renderer": { + "version": "18.3.0", + "resolved": "https://registry.npmjs.org/@types/react-test-renderer/-/react-test-renderer-18.3.0.tgz", + "integrity": "sha512-HW4MuEYxfDbOHQsVlY/XtOvNHftCVEPhJF2pQXXwcUiUF+Oyb0usgp48HSgpK5rt8m9KZb22yqOeZm+rrVG8gw==", + "dev": true, + "license": "MIT", + "dependencies": { + "@types/react": "*" + } + }, "node_modules/@types/semver": { "version": "7.5.0", "dev": true, @@ -2423,6 +2435,16 @@ "dev": true, "license": "MIT" }, + "node_modules/@types/testing-library__react-hooks": { + "version": "3.4.1", + "resolved": "https://registry.npmjs.org/@types/testing-library__react-hooks/-/testing-library__react-hooks-3.4.1.tgz", + "integrity": "sha512-G4JdzEcq61fUyV6wVW9ebHWEiLK2iQvaBuCHHn9eMSbZzVh4Z4wHnUGIvQOYCCYeu5DnUtFyNYuAAgbSaO/43Q==", + "dev": true, + "license": "MIT", + "dependencies": { + "@types/react-test-renderer": "*" + } + }, "node_modules/@types/tough-cookie": { "version": "4.0.5", "resolved": "https://registry.npmjs.org/@types/tough-cookie/-/tough-cookie-4.0.5.tgz", @@ -2491,6 +2513,8 @@ }, "node_modules/@typescript-eslint/parser": { "version": "5.62.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/parser/-/parser-5.62.0.tgz", + "integrity": "sha512-VlJEV0fOQ7BExOsHYAGrgbEiZoi8D+Bl2+f6V2RrXerRSylnp+ZBHmPvaIa8cz0Ajx7WO7Z5RqfgYg7ED1nRhA==", "dev": true, "license": "BSD-2-Clause", "peer": true, diff --git a/package.json b/package.json index 0b3adb76..bb1b130f 100644 --- a/package.json +++ b/package.json @@ -50,7 +50,7 @@ "react-dom": ">=16.14.0 <20.0.0 || ^19.0.0-0" }, "devDependencies": { - "@testing-library/jest-dom": "^6.5.0", + "@testing-library/jest-dom": "^6.6.2", "@testing-library/react": "^16.0.1", "@types/dom-speech-recognition": "^0.0.4", "@types/jest": "^29.5.13",