Skip to content

Commit cf01917

Browse files
authored
Fix/remove outdated fields (#914)
* featureUrl removed * removed feature/group * change class inputBox instead radioButton * task level section removed * unncessary object destruction under featureflag removed * status=available typo fixed * tests added for updated changes * Tests fixed * Added data-testid for testing,also added new tests * Test api updated to staging * refactored for readability * created a constants file * API_BASE_URL changed to stating for testing
1 parent 2f2d354 commit cf01917

File tree

4 files changed

+259
-125
lines changed

4 files changed

+259
-125
lines changed

__tests__/tasks/task-dependency.test.js

Lines changed: 146 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -16,79 +16,161 @@ describe('Input box', () => {
1616
args: ['--incognito', '--disable-web-security'],
1717
devtools: false,
1818
});
19-
page = await browser.newPage();
2019

21-
await page.setRequestInterception(true);
22-
23-
page.on('request', (interceptedRequest) => {
24-
const url = interceptedRequest.url();
25-
if (url === `${STAGING_API_URL}/levels`) {
26-
interceptedRequest.respond({
27-
status: 200,
28-
contentType: 'application/json',
29-
headers: {
30-
'Access-Control-Allow-Origin': '*',
31-
'Access-Control-Allow-Methods': 'GET, POST, PUT, DELETE, OPTIONS',
32-
'Access-Control-Allow-Headers': 'Content-Type, Authorization',
33-
},
34-
body: JSON.stringify(levels),
35-
});
36-
} else if (url === `${STAGING_API_URL}/users`) {
37-
interceptedRequest.respond({
38-
status: 200,
39-
contentType: 'application/json',
40-
headers: {
41-
'Access-Control-Allow-Origin': '*',
42-
'Access-Control-Allow-Methods': 'GET, POST, PUT, DELETE, OPTIONS',
43-
'Access-Control-Allow-Headers': 'Content-Type, Authorization',
44-
},
45-
body: JSON.stringify(users),
46-
});
47-
} else if (url === `${STAGING_API_URL}/tags`) {
48-
interceptedRequest.respond({
49-
status: 200,
50-
contentType: 'application/json',
51-
headers: {
52-
'Access-Control-Allow-Origin': '*',
53-
'Access-Control-Allow-Methods': 'GET, POST, PUT, DELETE, OPTIONS',
54-
'Access-Control-Allow-Headers': 'Content-Type, Authorization',
55-
},
56-
body: JSON.stringify(tags),
57-
});
58-
} else {
59-
interceptedRequest.continue();
60-
}
61-
});
20+
// Mock API response setup
21+
const interceptAPI = async (page) => {
22+
await page.setRequestInterception(true);
23+
page.on('request', (interceptedRequest) => {
24+
const url = interceptedRequest.url();
25+
26+
const mockResponses = {
27+
[`${STAGING_API_URL}/levels`]: levels,
28+
[`${STAGING_API_URL}/users`]: users,
29+
[`${STAGING_API_URL}/tags`]: tags,
30+
};
31+
32+
if (mockResponses[url]) {
33+
interceptedRequest.respond({
34+
status: 200,
35+
contentType: 'application/json',
36+
headers: {
37+
'Access-Control-Allow-Origin': '*',
38+
},
39+
body: JSON.stringify(mockResponses[url]),
40+
});
41+
} else {
42+
interceptedRequest.continue();
43+
}
44+
});
45+
};
46+
47+
// Open a shared page instance and intercept API for all tests
48+
page = await browser.newPage();
49+
await interceptAPI(page);
6250
await page.goto('http://localhost:8000/task');
6351
await page.waitForNetworkIdle();
6452
});
6553

6654
afterAll(async () => {
6755
await browser.close();
6856
});
69-
it('DependsOn input box should exist', async () => {
70-
const inputBox = await page.evaluate(() =>
71-
document.querySelector('.inputBox'),
72-
);
73-
const linksDisplay = await page.evaluate(() =>
74-
document.querySelector('#linksDisplay'),
75-
);
57+
58+
// Form Presence Tests
59+
describe('Form Field Presence', () => {
60+
it('should display the title field', async () => {
61+
const titleField = await page.$('[data-testid="title"]');
62+
expect(titleField).toBeTruthy();
63+
});
64+
65+
it('should display the status field', async () => {
66+
const statusField = await page.$('[data-testid="status"]');
67+
expect(statusField).toBeTruthy();
68+
});
69+
70+
it('should display the priority field', async () => {
71+
const priorityField = await page.$('[data-testid="priority"]');
72+
expect(priorityField).toBeTruthy();
73+
});
74+
75+
it('should display the isNoteworthy checkbox', async () => {
76+
const noteworthyField = await page.$('[data-testid="isNoteworthy"]');
77+
expect(noteworthyField).toBeTruthy();
78+
});
79+
80+
it('should display the purpose field', async () => {
81+
const purposeField = await page.$('[data-testid="purpose"]');
82+
expect(purposeField).toBeTruthy();
83+
});
84+
85+
it('should display the dependsOn field', async () => {
86+
const dependsOnField = await page.$('[data-testid="dependsOn"]');
87+
expect(dependsOnField).toBeTruthy();
88+
});
7689
});
7790

78-
it('DependsOn input should have correct attributes', async () => {
79-
const input = await page.$('#dependsOn');
80-
const type = await input.evaluate((el) => el.getAttribute('type'));
81-
const name = await input.evaluate((el) => el.getAttribute('name'));
82-
const id = await input.evaluate((el) => el.getAttribute('id'));
83-
const placeholder = await input.evaluate((el) =>
84-
el.getAttribute('placeholder'),
85-
);
86-
const classList = await input.evaluate((el) => Array.from(el.classList));
87-
88-
expect(type).toBe('text');
89-
expect(name).toBe('dependsOn');
90-
expect(id).toBe('dependsOn');
91-
expect(placeholder).toBe('Task ID separated with comma ');
92-
expect(classList.includes('notEditing')).toBeTruthy();
91+
// Status Field Behavior Tests
92+
describe('Status Field Behavior', () => {
93+
beforeEach(async () => {
94+
await page.goto('http://localhost:8000/task');
95+
await page.waitForNetworkIdle();
96+
});
97+
98+
it('should have default status as "available"', async () => {
99+
const defaultStatus = await page.$eval(
100+
'[data-testid="status"] select',
101+
(el) => el.value,
102+
);
103+
expect(defaultStatus).toBe('AVAILABLE');
104+
});
105+
106+
it('should show/hide fields based on "status" selection', async () => {
107+
// Change status to "assigned"
108+
await page.select('[data-testid="status"] select', 'ASSIGNED');
109+
110+
const assigneeVisible = await page.$eval(
111+
'[data-testid="assignee"]',
112+
(el) => window.getComputedStyle(el).display !== 'none',
113+
);
114+
const endsOnVisible = await page.$eval(
115+
'[data-testid="endsOn"]',
116+
(el) => window.getComputedStyle(el).display !== 'none',
117+
);
118+
expect(assigneeVisible).toBeTruthy();
119+
expect(endsOnVisible).toBeTruthy();
120+
121+
// Change status back to "available"
122+
await page.select('[data-testid="status"] select', 'available');
123+
124+
const assigneeHidden = await page.$eval(
125+
'[data-testid="assignee"]',
126+
(el) => window.getComputedStyle(el).display === 'none',
127+
);
128+
const endsOnHidden = await page.$eval(
129+
'[data-testid="endsOn"]',
130+
(el) => window.getComputedStyle(el).display === 'none',
131+
);
132+
expect(assigneeHidden).toBeTruthy();
133+
expect(endsOnHidden).toBeTruthy();
134+
});
135+
});
136+
137+
// Dev Mode Tests
138+
describe('Dev Mode Behavior', () => {
139+
beforeAll(async () => {
140+
await page.goto('http://localhost:8000/task?dev=true');
141+
await page.waitForNetworkIdle();
142+
});
143+
144+
it('should hide feature URL field in dev mode', async () => {
145+
const featureUrlField = await page.$('[data-testid="featureUrl"]');
146+
const display = await page.$eval(
147+
'[data-testid="featureUrl"]',
148+
(el) => window.getComputedStyle(el).display,
149+
);
150+
expect(display).toBe('none');
151+
});
152+
153+
it('should hide task level field in dev mode', async () => {
154+
const taskLevelField = await page.$('[data-testid="taskLevel"]');
155+
const display = await page.$eval(
156+
'[data-testid="taskLevel"]',
157+
(el) => window.getComputedStyle(el).display,
158+
);
159+
expect(display).toBe('none');
160+
});
161+
162+
it('should hide feature/group radio buttons in dev mode', async () => {
163+
const radioButtons = await page.$('[data-testid="radioButtons"]');
164+
const display = await page.$eval(
165+
'[data-testid="radioButtons"]',
166+
(el) => window.getComputedStyle(el).display,
167+
);
168+
expect(display).toBe('none');
169+
});
170+
171+
it('should display the dependsOn field in dev mode', async () => {
172+
const dependsOnField = await page.$('[data-testid="dependsOn"]');
173+
expect(dependsOnField).toBeTruthy();
174+
});
93175
});
94176
});

task/constants.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
const StatusType = {
2+
AVAILABLE: 'AVAILABLE',
3+
ASSIGNED: 'ASSIGNED',
4+
};

0 commit comments

Comments
 (0)