| 
 | 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