Skip to content

Commit b68987a

Browse files
Ishan VeerIshan Veer
authored andcommitted
Added tests and feature flag
1 parent d52882f commit b68987a

File tree

5 files changed

+1191
-1
lines changed

5 files changed

+1191
-1
lines changed

__tests__/users/App.test.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
const puppeteer = require('puppeteer');
22
const { filteredUsersData } = require('../../mock-data/users');
33
const { mockUserData } = require('../../mock-data/users/mockdata');
4+
const { getUsers } = require('../../users/discord/utils/util');
5+
const { paginateFetchedUsers } = require('../../users/discord/App');
46
const API_BASE_URL = 'https://staging-api.realdevsquad.com';
57

68
describe('App Component', () => {
@@ -89,4 +91,26 @@ describe('App Component', () => {
8991
const url = await page.url();
9092
expect(url).toContain('?tab=verified');
9193
});
94+
it('should fetch and append new users on subsequent pages for both tabs', async () => {
95+
// Mock the getUsers function to return full set of user data.
96+
jest.spyOn(global, getUsers).mockResolveValue([mockUserData]);
97+
98+
// test in_discord tab
99+
await paginateFetchedUsers('in_discord', 1);
100+
expect(usersData['in_discord'].length).toBe(10);
101+
expect(currentPage).toBe(1);
102+
103+
await paginateFetchedUsers('in_discord', 2);
104+
expect(usersData['in_discord'].length).toBe(20);
105+
expect(currentPage).toBe(2);
106+
107+
// test verified tab
108+
await paginateFetchedUsers('verified', 1);
109+
expect(usersData['verified'].length).toBe(10);
110+
expect(currentPage).toBe(1);
111+
112+
await paginateFetchedUsers('verified', 2);
113+
expect(usersData['verified'].length).toBe(20);
114+
expect(currentPage).toBe(2);
115+
});
92116
});

babel.config.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
const plugins = ['istanbul'];
22

33
module.exports = {
4+
presets: [
5+
[
6+
'@babel/preset-env',
7+
{
8+
targets: {
9+
node: 'current',
10+
},
11+
},
12+
],
13+
],
414
plugins: plugins,
515
};

jest.config.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,16 @@
11
const config = {
22
preset: 'jest-puppeteer',
3+
transform: {
4+
'^.+\\.jsx?$': 'babel-jest', // Add transform for ES Modules
5+
},
6+
transformIgnorePatterns: [
7+
'node_modules/(?!(module-that-needs-transpiling)/)',
8+
],
39
collectCoverage: true,
410
collectCoverageFrom: ['src/**/*'],
511
reporters: ['default'],
612
coverageDirectory: 'coverage',
13+
moduleFileExtensions: ['js', 'jsx', 'json', 'node'],
14+
testEnvironment: 'node',
715
};
816
module.exports = config;

package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@
2323
"pre-commit": "check",
2424
"homepage": "https://github.com/Real-Dev-Squad/website-dashboard#readme",
2525
"devDependencies": {
26+
"@babel/core": "^7.26.0",
27+
"@babel/preset-env": "^7.26.0",
28+
"babel-jest": "^29.7.0",
2629
"jest": "^29.5.0",
2730
"jest-puppeteer": "^8.0.6",
2831
"jest-puppeteer-istanbul": "^0.5.3",

0 commit comments

Comments
 (0)