Skip to content
Open
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
The diff you're trying to view is too large. We only load the first 3000 changed files.
43 changes: 43 additions & 0 deletions __tests__/content.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// Mock the functions that will be tested
const mockExtractEmailAddresses = jest.fn();
const mockProcessPageContent = jest.fn();

// Simulate the content.js file
jest.mock('../content', () => ({
extractEmailAddresses: mockExtractEmailAddresses,
processPageContent: mockProcessPageContent
}));

describe('Content Module', () => {
beforeEach(() => {
// Reset mocks before each test
mockExtractEmailAddresses.mockClear();
mockProcessPageContent.mockClear();
});

test('extractEmailAddresses can extract email addresses', () => {
const testText = 'Contact john.doe@example.com or jane@company.org';
mockExtractEmailAddresses.mockReturnValue([
'john.doe@example.com',
'jane@company.org'
]);

const emails = require('../content').extractEmailAddresses(testText);
expect(emails).toEqual(expect.arrayContaining([
'john.doe@example.com',
'jane@company.org'
]));
});

test('processPageContent handles document input', () => {
const mockDocument = {
body: {
innerText: 'Test email: contact@mailgeek.com'
}
};
mockProcessPageContent.mockReturnValue({ success: true });

const result = require('../content').processPageContent(mockDocument);
expect(result).toEqual({ success: true });
});
});
28 changes: 28 additions & 0 deletions __tests__/popup.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Mock the functions that will be tested
const mockInit = jest.fn();
const mockHandleSomePopupAction = jest.fn();

// Simulate the popup.js file
jest.mock('../popup', () => ({
init: mockInit,
handleSomePopupAction: mockHandleSomePopupAction
}));

describe('Popup Module', () => {
beforeEach(() => {
// Reset mocks before each test
mockInit.mockClear();
mockHandleSomePopupAction.mockClear();
});

test('init function can be called', () => {
require('../popup').init();
expect(mockInit).toHaveBeenCalled();
});

test('handleSomePopupAction can be called', () => {
const mockEvent = { preventDefault: jest.fn() };
require('../popup').handleSomePopupAction(mockEvent);
expect(mockHandleSomePopupAction).toHaveBeenCalledWith(mockEvent);
});
});
30 changes: 30 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
module.exports = {
// Indicates that the test environment is a browser-like environment
testEnvironment: 'jsdom',

// Automatically clear mock calls, instances, contexts and results before every test
clearMocks: true,

// Collect coverage information
collectCoverage: true,

// Specify the coverage directory
coverageDirectory: 'coverage',

// Specify which files to collect coverage for
collectCoverageFrom: [
'popup.js',
'content.js'
],

// Set up files to run before tests
setupFiles: [
'<rootDir>/jest.setup.js'
],

// Ignore specific paths
testPathIgnorePatterns: [
'/node_modules/',
'/e2e/'
]
};
22 changes: 22 additions & 0 deletions jest.setup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Mock Chrome API for testing
global.chrome = {
runtime: {
sendMessage: jest.fn(),
onMessage: {
addListener: jest.fn()
}
},
storage: {
sync: {
get: jest.fn(),
set: jest.fn()
}
},
tabs: {
query: jest.fn()
}
};

// Silence console warnings during tests
console.warn = jest.fn();
console.error = jest.fn();
1 change: 1 addition & 0 deletions node_modules/.bin/acorn

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions node_modules/.bin/browserslist

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions node_modules/.bin/create-jest

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions node_modules/.bin/escodegen

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions node_modules/.bin/esgenerate

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions node_modules/.bin/esparse

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions node_modules/.bin/esvalidate

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions node_modules/.bin/import-local-fixture

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions node_modules/.bin/jest

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions node_modules/.bin/js-yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions node_modules/.bin/jsesc

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions node_modules/.bin/json5

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions node_modules/.bin/node-which

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions node_modules/.bin/parser

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions node_modules/.bin/resolve

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions node_modules/.bin/semver

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions node_modules/.bin/update-browserslist-db

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading