Skip to content

Commit 6aeeef3

Browse files
[Bugfix:Forum] Separate and fix inconsistent forum test (Submitty#11441)
### What is the current behavior? <!-- List issue if it fixes/closes/implements one using the "Fixes #<number>" or "Closes #<number>" syntax --> Mentioned in Submitty#11407 by @IDzyre This is 2/2 of fixing the forums test. The following needs to be merged first: - [x] Submitty#11442 ### What is the new behavior? Moves the upduck to the new file, and in addition, uses the current threads to test upducks. Refactor it to not use wait statements. Will fix the inconsistency of the forum thread merge and deletion. ### Other information? <!-- Is this a breaking change? --> <!-- How did you test -->
1 parent e4db354 commit 6aeeef3

File tree

4 files changed

+183
-112
lines changed

4 files changed

+183
-112
lines changed

site/app/templates/forum/ForumBar.twig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@
7777
{% if user_group <= more.required_rank %}
7878
{% set onclick = (more.onclick[0]) ? 'onclick=' ~ more.onclick[1] %}
7979
{% set optional_class = (more.optional_class[0]) ? 'class=' ~ more.optional_class[1] %}
80-
<a id="{{ more.id }}" class="dropdown-item" title="{{ more.title }}" {{ optional_class }} href="{{ more.link }}" {{ onclick }}>{{ more.display_text }}</a>
80+
<a id="{{ more.id }}" data-testid="{{ more.id }}" class="dropdown-item" title="{{ more.title }}" {{ optional_class }} href="{{ more.link }}" {{ onclick }}>{{ more.display_text }}</a>
8181
{% endif %}
8282
{% endfor %}
8383
{% if core.getUser().accessGrading() %}

site/app/templates/forum/ThreadPostForm.twig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
<div style="margin-bottom:10px;" class="form-group row position-relative">
2020
<input type="hidden" name="markdown_status" id="markdown_input_{{ post_box_id }}" value="{{ render_markdown is defined and render_markdown ? 1 : 0 }}" />
2121
{% if show_merge_thread_button is defined and show_merge_thread_button and core.getUser().accessGrading() %}
22-
<a class="btn btn-primary key_to_click" tabindex = "0" id="merge-thread-btn" title="Merge Thread Into Another Thread" onclick="$('#merge-threads').css('display', 'block'); captureTabInModal('merge-threads');">Merge Threads</a>
22+
<a class="btn btn-primary key_to_click" tabindex = "0" id="merge-thread-btn" title="Merge Thread Into Another Thread" data-testid="merge-thread" onclick="$('#merge-threads').css('display', 'block'); captureTabInModal('merge-threads');">Merge Threads</a>
2323
{% endif %}
2424
{% if show_lock_date is defined and show_lock_date and core.getUser().getGroup() <= 2 %}
2525
<label id="label_lock_thread" for="lock_thread_date"> Lock Thread Date

site/cypress/e2e/Cypress-Feature/forums.spec.js

Lines changed: 11 additions & 110 deletions
Original file line numberDiff line numberDiff line change
@@ -30,48 +30,28 @@ const replyToThread = (title, reply) => {
3030
cy.get('#posts_list').should('contain', reply);
3131
};
3232

33-
const upduckPost = (thread_title) => {
34-
cy.get('[data-testid="thread-list-item"]').contains(thread_title).click();
35-
cy.get('[data-testid="create-post-head"]').should('contain', thread_title);
36-
cy.get('[data-testid="like-count"]').first().should('have.text', 0);
37-
cy.get('[data-testid="upduck-button"]').first().click();
38-
// eslint-disable-next-line cypress/no-unnecessary-waiting
39-
cy.wait(1000);
40-
cy.get('[data-testid="like-count"]', { timeout: 10000 }).first().should('have.text', 1);
41-
};
42-
43-
const upduckReply = (thread_title) => {
44-
// Upduck the first reply
45-
cy.get('[data-testid="thread-list-item"]').contains(thread_title).click();
46-
cy.get('[data-testid="create-post-head"]').should('contain', thread_title);
47-
cy.get('[data-testid="upduck-button"]').eq(1).click();
48-
// eslint-disable-next-line cypress/no-unnecessary-waiting
49-
cy.wait(1000);
50-
};
51-
52-
const checkStatsUpducks = (fullName, numUpducks) => {
53-
// Check the stats page for a user with fullName and
54-
// number of upducks numUpducks
55-
cy.get('[data-testid="more-dropdown"]').click();
56-
cy.get('#forum_stats').click();
57-
cy.get('[data-testid="user-stat"]').contains(fullName).siblings('[data-testid="upduck-stat"]').should('contain.text', numUpducks);
58-
cy.get('[title="Back to threads"]').click();
59-
};
60-
6133
const mergeThreads = (fromThread, toThread, mergedContent) => {
6234
// Add more to tests for uploading attachments
6335
cy.get('[data-testid="thread-list-item"]').contains(fromThread).click();
36+
// eslint-disable-next-line cypress/no-unnecessary-waiting
37+
cy.wait(1000);
6438
cy.get('[title="Merge Thread Into Another Thread"]').click();
39+
// eslint-disable-next-line cypress/no-unnecessary-waiting
40+
cy.wait(1000);
6541
cy.get('.chosen-single > span').click();
66-
cy.get('.active-result').contains(toThread).click({ force: true });
67-
cy.get('[value="Merge Thread"]').click({ force: true });
42+
// eslint-disable-next-line cypress/no-unnecessary-waiting
43+
cy.wait(1000);
44+
cy.get('.active-result').contains(toThread).click();
45+
// eslint-disable-next-line cypress/no-unnecessary-waiting
46+
cy.wait(1000);
47+
cy.get('[value="Merge Thread"]').click();
6848
cy.get('.pre-forum > .post_content').should('contain', mergedContent);
6949
};
7050

7151
const removeThread = (title) => {
7252
cy.get('[data-testid="thread-list-item"]').contains(title).click();
7353
cy.get('[data-testid="thread-dropdown"]').first().click();
74-
cy.get('[data-testid="delete-post-button"]').first().click();
54+
cy.get('[data-testid="delete-post-button"]').first().click({ force: true });
7555
cy.get('[data-testid="thread-list-item"]').contains(title).should('not.exist');
7656
};
7757

@@ -107,53 +87,6 @@ const replyDisabled = (title, attachment) => {
10787
cy.contains('p', attachment).should('be.visible');
10888
};
10989

110-
const removeUpduckPost = (thread_title) => {
111-
cy.get('[data-testid="create-post-head"]').should('contain', thread_title);
112-
cy.get('[data-testid="like-count"]').first().should('have.text', 1);
113-
cy.get('[data-testid="upduck-button"]').first().click();
114-
// wait for duck like to update
115-
// eslint-disable-next-line cypress/no-unnecessary-waiting
116-
cy.wait(1000);
117-
cy.get('[data-testid="like-count"]', { timeout: 10000 }).first().should('have.text', 0);
118-
};
119-
120-
const staffUpduckPost = (user, thread_title) => {
121-
checkStaffUpduck(thread_title, 'be.not.visible');
122-
upduckPost(thread_title);
123-
checkStaffUpduck(thread_title, 'be.visible');
124-
125-
// Ta will upduck reply in thread 2,3 and instructor will upduck reply in thread 1, 2 and 3
126-
if (!(user === 'ta' && thread_title === title1)) {
127-
upduckReply(thread_title);
128-
}
129-
if (user !== 'instructor') {
130-
removeUpduckPost(thread_title);
131-
checkStaffUpduck(thread_title, 'be.not.visible');
132-
}
133-
};
134-
135-
const studentUpduckPost = (thread_title) => {
136-
checkStaffUpduck(thread_title, 'be.not.visible');
137-
upduckPost(thread_title);
138-
checkStaffUpduck(thread_title, 'be.not.visible');
139-
removeUpduckPost(thread_title);
140-
// upduck reply, do not remove yet, for checking thread sum duck purpose
141-
if (thread_title === title3) {
142-
upduckReply(thread_title);
143-
}
144-
};
145-
146-
const checkStaffUpduck = (title, visible) => {
147-
cy.get('[data-testid="thread-list-item"]').contains(title).click();
148-
cy.get('[data-testid="create-post-head"]').should('contain', title);
149-
cy.get('[data-testid="instructor-like"]').first().should(visible);
150-
};
151-
152-
const checkThreadduck = (order, ducks) => {
153-
// thread 1 suppose to have 2 total duck, thread 2 suppose to have 3 total ducks, thread 3 suppose to have 4 total ducks
154-
cy.get('.thread_box').eq(order).find('[data-testid="thread-like-count"]').should('have.text', ducks);
155-
};
156-
15790
describe('Should test creating, replying, merging, removing, and upducks in forum', () => {
15891
beforeEach(() => {
15992
cy.login('instructor');
@@ -178,38 +111,6 @@ describe('Should test creating, replying, merging, removing, and upducks in foru
178111
replyToThread(title2, reply2);
179112
replyToThread(title3, reply3);
180113

181-
// Student upduck
182-
cy.logout();
183-
cy.login('student');
184-
cy.visit(['sample', 'forum']);
185-
studentUpduckPost(title1);
186-
studentUpduckPost(title2);
187-
studentUpduckPost(title3);
188-
189-
// TA upduck
190-
cy.logout();
191-
cy.login('ta');
192-
cy.visit(['sample', 'forum']);
193-
staffUpduckPost('ta', title1);
194-
staffUpduckPost('ta', title2);
195-
staffUpduckPost('ta', title3);
196-
197-
// Instructor upduck and check the stats page for instructor with 3 upducks
198-
cy.logout();
199-
cy.login('instructor');
200-
cy.visit(['sample', 'forum']);
201-
staffUpduckPost('instructor', title1);
202-
staffUpduckPost('instructor', title2);
203-
staffUpduckPost('instructor', title3);
204-
205-
// Check thread sum duck
206-
cy.visit(['sample', 'forum']);
207-
checkThreadduck(2, 2);
208-
checkThreadduck(1, 3);
209-
checkThreadduck(0, 4);
210-
211-
checkStatsUpducks('Instructor, Quinn', 6);
212-
213114
// Tutorial into Questions
214115
mergeThreads(title3, title2, merged1);
215116

Lines changed: 170 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,170 @@
1+
import { buildUrl } from '../../support/utils';
2+
3+
const title1 = 'Attachment contains secret';
4+
const title2 = 'Different Levels& display order';
5+
const title3 = 'Simple C++ threading example';
6+
7+
const upduckPost = (thread_title, thread_number = 0, num_ducks = 0) => {
8+
cy.get('[data-testid="thread-list-item"]').contains(thread_title).click();
9+
cy.get('[data-testid="create-post-head"]').should('contain', thread_title);
10+
cy.get('[data-testid="like-count"]').eq(thread_number).should('have.text', num_ducks);
11+
cy.get('[data-testid="upduck-button"]').eq(thread_number).click();
12+
cy.wait('@upduck', { responseTimeout: 15000 });
13+
cy.get('[data-testid="like-count"]').eq(thread_number).should('have.text', num_ducks + 1);
14+
};
15+
16+
const removeUpduck = (thread_title, thread_number = 0, num_ducks = 1) => {
17+
cy.get('[data-testid="thread-list-item"]').contains(thread_title).click();
18+
cy.get('[data-testid="create-post-head"]').should('contain', thread_title);
19+
cy.get('[data-testid="like-count"]').eq(thread_number).should('have.text', num_ducks);
20+
cy.get('[data-testid="upduck-button"]').eq(thread_number).click();
21+
cy.wait('@upduck', { responseTimeout: 15000 });
22+
cy.get('[data-testid="like-count"]').eq(thread_number).should('have.text', num_ducks - 1);
23+
};
24+
25+
const checkStaffUpduck = (title, visible, thread_number = 0) => {
26+
cy.get('[data-testid="thread-list-item"]').contains(title).click();
27+
cy.get('[data-testid="create-post-head"]').should('contain', title);
28+
cy.get('[data-testid="instructor-like"]').eq(thread_number).should(visible);
29+
};
30+
31+
const checkThreadduck = (title, ducks) => {
32+
cy.get('[data-testid="thread-list-item"]').contains(title).parents('[data-testid="thread_box"]').find('[data-testid="thread-like-count"]').should('have.text', ducks);
33+
};
34+
35+
const checkStatsUpducks = (fullName, numUpducks) => {
36+
// Check the stats page for a user with fullName and
37+
// number of upducks numUpducks
38+
cy.get('[data-testid="more-dropdown"]').click();
39+
cy.get('[data-testid="forum_stats"]').click();
40+
cy.get('[data-testid="user-stat"]').contains(fullName).siblings('[data-testid="upduck-stat"]').should('contain.text', numUpducks);
41+
cy.get('[title="Back to threads"]').click();
42+
};
43+
44+
const staffUpduckPost = (user, thread_title) => {
45+
checkStaffUpduck(thread_title, 'be.not.visible');
46+
upduckPost(thread_title);
47+
checkStaffUpduck(thread_title, 'be.visible');
48+
49+
if (user === 'instructor') {
50+
// upduck reply
51+
const reply = 1;
52+
if (thread_title === title1) {
53+
checkStaffUpduck(thread_title, 'be.not.visible', reply);
54+
upduckPost(thread_title, reply, 0);
55+
checkStaffUpduck(thread_title, 'be.visible', reply);
56+
}
57+
else if (thread_title === title2) {
58+
checkStaffUpduck(thread_title, 'be.visible', reply);
59+
upduckPost(thread_title, reply, 1);
60+
checkStaffUpduck(thread_title, 'be.visible', reply);
61+
}
62+
else {
63+
checkStaffUpduck(thread_title, 'be.visible', reply);
64+
upduckPost(thread_title, reply, 2);
65+
checkStaffUpduck(thread_title, 'be.visible', reply);
66+
}
67+
}
68+
// TA has different numbers than instructors
69+
else if (user === 'ta') {
70+
const reply = 1;
71+
// upduck 2nd and 3rd post's reply, student already upducked the 3rd post's reply
72+
if (thread_title === title2) {
73+
upduckPost(thread_title, reply, 0);
74+
checkStaffUpduck(thread_title, 'be.visible', reply);
75+
}
76+
else if (thread_title === title3) {
77+
upduckPost(thread_title, reply, 1);
78+
checkStaffUpduck(thread_title, 'be.visible', reply);
79+
}
80+
// remove upduck from parent post and make sure staff upduck is not visible
81+
removeUpduck(thread_title);
82+
checkStaffUpduck(thread_title, 'be.not.visible');
83+
}
84+
};
85+
86+
const studentUpduckPost = (thread_title) => {
87+
checkStaffUpduck(thread_title, 'be.not.visible');
88+
upduckPost(thread_title);
89+
checkStaffUpduck(thread_title, 'be.not.visible');
90+
removeUpduck(thread_title);
91+
// upduck reply, do not remove yet, for checking thread sum duck purpose
92+
if (thread_title === title3) {
93+
upduckPost(thread_title, 1, 0);
94+
}
95+
};
96+
97+
describe('Should test upducks relating to students, TAs, and instructors', () => {
98+
beforeEach(() => {
99+
cy.intercept('POST', buildUrl(['sample', 'posts', 'likes'])).as('upduck');
100+
});
101+
102+
it('Upducking and checking upducks', () => {
103+
// Student upduck. After the student is done, post #3's first reply has 1 upduck
104+
cy.login('student');
105+
cy.visit(['sample', 'forum']);
106+
studentUpduckPost(title1);
107+
studentUpduckPost(title2);
108+
studentUpduckPost(title3);
109+
110+
// TA upduck
111+
cy.logout();
112+
cy.login('ta');
113+
cy.visit(['sample', 'forum']);
114+
staffUpduckPost('ta', title1);
115+
staffUpduckPost('ta', title2);
116+
staffUpduckPost('ta', title3);
117+
118+
// Instructor upduck and check the stats page for instructor with 3 upducks
119+
cy.logout();
120+
cy.login('instructor');
121+
cy.visit(['sample', 'forum']);
122+
staffUpduckPost('instructor', title1);
123+
staffUpduckPost('instructor', title2);
124+
staffUpduckPost('instructor', title3);
125+
126+
// Check thread sum duck
127+
// thread 1 suppose to have 2 duck, thread 2 suppose to have 3 total ducks, thread 3 suppose to have 4 total ducks
128+
cy.visit(['sample', 'forum']);
129+
checkThreadduck(title1, 2);
130+
checkThreadduck(title2, 3);
131+
checkThreadduck(title3, 4);
132+
133+
checkStatsUpducks('Instructor, Quinn', 6);
134+
checkStatsUpducks('TA, Jill', 2);
135+
checkStatsUpducks('Student, Joe', 1);
136+
});
137+
138+
it('Delete all remaining upducks', () => {
139+
// instructor has 6, ta has 2, student has 1
140+
const post = 0, reply = 1;
141+
cy.login('student');
142+
cy.visit(['sample', 'forum']);
143+
removeUpduck(title3, reply, 3);
144+
145+
cy.logout();
146+
cy.login('ta');
147+
cy.visit(['sample', 'forum']);
148+
removeUpduck(title2, reply, 2);
149+
removeUpduck(title3, reply, 2);
150+
151+
cy.logout();
152+
cy.login('instructor');
153+
cy.visit(['sample', 'forum']);
154+
removeUpduck(title1, post, 1);
155+
removeUpduck(title1, reply, 1);
156+
removeUpduck(title2, post, 1);
157+
removeUpduck(title2, reply, 1);
158+
removeUpduck(title3, post, 1);
159+
removeUpduck(title3, reply, 1);
160+
161+
cy.visit(['sample', 'forum']);
162+
checkThreadduck(title1, 0);
163+
checkThreadduck(title2, 0);
164+
checkThreadduck(title3, 0);
165+
166+
checkStatsUpducks('Instructor, Quinn', 0);
167+
checkStatsUpducks('TA, Jill', 0);
168+
checkStatsUpducks('Student, Joe', 0);
169+
});
170+
});

0 commit comments

Comments
 (0)