br-dionysus 1.17.6 → 1.18.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +73 -24
- package/attributes.json +1 -1
- package/cypress/component/MSelect.cy.ts +0 -1
- package/cypress/component/MSelectTable.cy.ts +538 -0
- package/cypress/component/MSelectV2.cy.ts +0 -1
- package/cypress/component/MTable.cy.ts +123 -0
- package/cypress/e2e/1-getting-started/todo.cy.js +143 -0
- package/cypress/e2e/2-advanced-examples/actions.cy.js +321 -0
- package/cypress/e2e/2-advanced-examples/aliasing.cy.js +39 -0
- package/cypress/e2e/2-advanced-examples/assertions.cy.js +176 -0
- package/cypress/e2e/2-advanced-examples/connectors.cy.js +98 -0
- package/cypress/e2e/2-advanced-examples/cookies.cy.js +118 -0
- package/cypress/e2e/2-advanced-examples/cypress_api.cy.js +184 -0
- package/cypress/e2e/2-advanced-examples/files.cy.js +85 -0
- package/cypress/e2e/2-advanced-examples/location.cy.js +32 -0
- package/cypress/e2e/2-advanced-examples/misc.cy.js +98 -0
- package/cypress/e2e/2-advanced-examples/navigation.cy.js +55 -0
- package/cypress/e2e/2-advanced-examples/network_requests.cy.js +163 -0
- package/cypress/e2e/2-advanced-examples/querying.cy.js +114 -0
- package/cypress/e2e/2-advanced-examples/spies_stubs_clocks.cy.js +204 -0
- package/cypress/e2e/2-advanced-examples/storage.cy.js +117 -0
- package/cypress/e2e/2-advanced-examples/traversal.cy.js +121 -0
- package/cypress/e2e/2-advanced-examples/utilities.cy.js +107 -0
- package/cypress/e2e/2-advanced-examples/viewport.cy.js +58 -0
- package/cypress/e2e/2-advanced-examples/waiting.cy.js +30 -0
- package/cypress/e2e/2-advanced-examples/window.cy.js +22 -0
- package/cypress/e2e/toolSlotsToData.cy.ts +127 -0
- package/cypress/e2e/toolUniqueByKey.cy.ts +79 -0
- package/cypress/support/component.ts +20 -1
- package/cypress.config.ts +1 -0
- package/dist/br-dionysus.es.js +5872 -5695
- package/dist/br-dionysus.umd.js +6 -5
- package/dist/cypress/component/MInputNumber.cy.d.ts +0 -0
- package/dist/cypress/component/MSelect.cy.d.ts +1 -0
- package/dist/cypress/component/MSelectTable.cy.d.ts +1 -0
- package/dist/cypress/component/MSelectV2.cy.d.ts +1 -0
- package/dist/cypress/component/MTable.cy.d.ts +1 -0
- package/dist/cypress/e2e/spec.cy.d.ts +0 -0
- package/dist/cypress/e2e/toolCheckType.cy.d.ts +1 -0
- package/dist/cypress/e2e/toolCompareStructures.cy.d.ts +1 -0
- package/dist/cypress/e2e/toolCreateHash.cy.d.ts +1 -0
- package/dist/cypress/e2e/toolMoneyFormat.cy.d.ts +1 -0
- package/dist/cypress/e2e/toolSlotsToData.cy.d.ts +1 -0
- package/dist/cypress/e2e/toolUniqueByKey.cy.d.ts +1 -0
- package/dist/cypress/support/commands.d.ts +0 -0
- package/dist/cypress/support/component.d.ts +9 -0
- package/dist/cypress/support/e2e.d.ts +0 -0
- package/dist/index.css +1 -1
- package/dist/packages/Hook/usePackageConfig/usePackageConfig.d.ts +2 -0
- package/dist/packages/MTable/src/MTable.vue.d.ts +49 -15
- package/dist/packages/MTable/src/token.d.ts +13 -0
- package/dist/packages/MTableColumn/src/MTableColumn.vue.d.ts +9 -14
- package/dist/packages/Tool/globalEvents/globalEvents.d.ts +26 -0
- package/dist/packages/index.d.ts +2 -0
- package/mock/ajax/index.ts +48 -0
- package/mock/index.ts +51 -0
- package/mock/interface/enum.ts +4 -0
- package/mock/interface/type.ts +32 -0
- package/mock/mockData/book.ts +48 -0
- package/package.json +4 -2
- package/packages/Hook/usePackageConfig/usePackageConfig.ts +6 -4
- package/packages/Hook/useZIndex/useGlobalZIndex.ts +1 -1
- package/packages/MDialog/src/MDialog.vue +8 -8
- package/packages/MSelectTable/docs/DemoTest1.vue +25 -43
- package/packages/MSelectTable/docs/DemoTest2.vue +25 -43
- package/packages/MSelectTable/docs/DemoTest3.vue +29 -45
- package/packages/MSelectTable/docs/DemoTest4.vue +32 -39
- package/packages/MSelectTable/docs/DemoTest5.vue +37 -50
- package/packages/MSelectTable/docs/DemoTest6.vue +29 -44
- package/packages/MSelectTable/docs/README.md +1 -0
- package/packages/MSelectTable/src/MSelectTable.vue +9 -6
- package/packages/MTable/docs/DemoTest4.vue +0 -1
- package/packages/MTable/docs/DemoTest6.vue +122 -0
- package/packages/MTable/docs/DemoTest7.vue +138 -0
- package/packages/MTable/docs/README.md +10 -10
- package/packages/MTable/docs/demo.vue +10 -2
- package/packages/MTable/src/MBatchEdit.vue +1 -0
- package/packages/MTable/src/MTable.vue +254 -38
- package/packages/MTable/src/token.ts +14 -1
- package/packages/MTableColumn/docs/README.md +1 -0
- package/packages/MTableColumn/src/MTableColumn.vue +98 -24
- package/packages/Tool/globalEvents/README.md +23 -0
- package/packages/Tool/globalEvents/globalEvents.ts +79 -0
- package/packages/Tool/moneyFormat/moneyFormat.ts +2 -1
- package/packages/index.ts +2 -0
- package/packages/typings/global.d.ts +6 -2
- package/tags.json +1 -1
- package/tsconfig.json +3 -1
- package/vite.config.ts +1 -1
- package/web-types.json +1 -1
- package/cypress/screenshots/MSelectTable.cy.ts//344/270/213/346/213/211/350/241/250/346/240/274/351/200/211/346/213/251/345/231/250/347/273/204/344/273/266MSelectTable -- /346/265/213/350/257/225/345/215/225/351/200/211/345/212/237/350/203/275 (failed).png +0 -0
- package/cypress/screenshots/MSelectTable.cy.ts//344/270/213/346/213/211/350/241/250/346/240/274/351/200/211/346/213/251/345/231/250/347/273/204/344/273/266MSelectTable -- /346/265/213/350/257/225/345/237/272/347/241/200/345/212/237/350/203/275 (failed).png +0 -0
- package/cypress/screenshots/MSelectTable.cy.ts//344/270/213/346/213/211/350/241/250/346/240/274/351/200/211/346/213/251/345/231/250/347/273/204/344/273/266MSelectTable -- /346/265/213/350/257/225/345/244/232/351/200/211/345/212/237/350/203/275 (failed).png +0 -0
- package/cypress/screenshots/MSelectTable.cy.ts//344/270/213/346/213/211/350/241/250/346/240/274/351/200/211/346/213/251/345/231/250/347/273/204/344/273/266MSelectTable -- /346/265/213/350/257/225/350/277/234/347/250/213/346/220/234/347/264/242/345/212/237/350/203/275 (failed).png +0 -0
- package/src/global.d.ts +0 -7
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
/// <reference types="cypress" />
|
|
2
|
+
|
|
3
|
+
// Welcome to Cypress!
|
|
4
|
+
//
|
|
5
|
+
// This spec file contains a variety of sample tests
|
|
6
|
+
// for a todo list app that are designed to demonstrate
|
|
7
|
+
// the power of writing tests in Cypress.
|
|
8
|
+
//
|
|
9
|
+
// To learn more about how Cypress works and
|
|
10
|
+
// what makes it such an awesome testing tool,
|
|
11
|
+
// please read our getting started guide:
|
|
12
|
+
// https://on.cypress.io/introduction-to-cypress
|
|
13
|
+
|
|
14
|
+
describe('example to-do app', () => {
|
|
15
|
+
beforeEach(() => {
|
|
16
|
+
// Cypress starts out with a blank slate for each test
|
|
17
|
+
// so we must tell it to visit our website with the `cy.visit()` command.
|
|
18
|
+
// Since we want to visit the same URL at the start of all our tests,
|
|
19
|
+
// we include it in our beforeEach function so that it runs before each test
|
|
20
|
+
cy.visit('https://example.cypress.io/todo')
|
|
21
|
+
})
|
|
22
|
+
|
|
23
|
+
it('displays two todo items by default', () => {
|
|
24
|
+
// We use the `cy.get()` command to get all elements that match the selector.
|
|
25
|
+
// Then, we use `should` to assert that there are two matched items,
|
|
26
|
+
// which are the two default items.
|
|
27
|
+
cy.get('.todo-list li').should('have.length', 2)
|
|
28
|
+
|
|
29
|
+
// We can go even further and check that the default todos each contain
|
|
30
|
+
// the correct text. We use the `first` and `last` functions
|
|
31
|
+
// to get just the first and last matched elements individually,
|
|
32
|
+
// and then perform an assertion with `should`.
|
|
33
|
+
cy.get('.todo-list li').first().should('have.text', 'Pay electric bill')
|
|
34
|
+
cy.get('.todo-list li').last().should('have.text', 'Walk the dog')
|
|
35
|
+
})
|
|
36
|
+
|
|
37
|
+
it('can add new todo items', () => {
|
|
38
|
+
// We'll store our item text in a variable so we can reuse it
|
|
39
|
+
const newItem = 'Feed the cat'
|
|
40
|
+
|
|
41
|
+
// Let's get the input element and use the `type` command to
|
|
42
|
+
// input our new list item. After typing the content of our item,
|
|
43
|
+
// we need to type the enter key as well in order to submit the input.
|
|
44
|
+
// This input has a data-test attribute so we'll use that to select the
|
|
45
|
+
// element in accordance with best practices:
|
|
46
|
+
// https://on.cypress.io/selecting-elements
|
|
47
|
+
cy.get('[data-test=new-todo]').type(`${newItem}{enter}`)
|
|
48
|
+
|
|
49
|
+
// Now that we've typed our new item, let's check that it actually was added to the list.
|
|
50
|
+
// Since it's the newest item, it should exist as the last element in the list.
|
|
51
|
+
// In addition, with the two default items, we should have a total of 3 elements in the list.
|
|
52
|
+
// Since assertions yield the element that was asserted on,
|
|
53
|
+
// we can chain both of these assertions together into a single statement.
|
|
54
|
+
cy.get('.todo-list li')
|
|
55
|
+
.should('have.length', 3)
|
|
56
|
+
.last()
|
|
57
|
+
.should('have.text', newItem)
|
|
58
|
+
})
|
|
59
|
+
|
|
60
|
+
it('can check off an item as completed', () => {
|
|
61
|
+
// In addition to using the `get` command to get an element by selector,
|
|
62
|
+
// we can also use the `contains` command to get an element by its contents.
|
|
63
|
+
// However, this will yield the <label>, which is lowest-level element that contains the text.
|
|
64
|
+
// In order to check the item, we'll find the <input> element for this <label>
|
|
65
|
+
// by traversing up the dom to the parent element. From there, we can `find`
|
|
66
|
+
// the child checkbox <input> element and use the `check` command to check it.
|
|
67
|
+
cy.contains('Pay electric bill')
|
|
68
|
+
.parent()
|
|
69
|
+
.find('input[type=checkbox]')
|
|
70
|
+
.check()
|
|
71
|
+
|
|
72
|
+
// Now that we've checked the button, we can go ahead and make sure
|
|
73
|
+
// that the list element is now marked as completed.
|
|
74
|
+
// Again we'll use `contains` to find the <label> element and then use the `parents` command
|
|
75
|
+
// to traverse multiple levels up the dom until we find the corresponding <li> element.
|
|
76
|
+
// Once we get that element, we can assert that it has the completed class.
|
|
77
|
+
cy.contains('Pay electric bill')
|
|
78
|
+
.parents('li')
|
|
79
|
+
.should('have.class', 'completed')
|
|
80
|
+
})
|
|
81
|
+
|
|
82
|
+
context('with a checked task', () => {
|
|
83
|
+
beforeEach(() => {
|
|
84
|
+
// We'll take the command we used above to check off an element
|
|
85
|
+
// Since we want to perform multiple tests that start with checking
|
|
86
|
+
// one element, we put it in the beforeEach hook
|
|
87
|
+
// so that it runs at the start of every test.
|
|
88
|
+
cy.contains('Pay electric bill')
|
|
89
|
+
.parent()
|
|
90
|
+
.find('input[type=checkbox]')
|
|
91
|
+
.check()
|
|
92
|
+
})
|
|
93
|
+
|
|
94
|
+
it('can filter for uncompleted tasks', () => {
|
|
95
|
+
// We'll click on the "active" button in order to
|
|
96
|
+
// display only incomplete items
|
|
97
|
+
cy.contains('Active').click()
|
|
98
|
+
|
|
99
|
+
// After filtering, we can assert that there is only the one
|
|
100
|
+
// incomplete item in the list.
|
|
101
|
+
cy.get('.todo-list li')
|
|
102
|
+
.should('have.length', 1)
|
|
103
|
+
.first()
|
|
104
|
+
.should('have.text', 'Walk the dog')
|
|
105
|
+
|
|
106
|
+
// For good measure, let's also assert that the task we checked off
|
|
107
|
+
// does not exist on the page.
|
|
108
|
+
cy.contains('Pay electric bill').should('not.exist')
|
|
109
|
+
})
|
|
110
|
+
|
|
111
|
+
it('can filter for completed tasks', () => {
|
|
112
|
+
// We can perform similar steps as the test above to ensure
|
|
113
|
+
// that only completed tasks are shown
|
|
114
|
+
cy.contains('Completed').click()
|
|
115
|
+
|
|
116
|
+
cy.get('.todo-list li')
|
|
117
|
+
.should('have.length', 1)
|
|
118
|
+
.first()
|
|
119
|
+
.should('have.text', 'Pay electric bill')
|
|
120
|
+
|
|
121
|
+
cy.contains('Walk the dog').should('not.exist')
|
|
122
|
+
})
|
|
123
|
+
|
|
124
|
+
it('can delete all completed tasks', () => {
|
|
125
|
+
// First, let's click the "Clear completed" button
|
|
126
|
+
// `contains` is actually serving two purposes here.
|
|
127
|
+
// First, it's ensuring that the button exists within the dom.
|
|
128
|
+
// This button only appears when at least one task is checked
|
|
129
|
+
// so this command is implicitly verifying that it does exist.
|
|
130
|
+
// Second, it selects the button so we can click it.
|
|
131
|
+
cy.contains('Clear completed').click()
|
|
132
|
+
|
|
133
|
+
// Then we can make sure that there is only one element
|
|
134
|
+
// in the list and our element does not exist
|
|
135
|
+
cy.get('.todo-list li')
|
|
136
|
+
.should('have.length', 1)
|
|
137
|
+
.should('not.have.text', 'Pay electric bill')
|
|
138
|
+
|
|
139
|
+
// Finally, make sure that the clear button no longer exists.
|
|
140
|
+
cy.contains('Clear completed').should('not.exist')
|
|
141
|
+
})
|
|
142
|
+
})
|
|
143
|
+
})
|
|
@@ -0,0 +1,321 @@
|
|
|
1
|
+
/// <reference types="cypress" />
|
|
2
|
+
|
|
3
|
+
context('Actions', () => {
|
|
4
|
+
beforeEach(() => {
|
|
5
|
+
cy.visit('https://example.cypress.io/commands/actions')
|
|
6
|
+
})
|
|
7
|
+
|
|
8
|
+
// https://on.cypress.io/interacting-with-elements
|
|
9
|
+
|
|
10
|
+
it('.type() - type into a DOM element', () => {
|
|
11
|
+
// https://on.cypress.io/type
|
|
12
|
+
cy.get('.action-email').type('fake@email.com')
|
|
13
|
+
cy.get('.action-email').should('have.value', 'fake@email.com')
|
|
14
|
+
|
|
15
|
+
// .type() with special character sequences
|
|
16
|
+
cy.get('.action-email').type('{leftarrow}{rightarrow}{uparrow}{downarrow}')
|
|
17
|
+
cy.get('.action-email').type('{del}{selectall}{backspace}')
|
|
18
|
+
|
|
19
|
+
// .type() with key modifiers
|
|
20
|
+
cy.get('.action-email').type('{alt}{option}') // these are equivalent
|
|
21
|
+
cy.get('.action-email').type('{ctrl}{control}') // these are equivalent
|
|
22
|
+
cy.get('.action-email').type('{meta}{command}{cmd}') // these are equivalent
|
|
23
|
+
cy.get('.action-email').type('{shift}')
|
|
24
|
+
|
|
25
|
+
// Delay each keypress by 0.1 sec
|
|
26
|
+
cy.get('.action-email').type('slow.typing@email.com', { delay: 100 })
|
|
27
|
+
cy.get('.action-email').should('have.value', 'slow.typing@email.com')
|
|
28
|
+
|
|
29
|
+
cy.get('.action-disabled')
|
|
30
|
+
// Ignore error checking prior to type
|
|
31
|
+
// like whether the input is visible or disabled
|
|
32
|
+
.type('disabled error checking', { force: true })
|
|
33
|
+
cy.get('.action-disabled').should('have.value', 'disabled error checking')
|
|
34
|
+
})
|
|
35
|
+
|
|
36
|
+
it('.focus() - focus on a DOM element', () => {
|
|
37
|
+
// https://on.cypress.io/focus
|
|
38
|
+
cy.get('.action-focus').focus()
|
|
39
|
+
cy.get('.action-focus').should('have.class', 'focus')
|
|
40
|
+
.prev().should('have.attr', 'style', 'color: orange;')
|
|
41
|
+
})
|
|
42
|
+
|
|
43
|
+
it('.blur() - blur off a DOM element', () => {
|
|
44
|
+
// https://on.cypress.io/blur
|
|
45
|
+
cy.get('.action-blur').type('About to blur')
|
|
46
|
+
cy.get('.action-blur').blur()
|
|
47
|
+
cy.get('.action-blur').should('have.class', 'error')
|
|
48
|
+
.prev().should('have.attr', 'style', 'color: red;')
|
|
49
|
+
})
|
|
50
|
+
|
|
51
|
+
it('.clear() - clears an input or textarea element', () => {
|
|
52
|
+
// https://on.cypress.io/clear
|
|
53
|
+
cy.get('.action-clear').type('Clear this text')
|
|
54
|
+
cy.get('.action-clear').should('have.value', 'Clear this text')
|
|
55
|
+
cy.get('.action-clear').clear()
|
|
56
|
+
cy.get('.action-clear').should('have.value', '')
|
|
57
|
+
})
|
|
58
|
+
|
|
59
|
+
it('.submit() - submit a form', () => {
|
|
60
|
+
// https://on.cypress.io/submit
|
|
61
|
+
cy.get('.action-form')
|
|
62
|
+
.find('[type="text"]').type('HALFOFF')
|
|
63
|
+
|
|
64
|
+
cy.get('.action-form').submit()
|
|
65
|
+
cy.get('.action-form').next().should('contain', 'Your form has been submitted!')
|
|
66
|
+
})
|
|
67
|
+
|
|
68
|
+
it('.click() - click on a DOM element', () => {
|
|
69
|
+
// https://on.cypress.io/click
|
|
70
|
+
cy.get('.action-btn').click()
|
|
71
|
+
|
|
72
|
+
// You can click on 9 specific positions of an element:
|
|
73
|
+
// -----------------------------------
|
|
74
|
+
// | topLeft top topRight |
|
|
75
|
+
// | |
|
|
76
|
+
// | |
|
|
77
|
+
// | |
|
|
78
|
+
// | left center right |
|
|
79
|
+
// | |
|
|
80
|
+
// | |
|
|
81
|
+
// | |
|
|
82
|
+
// | bottomLeft bottom bottomRight |
|
|
83
|
+
// -----------------------------------
|
|
84
|
+
|
|
85
|
+
// clicking in the center of the element is the default
|
|
86
|
+
cy.get('#action-canvas').click()
|
|
87
|
+
|
|
88
|
+
cy.get('#action-canvas').click('topLeft')
|
|
89
|
+
cy.get('#action-canvas').click('top')
|
|
90
|
+
cy.get('#action-canvas').click('topRight')
|
|
91
|
+
cy.get('#action-canvas').click('left')
|
|
92
|
+
cy.get('#action-canvas').click('right')
|
|
93
|
+
cy.get('#action-canvas').click('bottomLeft')
|
|
94
|
+
cy.get('#action-canvas').click('bottom')
|
|
95
|
+
cy.get('#action-canvas').click('bottomRight')
|
|
96
|
+
|
|
97
|
+
// .click() accepts an x and y coordinate
|
|
98
|
+
// that controls where the click occurs :)
|
|
99
|
+
|
|
100
|
+
cy.get('#action-canvas')
|
|
101
|
+
cy.get('#action-canvas').click(80, 75) // click 80px on x coord and 75px on y coord
|
|
102
|
+
cy.get('#action-canvas').click(170, 75)
|
|
103
|
+
cy.get('#action-canvas').click(80, 165)
|
|
104
|
+
cy.get('#action-canvas').click(100, 185)
|
|
105
|
+
cy.get('#action-canvas').click(125, 190)
|
|
106
|
+
cy.get('#action-canvas').click(150, 185)
|
|
107
|
+
cy.get('#action-canvas').click(170, 165)
|
|
108
|
+
|
|
109
|
+
// click multiple elements by passing multiple: true
|
|
110
|
+
cy.get('.action-labels>.label').click({ multiple: true })
|
|
111
|
+
|
|
112
|
+
// Ignore error checking prior to clicking
|
|
113
|
+
cy.get('.action-opacity>.btn').click({ force: true })
|
|
114
|
+
})
|
|
115
|
+
|
|
116
|
+
it('.dblclick() - double click on a DOM element', () => {
|
|
117
|
+
// https://on.cypress.io/dblclick
|
|
118
|
+
|
|
119
|
+
// Our app has a listener on 'dblclick' event in our 'scripts.js'
|
|
120
|
+
// that hides the div and shows an input on double click
|
|
121
|
+
cy.get('.action-div').dblclick()
|
|
122
|
+
cy.get('.action-div').should('not.be.visible')
|
|
123
|
+
cy.get('.action-input-hidden').should('be.visible')
|
|
124
|
+
})
|
|
125
|
+
|
|
126
|
+
it('.rightclick() - right click on a DOM element', () => {
|
|
127
|
+
// https://on.cypress.io/rightclick
|
|
128
|
+
|
|
129
|
+
// Our app has a listener on 'contextmenu' event in our 'scripts.js'
|
|
130
|
+
// that hides the div and shows an input on right click
|
|
131
|
+
cy.get('.rightclick-action-div').rightclick()
|
|
132
|
+
cy.get('.rightclick-action-div').should('not.be.visible')
|
|
133
|
+
cy.get('.rightclick-action-input-hidden').should('be.visible')
|
|
134
|
+
})
|
|
135
|
+
|
|
136
|
+
it('.check() - check a checkbox or radio element', () => {
|
|
137
|
+
// https://on.cypress.io/check
|
|
138
|
+
|
|
139
|
+
// By default, .check() will check all
|
|
140
|
+
// matching checkbox or radio elements in succession, one after another
|
|
141
|
+
cy.get('.action-checkboxes [type="checkbox"]').not('[disabled]').check()
|
|
142
|
+
cy.get('.action-checkboxes [type="checkbox"]').not('[disabled]').should('be.checked')
|
|
143
|
+
|
|
144
|
+
cy.get('.action-radios [type="radio"]').not('[disabled]').check()
|
|
145
|
+
cy.get('.action-radios [type="radio"]').not('[disabled]').should('be.checked')
|
|
146
|
+
|
|
147
|
+
// .check() accepts a value argument
|
|
148
|
+
cy.get('.action-radios [type="radio"]').check('radio1')
|
|
149
|
+
cy.get('.action-radios [type="radio"]').should('be.checked')
|
|
150
|
+
|
|
151
|
+
// .check() accepts an array of values
|
|
152
|
+
cy.get('.action-multiple-checkboxes [type="checkbox"]').check(['checkbox1', 'checkbox2'])
|
|
153
|
+
cy.get('.action-multiple-checkboxes [type="checkbox"]').should('be.checked')
|
|
154
|
+
|
|
155
|
+
// Ignore error checking prior to checking
|
|
156
|
+
cy.get('.action-checkboxes [disabled]').check({ force: true })
|
|
157
|
+
cy.get('.action-checkboxes [disabled]').should('be.checked')
|
|
158
|
+
|
|
159
|
+
cy.get('.action-radios [type="radio"]').check('radio3', { force: true })
|
|
160
|
+
cy.get('.action-radios [type="radio"]').should('be.checked')
|
|
161
|
+
})
|
|
162
|
+
|
|
163
|
+
it('.uncheck() - uncheck a checkbox element', () => {
|
|
164
|
+
// https://on.cypress.io/uncheck
|
|
165
|
+
|
|
166
|
+
// By default, .uncheck() will uncheck all matching
|
|
167
|
+
// checkbox elements in succession, one after another
|
|
168
|
+
cy.get('.action-check [type="checkbox"]')
|
|
169
|
+
.not('[disabled]')
|
|
170
|
+
.uncheck()
|
|
171
|
+
cy.get('.action-check [type="checkbox"]')
|
|
172
|
+
.not('[disabled]')
|
|
173
|
+
.should('not.be.checked')
|
|
174
|
+
|
|
175
|
+
// .uncheck() accepts a value argument
|
|
176
|
+
cy.get('.action-check [type="checkbox"]')
|
|
177
|
+
.check('checkbox1')
|
|
178
|
+
cy.get('.action-check [type="checkbox"]')
|
|
179
|
+
.uncheck('checkbox1')
|
|
180
|
+
cy.get('.action-check [type="checkbox"][value="checkbox1"]')
|
|
181
|
+
.should('not.be.checked')
|
|
182
|
+
|
|
183
|
+
// .uncheck() accepts an array of values
|
|
184
|
+
cy.get('.action-check [type="checkbox"]')
|
|
185
|
+
.check(['checkbox1', 'checkbox3'])
|
|
186
|
+
cy.get('.action-check [type="checkbox"]')
|
|
187
|
+
.uncheck(['checkbox1', 'checkbox3'])
|
|
188
|
+
cy.get('.action-check [type="checkbox"][value="checkbox1"]')
|
|
189
|
+
.should('not.be.checked')
|
|
190
|
+
cy.get('.action-check [type="checkbox"][value="checkbox3"]')
|
|
191
|
+
.should('not.be.checked')
|
|
192
|
+
|
|
193
|
+
// Ignore error checking prior to unchecking
|
|
194
|
+
cy.get('.action-check [disabled]').uncheck({ force: true })
|
|
195
|
+
cy.get('.action-check [disabled]').should('not.be.checked')
|
|
196
|
+
})
|
|
197
|
+
|
|
198
|
+
it('.select() - select an option in a <select> element', () => {
|
|
199
|
+
// https://on.cypress.io/select
|
|
200
|
+
|
|
201
|
+
// at first, no option should be selected
|
|
202
|
+
cy.get('.action-select')
|
|
203
|
+
.should('have.value', '--Select a fruit--')
|
|
204
|
+
|
|
205
|
+
// Select option(s) with matching text content
|
|
206
|
+
cy.get('.action-select').select('apples')
|
|
207
|
+
// confirm the apples were selected
|
|
208
|
+
// note that each value starts with "fr-" in our HTML
|
|
209
|
+
cy.get('.action-select').should('have.value', 'fr-apples')
|
|
210
|
+
|
|
211
|
+
cy.get('.action-select-multiple')
|
|
212
|
+
.select(['apples', 'oranges', 'bananas'])
|
|
213
|
+
cy.get('.action-select-multiple')
|
|
214
|
+
// when getting multiple values, invoke "val" method first
|
|
215
|
+
.invoke('val')
|
|
216
|
+
.should('deep.equal', ['fr-apples', 'fr-oranges', 'fr-bananas'])
|
|
217
|
+
|
|
218
|
+
// Select option(s) with matching value
|
|
219
|
+
cy.get('.action-select').select('fr-bananas')
|
|
220
|
+
cy.get('.action-select')
|
|
221
|
+
// can attach an assertion right away to the element
|
|
222
|
+
.should('have.value', 'fr-bananas')
|
|
223
|
+
|
|
224
|
+
cy.get('.action-select-multiple')
|
|
225
|
+
.select(['fr-apples', 'fr-oranges', 'fr-bananas'])
|
|
226
|
+
cy.get('.action-select-multiple')
|
|
227
|
+
.invoke('val')
|
|
228
|
+
.should('deep.equal', ['fr-apples', 'fr-oranges', 'fr-bananas'])
|
|
229
|
+
|
|
230
|
+
// assert the selected values include oranges
|
|
231
|
+
cy.get('.action-select-multiple')
|
|
232
|
+
.invoke('val').should('include', 'fr-oranges')
|
|
233
|
+
})
|
|
234
|
+
|
|
235
|
+
it('.scrollIntoView() - scroll an element into view', () => {
|
|
236
|
+
// https://on.cypress.io/scrollintoview
|
|
237
|
+
|
|
238
|
+
// normally all of these buttons are hidden,
|
|
239
|
+
// because they're not within
|
|
240
|
+
// the viewable area of their parent
|
|
241
|
+
// (we need to scroll to see them)
|
|
242
|
+
cy.get('#scroll-horizontal button')
|
|
243
|
+
.should('not.be.visible')
|
|
244
|
+
|
|
245
|
+
// scroll the button into view, as if the user had scrolled
|
|
246
|
+
cy.get('#scroll-horizontal button').scrollIntoView()
|
|
247
|
+
cy.get('#scroll-horizontal button')
|
|
248
|
+
.should('be.visible')
|
|
249
|
+
|
|
250
|
+
cy.get('#scroll-vertical button')
|
|
251
|
+
.should('not.be.visible')
|
|
252
|
+
|
|
253
|
+
// Cypress handles the scroll direction needed
|
|
254
|
+
cy.get('#scroll-vertical button').scrollIntoView()
|
|
255
|
+
cy.get('#scroll-vertical button')
|
|
256
|
+
.should('be.visible')
|
|
257
|
+
|
|
258
|
+
cy.get('#scroll-both button')
|
|
259
|
+
.should('not.be.visible')
|
|
260
|
+
|
|
261
|
+
// Cypress knows to scroll to the right and down
|
|
262
|
+
cy.get('#scroll-both button').scrollIntoView()
|
|
263
|
+
cy.get('#scroll-both button')
|
|
264
|
+
.should('be.visible')
|
|
265
|
+
})
|
|
266
|
+
|
|
267
|
+
it('.trigger() - trigger an event on a DOM element', () => {
|
|
268
|
+
// https://on.cypress.io/trigger
|
|
269
|
+
|
|
270
|
+
// To interact with a range input (slider)
|
|
271
|
+
// we need to set its value & trigger the
|
|
272
|
+
// event to signal it changed
|
|
273
|
+
|
|
274
|
+
// Here, we invoke jQuery's val() method to set
|
|
275
|
+
// the value and trigger the 'change' event
|
|
276
|
+
cy.get('.trigger-input-range')
|
|
277
|
+
.invoke('val', 25)
|
|
278
|
+
cy.get('.trigger-input-range')
|
|
279
|
+
.trigger('change')
|
|
280
|
+
cy.get('.trigger-input-range')
|
|
281
|
+
.get('input[type=range]').siblings('p')
|
|
282
|
+
.should('have.text', '25')
|
|
283
|
+
})
|
|
284
|
+
|
|
285
|
+
it('cy.scrollTo() - scroll the window or element to a position', () => {
|
|
286
|
+
// https://on.cypress.io/scrollto
|
|
287
|
+
|
|
288
|
+
// You can scroll to 9 specific positions of an element:
|
|
289
|
+
// -----------------------------------
|
|
290
|
+
// | topLeft top topRight |
|
|
291
|
+
// | |
|
|
292
|
+
// | |
|
|
293
|
+
// | |
|
|
294
|
+
// | left center right |
|
|
295
|
+
// | |
|
|
296
|
+
// | |
|
|
297
|
+
// | |
|
|
298
|
+
// | bottomLeft bottom bottomRight |
|
|
299
|
+
// -----------------------------------
|
|
300
|
+
|
|
301
|
+
// if you chain .scrollTo() off of cy, we will
|
|
302
|
+
// scroll the entire window
|
|
303
|
+
cy.scrollTo('bottom')
|
|
304
|
+
|
|
305
|
+
cy.get('#scrollable-horizontal').scrollTo('right')
|
|
306
|
+
|
|
307
|
+
// or you can scroll to a specific coordinate:
|
|
308
|
+
// (x axis, y axis) in pixels
|
|
309
|
+
cy.get('#scrollable-vertical').scrollTo(250, 250)
|
|
310
|
+
|
|
311
|
+
// or you can scroll to a specific percentage
|
|
312
|
+
// of the (width, height) of the element
|
|
313
|
+
cy.get('#scrollable-both').scrollTo('75%', '25%')
|
|
314
|
+
|
|
315
|
+
// control the easing of the scroll (default is 'swing')
|
|
316
|
+
cy.get('#scrollable-vertical').scrollTo('center', { easing: 'linear' })
|
|
317
|
+
|
|
318
|
+
// control the duration of the scroll (in ms)
|
|
319
|
+
cy.get('#scrollable-both').scrollTo('center', { duration: 2000 })
|
|
320
|
+
})
|
|
321
|
+
})
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/// <reference types="cypress" />
|
|
2
|
+
|
|
3
|
+
context('Aliasing', () => {
|
|
4
|
+
beforeEach(() => {
|
|
5
|
+
cy.visit('https://example.cypress.io/commands/aliasing')
|
|
6
|
+
})
|
|
7
|
+
|
|
8
|
+
it('.as() - alias a DOM element for later use', () => {
|
|
9
|
+
// https://on.cypress.io/as
|
|
10
|
+
|
|
11
|
+
// Alias a DOM element for use later
|
|
12
|
+
// We don't have to traverse to the element
|
|
13
|
+
// later in our code, we reference it with @
|
|
14
|
+
|
|
15
|
+
cy.get('.as-table').find('tbody>tr')
|
|
16
|
+
.first().find('td').first()
|
|
17
|
+
.find('button').as('firstBtn')
|
|
18
|
+
|
|
19
|
+
// when we reference the alias, we place an
|
|
20
|
+
// @ in front of its name
|
|
21
|
+
cy.get('@firstBtn').click()
|
|
22
|
+
|
|
23
|
+
cy.get('@firstBtn')
|
|
24
|
+
.should('have.class', 'btn-success')
|
|
25
|
+
.and('contain', 'Changed')
|
|
26
|
+
})
|
|
27
|
+
|
|
28
|
+
it('.as() - alias a route for later use', () => {
|
|
29
|
+
// Alias the route to wait for its response
|
|
30
|
+
cy.intercept('GET', '**/comments/*').as('getComment')
|
|
31
|
+
|
|
32
|
+
// we have code that gets a comment when
|
|
33
|
+
// the button is clicked in scripts.js
|
|
34
|
+
cy.get('.network-btn').click()
|
|
35
|
+
|
|
36
|
+
// https://on.cypress.io/wait
|
|
37
|
+
cy.wait('@getComment').its('response.statusCode').should('eq', 200)
|
|
38
|
+
})
|
|
39
|
+
})
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
/// <reference types="cypress" />
|
|
2
|
+
|
|
3
|
+
context('Assertions', () => {
|
|
4
|
+
beforeEach(() => {
|
|
5
|
+
cy.visit('https://example.cypress.io/commands/assertions')
|
|
6
|
+
})
|
|
7
|
+
|
|
8
|
+
describe('Implicit Assertions', () => {
|
|
9
|
+
it('.should() - make an assertion about the current subject', () => {
|
|
10
|
+
// https://on.cypress.io/should
|
|
11
|
+
cy.get('.assertion-table')
|
|
12
|
+
.find('tbody tr:last')
|
|
13
|
+
.should('have.class', 'success')
|
|
14
|
+
.find('td')
|
|
15
|
+
.first()
|
|
16
|
+
// checking the text of the <td> element in various ways
|
|
17
|
+
.should('have.text', 'Column content')
|
|
18
|
+
.should('contain', 'Column content')
|
|
19
|
+
.should('have.html', 'Column content')
|
|
20
|
+
// chai-jquery uses "is()" to check if element matches selector
|
|
21
|
+
.should('match', 'td')
|
|
22
|
+
// to match text content against a regular expression
|
|
23
|
+
// first need to invoke jQuery method text()
|
|
24
|
+
// and then match using regular expression
|
|
25
|
+
.invoke('text')
|
|
26
|
+
.should('match', /column content/i)
|
|
27
|
+
|
|
28
|
+
// a better way to check element's text content against a regular expression
|
|
29
|
+
// is to use "cy.contains"
|
|
30
|
+
// https://on.cypress.io/contains
|
|
31
|
+
cy.get('.assertion-table')
|
|
32
|
+
.find('tbody tr:last')
|
|
33
|
+
// finds first <td> element with text content matching regular expression
|
|
34
|
+
.contains('td', /column content/i)
|
|
35
|
+
.should('be.visible')
|
|
36
|
+
|
|
37
|
+
// for more information about asserting element's text
|
|
38
|
+
// see https://on.cypress.io/using-cypress-faq#How-do-I-get-an-element’s-text-contents
|
|
39
|
+
})
|
|
40
|
+
|
|
41
|
+
it('.and() - chain multiple assertions together', () => {
|
|
42
|
+
// https://on.cypress.io/and
|
|
43
|
+
cy.get('.assertions-link')
|
|
44
|
+
.should('have.class', 'active')
|
|
45
|
+
.and('have.attr', 'href')
|
|
46
|
+
.and('include', 'cypress.io')
|
|
47
|
+
})
|
|
48
|
+
})
|
|
49
|
+
|
|
50
|
+
describe('Explicit Assertions', () => {
|
|
51
|
+
// https://on.cypress.io/assertions
|
|
52
|
+
it('expect - make an assertion about a specified subject', () => {
|
|
53
|
+
// We can use Chai's BDD style assertions
|
|
54
|
+
expect(true).to.be.true
|
|
55
|
+
const o = { foo: 'bar' }
|
|
56
|
+
|
|
57
|
+
expect(o).to.equal(o)
|
|
58
|
+
expect(o).to.deep.equal({ foo: 'bar' })
|
|
59
|
+
// matching text using regular expression
|
|
60
|
+
expect('FooBar').to.match(/bar$/i)
|
|
61
|
+
})
|
|
62
|
+
|
|
63
|
+
it('pass your own callback function to should()', () => {
|
|
64
|
+
// Pass a function to should that can have any number
|
|
65
|
+
// of explicit assertions within it.
|
|
66
|
+
// The ".should(cb)" function will be retried
|
|
67
|
+
// automatically until it passes all your explicit assertions or times out.
|
|
68
|
+
cy.get('.assertions-p')
|
|
69
|
+
.find('p')
|
|
70
|
+
.should(($p) => {
|
|
71
|
+
// https://on.cypress.io/$
|
|
72
|
+
// return an array of texts from all of the p's
|
|
73
|
+
const texts = $p.map((i, el) => Cypress.$(el).text())
|
|
74
|
+
|
|
75
|
+
// jquery map returns jquery object
|
|
76
|
+
// and .get() convert this to simple array
|
|
77
|
+
const paragraphs = texts.get()
|
|
78
|
+
|
|
79
|
+
// array should have length of 3
|
|
80
|
+
expect(paragraphs, 'has 3 paragraphs').to.have.length(3)
|
|
81
|
+
|
|
82
|
+
// use second argument to expect(...) to provide clear
|
|
83
|
+
// message with each assertion
|
|
84
|
+
expect(paragraphs, 'has expected text in each paragraph').to.deep.eq([
|
|
85
|
+
'Some text from first p',
|
|
86
|
+
'More text from second p',
|
|
87
|
+
'And even more text from third p',
|
|
88
|
+
])
|
|
89
|
+
})
|
|
90
|
+
})
|
|
91
|
+
|
|
92
|
+
it('finds element by class name regex', () => {
|
|
93
|
+
cy.get('.docs-header')
|
|
94
|
+
.find('div')
|
|
95
|
+
// .should(cb) callback function will be retried
|
|
96
|
+
.should(($div) => {
|
|
97
|
+
expect($div).to.have.length(1)
|
|
98
|
+
|
|
99
|
+
const className = $div[0].className
|
|
100
|
+
|
|
101
|
+
expect(className).to.match(/heading-/)
|
|
102
|
+
})
|
|
103
|
+
// .then(cb) callback is not retried,
|
|
104
|
+
// it either passes or fails
|
|
105
|
+
.then(($div) => {
|
|
106
|
+
expect($div, 'text content').to.have.text('Introduction')
|
|
107
|
+
})
|
|
108
|
+
})
|
|
109
|
+
|
|
110
|
+
it('can throw any error', () => {
|
|
111
|
+
cy.get('.docs-header')
|
|
112
|
+
.find('div')
|
|
113
|
+
.should(($div) => {
|
|
114
|
+
if ($div.length !== 1) {
|
|
115
|
+
// you can throw your own errors
|
|
116
|
+
throw new Error('Did not find 1 element')
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
const className = $div[0].className
|
|
120
|
+
|
|
121
|
+
if (!className.match(/heading-/)) {
|
|
122
|
+
throw new Error(`Could not find class "heading-" in ${className}`)
|
|
123
|
+
}
|
|
124
|
+
})
|
|
125
|
+
})
|
|
126
|
+
|
|
127
|
+
it('matches unknown text between two elements', () => {
|
|
128
|
+
/**
|
|
129
|
+
* Text from the first element.
|
|
130
|
+
* @type {string}
|
|
131
|
+
*/
|
|
132
|
+
let text
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* Normalizes passed text,
|
|
136
|
+
* useful before comparing text with spaces and different capitalization.
|
|
137
|
+
* @param {string} s Text to normalize
|
|
138
|
+
*/
|
|
139
|
+
const normalizeText = (s) => s.replace(/\s/g, '').toLowerCase()
|
|
140
|
+
|
|
141
|
+
cy.get('.two-elements')
|
|
142
|
+
.find('.first')
|
|
143
|
+
.then(($first) => {
|
|
144
|
+
// save text from the first element
|
|
145
|
+
text = normalizeText($first.text())
|
|
146
|
+
})
|
|
147
|
+
|
|
148
|
+
cy.get('.two-elements')
|
|
149
|
+
.find('.second')
|
|
150
|
+
.should(($div) => {
|
|
151
|
+
// we can massage text before comparing
|
|
152
|
+
const secondText = normalizeText($div.text())
|
|
153
|
+
|
|
154
|
+
expect(secondText, 'second text').to.equal(text)
|
|
155
|
+
})
|
|
156
|
+
})
|
|
157
|
+
|
|
158
|
+
it('assert - assert shape of an object', () => {
|
|
159
|
+
const person = {
|
|
160
|
+
name: 'Joe',
|
|
161
|
+
age: 20,
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
assert.isObject(person, 'value is object')
|
|
165
|
+
})
|
|
166
|
+
|
|
167
|
+
it('retries the should callback until assertions pass', () => {
|
|
168
|
+
cy.get('#random-number')
|
|
169
|
+
.should(($div) => {
|
|
170
|
+
const n = parseFloat($div.text())
|
|
171
|
+
|
|
172
|
+
expect(n).to.be.gte(1).and.be.lte(10)
|
|
173
|
+
})
|
|
174
|
+
})
|
|
175
|
+
})
|
|
176
|
+
})
|