-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchatgippity_tests.js
120 lines (93 loc) · 3.87 KB
/
chatgippity_tests.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
// tests/unit-tests.js
describe('Firefox Extension', function() {
describe('Logging', function() {
it('should log the current site if enabled', function() {
// Mock the extension settings to be enabled
const settings = { loggingEnabled: true };
// Mock the current tab
const tab = { url: 'https://example.com' };
// Mock the function that logs the site
const logSite = jest.fn();
// Call the function that logs the site
require('../background-script.js').logCurrentSite(settings, tab, logSite);
// Expect the logSite function to have been called with the current tab's URL
expect(logSite).toHaveBeenCalledWith('https://example.com');
});
it('should not log the current site if disabled', function() {
// Mock the extension settings to be disabled
const settings = { loggingEnabled: false };
// Mock the current tab
const tab = { url: 'https://example.com' };
// Mock the function that logs the site
const logSite = jest.fn();
// Call the function that logs the site
require('../background-script.js').logCurrentSite(settings, tab, logSite);
// Expect the logSite function to not have been called
expect(logSite).not.toHaveBeenCalled();
});
});
describe('Data Pushing', function() {
it('should push data about the site to the main application', function() {
// Mock the site data
const siteData = { url: 'https://example.com', title: 'Example' };
// Mock the function that pushes data to the main application
const pushData = jest.fn();
// Call the function that pushes data to the main application
require('../background-script.js').pushSiteData(siteData, pushData);
// Expect the pushData function to have been called with the site data
expect(pushData).toHaveBeenCalledWith(siteData);
});
});
describe('Comment Sending', function() {
it('should send comments made to the database entry of the main application', function() {
// Mock the comment
const comment = 'This is a comment';
// Mock the function that sends comments to the main application
const sendComment = jest.fn();
// Call the function that sends comments to the main application
require('../background-script.js').sendComment(comment, sendComment);
// Expect the sendComment function to have been called with the comment
expect(sendComment).toHaveBeenCalledWith(comment);
});
});
describe('Link Extraction', function() {
it('should extract links from the page', function() {
// Mock the page content
const pageContent = `
<html>
<body>
<a href="https://example.com/link1">Link 1</a>
<a href="https://example.com/link2">Link 2</a>
</body>
</html>
`;
// Mock the function that extracts links from the page
const extractLinks = jest.fn(() => [
'https://example.com/link1',
'https://example.com/link2',
]);
// Call the function that extracts links from the page
const links = require('../background-script.js').extractLinks(pageContent, extractLinks);
// Expect the extractLinks function to have been called with the page content
expect(extractLinks).toHaveBeenCalledWith(pageContent);
// Expect the links to have been extracted correctly
expect(links).toEqual([
'https://example.com/link1',
'https://example.com/link2',
]);
});
it('should send the list of links to the main application', function() {
// Mock the list of links
const links = [
'https://example.com/link1',
'https://example.com/link2',
];
// Mock the function that sends the list of links to the main application
const sendLinks = jest.fn();
// Call the function that sends the list of links to the main application
require('../background-script.js').sendLinks(links, sendLinks);
// Expect the sendLinks function to have been called with the list of links
expect(sendLinks).toHaveBeenCalledWith(links);
});
});
});