Skip to content
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 jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ module.exports = {
'^.+\\.[jt]sx?$': 'babel-jest',
},
moduleNameMapper: {
'\\.svg(\\?react)?$': '<rootDir>/test/__mocks__/svgrMock.js',
'^@/(.*)$': '<rootDir>/src/$1',
'\\.(css|scss|sass)$': 'identity-obj-proxy',
'\\.(png|jpg|jpeg|gif|webp)$': '<rootDir>/test/__mocks__/fileMock.js',
'\\.svg(\\?react)?$': '<rootDir>/test/__mocks__/svgrMock.js',
'^marked$': '<rootDir>/test/__mocks__/marked.js',
'^@weni/webchat-service$': '<rootDir>/test/__mocks__/@weni/webchat-service.js',
'^react-i18next$': '<rootDir>/test/__mocks__/react-i18next.js',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,15 +88,15 @@ describe('ConversationStarterButton', () => {
).toBeInTheDocument();
});

it('renders using Button component with weni-button class', () => {
it('renders using FSButton component with weni-fs-button class', () => {
const { container } = render(
<ConversationStarterButton
question="Test question"
onClick={jest.fn()}
/>,
);

const button = container.querySelector('.weni-button');
const button = container.querySelector('.weni-fs-button');
expect(button).toBeInTheDocument();
});
});
Expand Down
8 changes: 5 additions & 3 deletions src/components/Product/InlineProduct.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,11 @@ export function InlineProduct({
: null;

const productURLObject = useMemo(() => {
return URL.canParse(productURL)
? new URL(productURL)
: { origin: '', pathname: '' };
try {
return new URL(productURL);
} catch {
return { origin: '', pathname: '' };
}
}, [productURL]);

const canUserNavigateToProductPage = useMemo(() => {
Expand Down
1 change: 1 addition & 0 deletions src/views/Cart.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ function setupMockContext(cartItems = {}) {
setCart: mockSetCart,
clearPageHistory: mockClearPageHistory,
sendOrder: mockSendOrder,
config: { addToCart: false },
});
}

Expand Down
9 changes: 0 additions & 9 deletions test/components/VoiceMode/VoiceModeButton.test.jsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,6 @@
import { render, screen } from "@testing-library/react";
import userEvent from "@testing-library/user-event";

const SvgStub = (props) => <svg {...props} />;
jest.mock("@/utils/icons", () => ({
icons: new Proxy(
{},
{
get: () => ({ default: SvgStub, filled: SvgStub }),
},
),
}));

import { VoiceModeButton } from "@/components/VoiceMode/VoiceModeButton";

Expand Down
9 changes: 0 additions & 9 deletions test/components/VoiceMode/VoiceModeError.test.jsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,6 @@
import { render, screen } from "@testing-library/react";
import userEvent from "@testing-library/user-event";

const SvgStub = (props) => <svg {...props} />;
jest.mock("@/utils/icons", () => ({
icons: new Proxy(
{},
{
get: () => ({ default: SvgStub, filled: SvgStub }),
},
),
}));

import { VoiceModeError } from "@/components/VoiceMode/VoiceModeError";

Expand Down
19 changes: 5 additions & 14 deletions test/services/voice/AudioCapture.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,9 @@ describe("AudioCapture", () => {

// -- requestPermission ----------------------------------------------------

describe("requestPermission()", () => {
describe("requestPermission() (static)", () => {
it("returns true when getUserMedia succeeds", async () => {
const result = await capture.requestPermission();
const result = await AudioCapture.requestPermission();
expect(result).toBe(true);
const stream =
await navigator.mediaDevices.getUserMedia.mock.results[0].value;
Expand All @@ -136,34 +136,25 @@ describe("AudioCapture", () => {
navigator.mediaDevices.getUserMedia.mockRejectedValueOnce(
new DOMException("denied", "NotAllowedError"),
);
const result = await capture.requestPermission();
const result = await AudioCapture.requestPermission();
expect(result).toBe(false);
});
});

describe("requestPermission() (static)", () => {
it("matches instance requestPermission() success", async () => {
const staticResult = await AudioCapture.requestPermission();
const instanceResult = await capture.requestPermission();
expect(staticResult).toBe(true);
expect(instanceResult).toBe(true);
});
});

// -- checkPermission ------------------------------------------------------

describe("checkPermission()", () => {
it("returns the permission state string", async () => {
navigator.permissions.query.mockResolvedValueOnce({ state: "denied" });
const result = await capture.checkPermission();
const result = await AudioCapture.checkPermission();
expect(result).toBe("denied");
});

it('returns "prompt" when permissions API throws', async () => {
navigator.permissions.query.mockRejectedValueOnce(
new Error("unsupported"),
);
const result = await capture.checkPermission();
const result = await AudioCapture.checkPermission();
expect(result).toBe("prompt");
});
});
Expand Down
Loading