|
| 1 | +import { Util } from 'cypress-wikibase-api'; |
| 2 | + |
| 3 | +import { checkA11y } from '../../support/checkA11y'; |
| 4 | +import { ItemViewPage } from '../../support/pageObjects/ItemViewPage'; |
| 5 | +import { EditStatementFormPage } from '../../support/pageObjects/EditStatementFormPage'; |
| 6 | + |
| 7 | +describe( 'wbui2025 entityId datatypes (item, property)', () => { |
| 8 | + |
| 9 | + const createEntityForDatatype = { |
| 10 | + item: ( label: string ) => cy.task( 'MwApi:CreateEntity', { |
| 11 | + entityType: 'item', |
| 12 | + label: label, |
| 13 | + data: { claims: [] }, |
| 14 | + } ), |
| 15 | + property: ( label: string ) => cy.task( 'MwApi:CreateEntity', { |
| 16 | + entityType: 'property', |
| 17 | + label: label, |
| 18 | + data: { |
| 19 | + datatype: 'string', |
| 20 | + claims: [], |
| 21 | + }, |
| 22 | + } ), |
| 23 | + }; |
| 24 | + |
| 25 | + for ( const datatype of [ 'item', 'property' ] ) { |
| 26 | + context( 'mobile view - ' + datatype + ' datatype', () => { |
| 27 | + let propertyName: string; |
| 28 | + let entityId: string; |
| 29 | + let linkedEntityId: string; |
| 30 | + let linkedEntityLabel: string; |
| 31 | + let newLinkedEntityLabel: string; |
| 32 | + |
| 33 | + before( () => { |
| 34 | + propertyName = Util.getTestString( datatype + '-property' + '-' ); |
| 35 | + linkedEntityLabel = Util.getTestString( 'linked-' + datatype + '-' ); |
| 36 | + newLinkedEntityLabel = Util.getTestString( 'new-linked-' + datatype + '-' ); |
| 37 | + createEntityForDatatype[ datatype ]( linkedEntityLabel ).then( ( newEntityId: string ) => { |
| 38 | + linkedEntityId = newEntityId; |
| 39 | + } ); |
| 40 | + createEntityForDatatype[ datatype ]( newLinkedEntityLabel ); |
| 41 | + cy.task( 'MwApi:CreateProperty', { |
| 42 | + label: propertyName, |
| 43 | + data: { datatype: 'wikibase-' + datatype }, |
| 44 | + } ).then( ( newPropertyId: string ) => { |
| 45 | + const statementData = { |
| 46 | + claims: [ { |
| 47 | + mainsnak: { |
| 48 | + snaktype: 'value', |
| 49 | + property: newPropertyId, |
| 50 | + datavalue: { |
| 51 | + value: { |
| 52 | + 'entity-type': datatype, |
| 53 | + id: linkedEntityId, |
| 54 | + }, |
| 55 | + type: 'wikibase-entityid', |
| 56 | + }, |
| 57 | + datatype: 'wikibase-' + datatype, |
| 58 | + }, |
| 59 | + type: 'statement', |
| 60 | + rank: 'normal', |
| 61 | + } ], |
| 62 | + }; |
| 63 | + cy.task( 'MwApi:CreateItem', { |
| 64 | + label: Util.getTestString( 'item-with-' + datatype + '-statement' ), |
| 65 | + data: statementData, |
| 66 | + } ).then( ( newItemId: string ) => { |
| 67 | + entityId = newItemId; |
| 68 | + } ); |
| 69 | + } ); |
| 70 | + } ); |
| 71 | + |
| 72 | + beforeEach( () => { |
| 73 | + cy.viewport( 375, 1280 ); |
| 74 | + } ); |
| 75 | + |
| 76 | + it( 'displays item statement and supports full editing workflow', () => { |
| 77 | + const itemViewPage = new ItemViewPage( entityId ); |
| 78 | + itemViewPage.open().statementsSection(); |
| 79 | + checkA11y( ItemViewPage.STATEMENTS ); |
| 80 | + |
| 81 | + itemViewPage.editLinks().first().should( 'exist' ).should( 'be.visible' ); |
| 82 | + itemViewPage.editLinks().first().click(); |
| 83 | + |
| 84 | + const editFormPage = new EditStatementFormPage(); |
| 85 | + editFormPage.formHeading().should( 'exist' ); |
| 86 | + editFormPage.propertyName().should( 'have.text', propertyName ); |
| 87 | + |
| 88 | + editFormPage.lookupComponent() |
| 89 | + .should( 'exist' ).should( 'be.visible' ); |
| 90 | + |
| 91 | + editFormPage.lookupInput() |
| 92 | + .should( 'have.value', linkedEntityLabel ); |
| 93 | + |
| 94 | + editFormPage.lookupInput().clear(); |
| 95 | + editFormPage.lookupInput().type( newLinkedEntityLabel ); |
| 96 | + editFormPage.lookupInput().focus(); |
| 97 | + |
| 98 | + editFormPage.menu().should( 'be.visible' ); |
| 99 | + |
| 100 | + editFormPage.menuItems().first().click(); |
| 101 | + editFormPage.lookupInput().should( 'have.value', newLinkedEntityLabel ); |
| 102 | + |
| 103 | + editFormPage.publishButton().click(); |
| 104 | + |
| 105 | + /* Wait for the form to close, and check the value is changed */ |
| 106 | + editFormPage.formHeading().should( 'not.exist' ); |
| 107 | + itemViewPage.mainSnakValues().first().should( 'contain.text', newLinkedEntityLabel ); |
| 108 | + |
| 109 | + } ); |
| 110 | + } ); |
| 111 | + } |
| 112 | +} ); |
0 commit comments