How to use getProps method in Playwright Internal

Best JavaScript code snippet using playwright-internal

Run Playwright Internal automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

AssignmentRowCellPropFactorySpec.js

Source: AssignmentRowCellPropFactorySpec.js Github

copy
1/*
2 * Copyright (C) 2017 - present Instructure, Inc.
3 *
4 * This file is part of Canvas.
5 *
6 * Canvas is free software: you can redistribute it and/or modify it under
7 * the terms of the GNU Affero General Public License as published by the Free
8 * Software Foundation, version 3 of the License.
9 *
10 * Canvas is distributed in the hope that it will be useful, but WITHOUT ANY
11 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
12 * A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
13 * details.
14 *
15 * You should have received a copy of the GNU Affero General Public License along
16 * with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19import AssignmentRowCellPropFactory from 'jsx/gradebook/default_gradebook/GradebookGrid/editors/AssignmentCellEditor/AssignmentRowCellPropFactory'
20import {
21  createGradebook,
22  setFixtureHtml
23} from 'jsx/gradebook/default_gradebook/__tests__/GradebookSpecHelper'
24
25QUnit.module('GradebookGrid AssignmentRowCellPropFactory', () => {
26  let $container
27  let gradebook
28
29  QUnit.module('#getProps()', hooks => {
30    let editorOptions
31
32    function getProps() {
33      const factory = new AssignmentRowCellPropFactory(gradebook)
34      return factory.getProps(editorOptions)
35    }
36
37    hooks.beforeEach(() => {
38      $container = document.body.appendChild(document.createElement('div'))
39      setFixtureHtml($container)
40
41      gradebook = createGradebook({context_id: '1201'})
42      gradebook.gradebookGrid.gridSupport = {
43        helper: {
44          commitCurrentEdit() {},
45          focus() {}
46        }
47      }
48
49      gradebook.students['1101'] = {id: '1101', isConcluded: false}
50      gradebook.setAssignments({
51        2301: {grading_type: 'points', id: '2301', points_possible: 10}
52      })
53      gradebook.updateSubmission({
54        assignment_id: '2301',
55        entered_grade: '7.8',
56        entered_score: 7.8,
57        excused: false,
58        grade: '6.8',
59        id: '2501',
60        score: 6.8,
61        user_id: '1101'
62      })
63
64      editorOptions = {
65        column: {
66          assignmentId: '2301'
67        },
68        item: {id: '1101'}
69      }
70
71      sinon.stub(gradebook, 'updateRowAndRenderSubmissionTray') // no rendering needed for these tests
72    })
73
74    hooks.afterEach(() => {
75      gradebook.destroy()
76      $container.remove()
77    })
78
79    test('.assignment.id is the id on the assignment', () => {
80      equal(getProps().assignment.id, '2301')
81    })
82
83    test('.assignment.pointsPossible is the points possible on the assignment', () => {
84      strictEqual(getProps().assignment.pointsPossible, 10)
85    })
86
87    test('.enterGradesAs is the "enter grades as" setting for the assignment', () => {
88      gradebook.setEnterGradesAsSetting('2301', 'percent')
89      equal(getProps().enterGradesAs, 'percent')
90    })
91
92    test('.gradeIsEditable is true when the grade for the submission is editable', () => {
93      sinon
94        .stub(gradebook, 'isGradeEditable')
95        .withArgs('1101', '2301')
96        .returns(true)
97      strictEqual(getProps().gradeIsEditable, true)
98    })
99
100    test('.gradeIsEditable is false when the grade for the submission is not editable', () => {
101      sinon
102        .stub(gradebook, 'isGradeEditable')
103        .withArgs('1101', '2301')
104        .returns(false)
105      strictEqual(getProps().gradeIsEditable, false)
106    })
107
108    test('.gradeIsVisible is true when the grade for the submission is visible', () => {
109      sinon
110        .stub(gradebook, 'isGradeVisible')
111        .withArgs('1101', '2301')
112        .returns(true)
113      strictEqual(getProps().gradeIsVisible, true)
114    })
115
116    test('.gradeIsVisible is false when the grade for the submission is not visible', () => {
117      sinon
118        .stub(gradebook, 'isGradeVisible')
119        .withArgs('1101', '2301')
120        .returns(false)
121      strictEqual(getProps().gradeIsVisible, false)
122    })
123
124    test('.gradingScheme is the grading scheme for the assignment', () => {
125      const gradingScheme = {
126        id: '2801',
127        data: [
128          ['😂', 0.9],
129          ['🙂', 0.8],
130          ['😐', 0.7],
131          ['😢', 0.6],
132          ['💩', 0]
133        ],
134        title: 'Emoji Grades'
135      }
136      gradebook.getAssignment('2301').grading_standard_id = '2801'
137      gradebook.courseContent.gradingSchemes = [gradingScheme]
138      deepEqual(getProps().gradingScheme, gradingScheme.data)
139    })
140
141    test('.isSubmissionTrayOpen is true when the tray is open for the current student and assignment', () => {
142      gradebook.setSubmissionTrayState(true, '1101', '2301')
143      strictEqual(getProps().isSubmissionTrayOpen, true)
144    })
145
146    test('.isSubmissionTrayOpen is false when the tray is closed', () => {
147      gradebook.setSubmissionTrayState(false, '1101', '2301')
148      strictEqual(getProps().isSubmissionTrayOpen, false)
149    })
150
151    test('.isSubmissionTrayOpen is true when the tray is open for a different student', () => {
152      gradebook.setSubmissionTrayState(true, '1102', '2301')
153      strictEqual(getProps().isSubmissionTrayOpen, false)
154    })
155
156    test('.isSubmissionTrayOpen is true when the tray is open for a different assignment', () => {
157      gradebook.setSubmissionTrayState(true, '1101', '2302')
158      strictEqual(getProps().isSubmissionTrayOpen, false)
159    })
160
161    test('.onGradeSubmission is the .gradeSubmission Gradebook method', () => {
162      strictEqual(getProps().onGradeSubmission, gradebook.gradeSubmission)
163    })
164
165    test('.onToggleSubmissionTrayOpen toggles the tray', () => {
166      getProps().onToggleSubmissionTrayOpen()
167      strictEqual(gradebook.getSubmissionTrayState().open, true)
168    })
169
170    test('.onToggleSubmissionTrayOpen toggles the tray using .toggleSubmissionTrayOpen', () => {
171      sinon.stub(gradebook, 'toggleSubmissionTrayOpen')
172      getProps().onToggleSubmissionTrayOpen()
173      strictEqual(gradebook.toggleSubmissionTrayOpen.callCount, 1)
174    })
175
176    test('.onToggleSubmissionTrayOpen toggles the tray for the current student', () => {
177      getProps().onToggleSubmissionTrayOpen()
178      strictEqual(gradebook.getSubmissionTrayState().studentId, '1101')
179    })
180
181    test('.onToggleSubmissionTrayOpen toggles the tray for the current assignment', () => {
182      getProps().onToggleSubmissionTrayOpen()
183      strictEqual(gradebook.getSubmissionTrayState().assignmentId, '2301')
184    })
185
186    test('.pendingGradeInfo is included when a valid pending grade exists', () => {
187      const pendingGradeInfo = {
188        enteredAs: 'points',
189        excused: false,
190        grade: 'A',
191        score: 10,
192        valid: true
193      }
194      gradebook.addPendingGradeInfo({assignmentId: '2301', userId: '1101'}, pendingGradeInfo)
195      deepEqual(getProps().pendingGradeInfo, {
196        ...pendingGradeInfo,
197        assignmentId: '2301',
198        userId: '1101'
199      })
200    })
201
202    test('.pendingGradeInfo is null when no pending grade exists', () => {
203      strictEqual(getProps().pendingGradeInfo, null)
204    })
205
206    test('.student is the student associated with the row of the cell', () => {
207      deepEqual(getProps().student, gradebook.students['1101'])
208    })
209
210    test('.submission.assignmentId is the assignment id', () => {
211      strictEqual(getProps().submission.assignmentId, '2301')
212    })
213
214    test('.submission.enteredGrade is the entered grade on the submission', () => {
215      strictEqual(getProps().submission.enteredGrade, '7.8')
216    })
217
218    test('.submission.enteredScore is the entered score on the submission', () => {
219      strictEqual(getProps().submission.enteredScore, 7.8)
220    })
221
222    test('.submission.excused is true when the submission is excused', () => {
223      gradebook.getSubmission('1101', '2301').excused = true
224      strictEqual(getProps().submission.excused, true)
225    })
226
227    test('.submission.excused is false when the value is undefined on the submission', () => {
228      gradebook.getSubmission('1101', '2301').excused = undefined
229      strictEqual(getProps().submission.excused, false)
230    })
231
232    test('.submission.grade is the final grade on the submission', () => {
233      strictEqual(getProps().submission.grade, '6.8')
234    })
235
236    test('.submission.id is the submission id', () => {
237      strictEqual(getProps().submission.id, '2501')
238    })
239
240    test('.submission.rawGrade is the raw grade on the submission', () => {
241      strictEqual(getProps().submission.rawGrade, '6.8')
242    })
243
244    test('.submission.score is the final score on the submission', () => {
245      strictEqual(getProps().submission.score, 6.8)
246    })
247
248    test('.submission.userId is the student id', () => {
249      strictEqual(getProps().submission.userId, '1101')
250    })
251
252    QUnit.module('.submission.similarityInfo', () => {
253      test('is null when not showing similarity scores in Gradebook', () => {
254        strictEqual(getProps().submission.similarityInfo, null)
255      })
256
257      QUnit.module('when showing similarity scores in Gradebook', showSimilarityScoreHooks => {
258        showSimilarityScoreHooks.beforeEach(() => {
259          sinon.stub(gradebook, 'showSimilarityScore').returns(true)
260        })
261
262        showSimilarityScoreHooks.afterEach(() => {
263          gradebook.showSimilarityScore.restore()
264        })
265
266        test('is null when the submission has no similarity data', () => {
267          strictEqual(getProps().submission.similarityInfo, null)
268        })
269
270        test('is set to the first entry returned by extractSimilarityInfo if data is present', () => {
271          const submission = {
272            assignment_id: '2301',
273            entered_grade: '7.8',
274            entered_score: 7.8,
275            excused: false,
276            grade: '6.8',
277            id: '2501',
278            score: 6.8,
279            submission_type: 'online_text_entry',
280            turnitin_data: {
281              submission_2501: {status: 'scored', similarity_score: 75}
282            },
283            user_id: '1101'
284          }
285
286          sinon.stub(gradebook, 'getSubmission').returns(submission)
287          deepEqual(getProps().submission.similarityInfo, {status: 'scored', similarityScore: 75})
288          gradebook.getSubmission.restore()
289        })
290      })
291    })
292
293    test('.submissionIsUpdating is true when a valid pending grade exists', () => {
294      gradebook.addPendingGradeInfo(
295        {assignmentId: '2301', userId: '1101'},
296        {enteredAs: 'points', excused: false, grade: 'A', score: 10, valid: true}
297      )
298      strictEqual(getProps().submissionIsUpdating, true)
299    })
300
301    test('.submissionIsUpdating is false when an invalid pending grade exists', () => {
302      gradebook.addPendingGradeInfo(
303        {assignmentId: '2301', userId: '1101'},
304        {enteredAs: null, excused: false, grade: null, score: null, valid: false}
305      )
306      strictEqual(getProps().submissionIsUpdating, false)
307    })
308
309    test('.submissionIsUpdating is false when no pending grade exists', () => {
310      strictEqual(getProps().submissionIsUpdating, false)
311    })
312  })
313})
314
Full Screen

proxy-array-prototype-methods.js

Source: proxy-array-prototype-methods.js Github

copy
1function assert(b) {
2    if (!b)
3        throw new Error("Bad assertion!");
4}
5
6function test(f) {
7    for (let i = 0; i < 1000; i++)
8        f();
9}
10
11function shallowEq(a, b) {
12    if (a.length !== b.length)
13        return false;
14    for (let i = 0; i < a.length; i++) {
15        if (a[i] !== b[i])
16            return false;
17    }
18    return true;
19}
20
21test(function() {
22    let delProps = new Set;
23    let hasProps = new Set;
24    let getProps = new Set;
25    let target = [ , , 1, , 4];
26    let handler = {
27        get(theTarget, key) {
28            getProps.add(key);
29            return Reflect.get(theTarget, key);
30        },
31        has(theTarget, key) {
32            hasProps.add(key);
33            return Reflect.has(theTarget, key);
34        },
35        deleteProperty(theTarget, key)
36        {
37            delProps.add(key);
38            return Reflect.deleteProperty(theTarget, key);
39        }
40    };
41
42    let proxy = new Proxy(target, handler);
43    proxy.unshift(20);
44
45    assert(delProps.size === 3);
46    assert(delProps.has("1"));
47    assert(delProps.has("2"));
48    assert(delProps.has("4"));
49
50    assert(hasProps.size === 5);
51    assert(hasProps.has("0"));
52    assert(hasProps.has("1"));
53    assert(hasProps.has("2"));
54    assert(hasProps.has("3"));
55    assert(hasProps.has("4"));
56
57    assert(getProps.size === 4);
58    assert(getProps.has("unshift"));
59    assert(getProps.has("length"));
60    assert(getProps.has("2"));
61    assert(getProps.has("4"));
62});
63
64test(function() {
65    let delProps = new Set;
66    let hasProps = new Set;
67    let getProps = new Set;
68    let target = [ 0, 0, , 1, , 4];
69    let handler = {
70        get(theTarget, key) {
71            getProps.add(key);
72            return Reflect.get(theTarget, key);
73        },
74        has(theTarget, key) {
75            hasProps.add(key);
76            return Reflect.has(theTarget, key);
77        },
78        deleteProperty(theTarget, key)
79        {
80            delProps.add(key);
81            return Reflect.deleteProperty(theTarget, key);
82        }
83    };
84
85    let proxy = new Proxy(target, handler);
86    proxy.shift();
87    assert(target.length === 5);
88
89    assert(delProps.size === 3);
90    assert(delProps.has("1"));
91    assert(delProps.has("3"));
92    assert(delProps.has("5"));
93
94    assert(hasProps.size === 5);
95    assert(hasProps.has("1"));
96    assert(hasProps.has("2"));
97    assert(hasProps.has("3"));
98    assert(hasProps.has("4"));
99    assert(hasProps.has("5"));
100
101    assert(getProps.size === 6);
102    assert(getProps.has("shift"));
103    assert(getProps.has("length"));
104    assert(getProps.has("0"));
105    assert(getProps.has("1"));
106    assert(getProps.has("3"));
107    assert(getProps.has("5"));
108});
109
110test(function() {
111    let delProps = new Set;
112    let hasProps = new Set;
113    let getProps = new Set;
114    let target = [ 0, , 1, , 2];
115    let handler = {
116        get(theTarget, key) {
117            getProps.add(key);
118            return Reflect.get(theTarget, key);
119        },
120        has(theTarget, key) {
121            hasProps.add(key);
122            return Reflect.has(theTarget, key);
123        },
124        deleteProperty(theTarget, key)
125        {
126            delProps.add(key);
127            return Reflect.deleteProperty(theTarget, key);
128        }
129    };
130
131    let proxy = new Proxy(target, handler);
132    proxy.splice(2, 2);
133
134    assert(delProps.size === 2);
135    assert(delProps.has("3"));
136    assert(delProps.has("4"));
137
138    assert(hasProps.size === 3);
139    assert(hasProps.has("2"));
140    assert(hasProps.has("3"));
141    assert(hasProps.has("4"));
142
143    assert(getProps.size === 5);
144    assert(getProps.has("splice"));
145    assert(getProps.has("length"));
146    assert(getProps.has("constructor"));
147    assert(getProps.has("2"));
148    assert(getProps.has("4"));
149});
150
151test(function() {
152    let delProps = new Set;
153    let hasProps = new Set;
154    let getProps = new Set;
155    let target = [ 0, , 1, , 2];
156    let handler = {
157        get(theTarget, key) {
158            getProps.add(key);
159            return Reflect.get(theTarget, key);
160        },
161        has(theTarget, key) {
162            hasProps.add(key);
163            return Reflect.has(theTarget, key);
164        },
165        deleteProperty(theTarget, key)
166        {
167            delProps.add(key);
168            return Reflect.deleteProperty(theTarget, key);
169        }
170    };
171
172    let proxy = new Proxy(target, handler);
173    proxy.slice(1, 5);
174
175    assert(delProps.size === 0);
176
177    assert(hasProps.size === 4);
178    assert(hasProps.has("1"));
179    assert(hasProps.has("2"));
180    assert(hasProps.has("3"));
181    assert(hasProps.has("4"));
182
183    assert(getProps.size === 5);
184    assert(getProps.has("slice"));
185    assert(getProps.has("length"));
186    assert(getProps.has("constructor"));
187    assert(getProps.has("2"));
188    assert(getProps.has("4"));
189});
190
191test(function() {
192    let x = [1,2,3];
193    x.__proto__ = new Proxy([], {
194        get(theTarget, prop, receiver) {
195            assert(prop === "shift");
196            assert(receiver === x);
197            return Reflect.get(theTarget, prop);
198        }
199    });
200    x.shift();
201    assert(x.length === 2);
202    assert(x[0] === 2);
203    assert(x[1] === 3);
204});
205
Full Screen

Accelerate Your Automation Test Cycles With LambdaTest

Leverage LambdaTest’s cloud-based platform to execute your automation tests in parallel and trim down your test execution time significantly. Your first 100 automation testing minutes are on us.

Try LambdaTest

Run JavaScript Tests on LambdaTest Cloud Grid

Execute automation tests with Playwright Internal on a cloud-based Grid of 3000+ real browsers and operating systems for both web and mobile applications.

Test now for Free
LambdaTestX

We use cookies to give you the best experience. Cookies help to provide a more personalized experience and relevant advertising for you, and web analytics for us. Learn More in our Cookies policy, Privacy & Terms of service

Allow Cookie
Sarah

I hope you find the best code examples for your project.

If you want to accelerate automated browser testing, try LambdaTest. Your first 100 automation testing minutes are FREE.

Sarah Elson (Product & Growth Lead)