|
| 1 | +import { Util } from 'cypress-wikibase-api'; |
| 2 | + |
| 3 | +import { EditStatementFormPage } from '../../support/pageObjects/EditStatementFormPage'; |
| 4 | +import { ItemViewPage } from '../../support/pageObjects/ItemViewPage'; |
| 5 | +import { LoginPage } from '../../support/pageObjects/LoginPage'; |
| 6 | +import { ValueForm } from '../../support/pageObjects/ValueForm'; |
| 7 | + |
| 8 | +describe( 'wbui2025 edit references', () => { |
| 9 | + context( 'mobile view', () => { |
| 10 | + const snakToDelete = 'single snak to delete'; |
| 11 | + |
| 12 | + beforeEach( () => { |
| 13 | + const loginPage = new LoginPage(); |
| 14 | + cy.task( |
| 15 | + 'MwApi:CreateUser', |
| 16 | + { usernamePrefix: 'mextest' }, |
| 17 | + ).then( ( { username, password } ) => { |
| 18 | + loginPage.login( username, password ); |
| 19 | + } ); |
| 20 | + |
| 21 | + cy.task( 'MwApi:GetOrCreatePropertyIdByDataType', { datatype: 'string' } ) |
| 22 | + .then( ( propertyId: string ) => { |
| 23 | + cy.wrap( propertyId ).as( 'propertyId' ); |
| 24 | + const statementData = { |
| 25 | + claims: [ { |
| 26 | + mainsnak: { |
| 27 | + snaktype: 'value', |
| 28 | + property: propertyId, |
| 29 | + datavalue: { |
| 30 | + value: 'example string value', |
| 31 | + type: 'string', |
| 32 | + }, |
| 33 | + }, |
| 34 | + type: 'statement', |
| 35 | + rank: 'normal', |
| 36 | + } ], |
| 37 | + }; |
| 38 | + cy.task( 'MwApi:CreateItem', { label: Util.getTestString( 'item' ), data: statementData } ) |
| 39 | + .then( ( itemId: string ) => { |
| 40 | + cy.wrap( itemId ).as( 'itemId' ); |
| 41 | + } ); |
| 42 | + cy.get( '@itemId' ).then( ( itemId ) => { |
| 43 | + cy.task( 'MwApi:GetEntityData', { entityId: itemId } ).then( ( data ) => { |
| 44 | + const snaks1 = { |
| 45 | + [ propertyId ]: [ { |
| 46 | + snaktype: 'value', |
| 47 | + property: propertyId, |
| 48 | + datavalue: { |
| 49 | + value: snakToDelete, |
| 50 | + type: 'string', |
| 51 | + }, |
| 52 | + datatype: 'string', |
| 53 | + } ], |
| 54 | + }; |
| 55 | + |
| 56 | + const snaks2 = { |
| 57 | + [ propertyId ]: [ |
| 58 | + { |
| 59 | + snaktype: 'value', |
| 60 | + property: propertyId, |
| 61 | + datavalue: { |
| 62 | + value: 'first snak', |
| 63 | + type: 'string', |
| 64 | + }, |
| 65 | + datatype: 'string', |
| 66 | + }, { |
| 67 | + snaktype: 'value', |
| 68 | + property: propertyId, |
| 69 | + datavalue: { |
| 70 | + value: 'second snak', |
| 71 | + type: 'string', |
| 72 | + }, |
| 73 | + datatype: 'string', |
| 74 | + }, |
| 75 | + ], |
| 76 | + }; |
| 77 | + |
| 78 | + cy.task( 'MwApi:BotRequest', { |
| 79 | + isEdit: true, |
| 80 | + isPost: true, |
| 81 | + parameters: { |
| 82 | + action: 'wbsetreference', |
| 83 | + statement: data.claims[ propertyId ][ 0 ].id, |
| 84 | + snaks: JSON.stringify( snaks1 ), |
| 85 | + }, |
| 86 | + } ); |
| 87 | + cy.task( 'MwApi:BotRequest', { |
| 88 | + isEdit: true, |
| 89 | + isPost: true, |
| 90 | + parameters: { |
| 91 | + action: 'wbsetreference', |
| 92 | + statement: data.claims[ propertyId ][ 0 ].id, |
| 93 | + snaks: JSON.stringify( snaks2 ), |
| 94 | + }, |
| 95 | + } ); |
| 96 | + } ); |
| 97 | + } ); |
| 98 | + } ); |
| 99 | + cy.viewport( 375, 1280 ); |
| 100 | + } ); |
| 101 | + it( 'references are editable and deletable', () => { |
| 102 | + cy.get( '@itemId' ).then( ( itemId ) => { |
| 103 | + const itemViewPage = new ItemViewPage( itemId ); |
| 104 | + itemViewPage.open().statementsSection(); |
| 105 | + itemViewPage.editLinks().first().click(); |
| 106 | + const editFormPage = new EditStatementFormPage(); |
| 107 | + editFormPage.referencesAccordion().click(); |
| 108 | + |
| 109 | + editFormPage.references().should( 'have.length', 2 ); |
| 110 | + |
| 111 | + const editedSnakValue = Util.getTestString( 'edited-snak' ); |
| 112 | + editFormPage.valueForms().first().within( () => { |
| 113 | + editFormPage.references().eq( 1 ).within( ( element ) => { |
| 114 | + const valueForm = new ValueForm( element ); |
| 115 | + valueForm.textInput().first().type( '{selectAll}{backspace}' + editedSnakValue ); |
| 116 | + } ); |
| 117 | + |
| 118 | + editFormPage.references().first().within( ( element ) => { |
| 119 | + ( new ValueForm( element ) ).removeSnakButton().first().click(); |
| 120 | + } ); |
| 121 | + } ); |
| 122 | + |
| 123 | + editFormPage.publishButton().click(); |
| 124 | + |
| 125 | + // Verify the edits |
| 126 | + editFormPage.valueForms().should( 'not.exist' ); |
| 127 | + itemViewPage.referencesSections().first().then( ( element ) => { |
| 128 | + itemViewPage.referencesAccordion( element ).click(); |
| 129 | + itemViewPage.references( element ).should( 'have.length', 1 ); |
| 130 | + itemViewPage.references( element ).should( 'not.contain.text', snakToDelete ); |
| 131 | + itemViewPage.references( element ).should( 'contain.text', editedSnakValue ); |
| 132 | + } ); |
| 133 | + |
| 134 | + cy.task( 'MwApi:GetEntityData', { entityId: itemId } ).then( ( data ) => { |
| 135 | + cy.get( '@propertyId' ).then( ( propertyId ) => { |
| 136 | + cy.wrap( data.claims[ propertyId ][ 0 ].references ) |
| 137 | + .should( 'have.length', 1 ); |
| 138 | + cy.wrap( data.claims[ propertyId ][ 0 ].references[ 0 ].snaks[ propertyId ] ) |
| 139 | + .should( 'have.length', 2 ); |
| 140 | + } ); |
| 141 | + } ); |
| 142 | + |
| 143 | + // Edit again, delete the reference with 2 snaks |
| 144 | + itemViewPage.editLinks().first().click(); |
| 145 | + editFormPage.referencesAccordion().click(); |
| 146 | + editFormPage.references().should( 'have.length', 1 ); |
| 147 | + editFormPage.valueForms().first().then( ( element: HTMLElement ) => { |
| 148 | + const valueForm = new ValueForm( element ); |
| 149 | + editFormPage.references().first().within( () => { |
| 150 | + valueForm.removeReferenceButton().click(); |
| 151 | + } ); |
| 152 | + } ); |
| 153 | + |
| 154 | + editFormPage.publishButton().click(); |
| 155 | + |
| 156 | + // Verify the edits |
| 157 | + editFormPage.valueForms().should( 'not.exist' ); |
| 158 | + itemViewPage.statementsSection().should( 'contain.text', '0 references' ); |
| 159 | + |
| 160 | + cy.task( 'MwApi:GetEntityData', { entityId: itemId } ).then( ( data ) => { |
| 161 | + cy.get( '@propertyId' ).then( ( propertyId ) => { |
| 162 | + cy.wrap( data.claims[ propertyId ][ 0 ].references ).should( 'be.undefined' ); |
| 163 | + } ); |
| 164 | + } ); |
| 165 | + |
| 166 | + } ); |
| 167 | + } ); |
| 168 | + } ); |
| 169 | +} ); |
0 commit comments