Merge from ecomp 718fd196 - Modern UI
[vid.git] / vid-webpack-master / cypress / support / elements / element.actions.ts
1 import Chainable = Cypress.Chainable;
2
3 declare namespace Cypress {
4   interface Chainable {
5     isElementContainsAttr : typeof isElementContainsAttr;
6     isElementDisabled : typeof isElementDisabled;
7     isElementEnabled : typeof isElementEnabled;
8     hasClass : typeof hasClass;
9     getElementByDataTestsId : typeof getElementByDataTestsId;
10     getTagElementContainsText : typeof  getTagElementContainsText;
11     isElementNotContainsAttr : typeof  isElementNotContainsAttr;
12   }
13 }
14
15 /*************************************************************************
16  isElementContainsAttr : check if element with id contains some attribute
17  *************************************************************************/
18 function isElementContainsAttr(id : string, attr: string) : void {
19   cy.getElementByDataTestsId(id).should('have.attr', attr);
20 }
21
22 /*************************************************************************
23  isElementContainsAttr : check if element with id not contains some attribute
24  *************************************************************************/
25 function isElementNotContainsAttr(id : string, attr: string) : void {
26   cy.getElementByDataTestsId(id).should('not.have.attr', attr);
27 }
28
29 /*********************************************************
30  isElementDisabled : check if element with id is disabled
31  *********************************************************/
32 function isElementDisabled(id : string) : void {
33   cy.getElementByDataTestsId(id).should('be:disabled');
34 }
35
36 function isElementEnabled(id : string) : void {
37   cy.getElementByDataTestsId(id).should('be:enabled');
38 }
39
40 /****************************************************************
41  hasClass : check if element with id contains some class name
42  ****************************************************************/
43 function hasClass(id : string, className : string) : void {
44   cy.getElementByDataTestsId(id).should('have.class', className);
45 }
46
47 function getElementByDataTestsId(dataTestsId : string) : Chainable<JQuery<HTMLElement>> {
48   return cy.get( "[data-tests-id='" + dataTestsId +"']");
49 }
50
51 /**************************************************
52  getTagElementContainsText : return tag with text
53  **************************************************/
54 function getTagElementContainsText(tag : string, text : string) : Chainable<JQuery<HTMLElement>> {
55   return cy.contains(tag,text);
56 }
57
58
59 Cypress.Commands.add('isElementContainsAttr', isElementContainsAttr);
60 Cypress.Commands.add('isElementDisabled', isElementDisabled);
61 Cypress.Commands.add('isElementEnabled', isElementEnabled);
62 Cypress.Commands.add('hasClass', hasClass);
63 Cypress.Commands.add('getElementByDataTestsId', getElementByDataTestsId);
64 Cypress.Commands.add('getTagElementContainsText', getTagElementContainsText);
65 Cypress.Commands.add('isElementNotContainsAttr', isElementNotContainsAttr);