|
| 1 | +import { Util } from 'cypress-wikibase-api'; |
| 2 | +import { EditStatementFormPage } from '../../support/pageObjects/EditStatementFormPage'; |
| 3 | +import { ItemViewPage } from '../../support/pageObjects/ItemViewPage'; |
| 4 | + |
| 5 | +// RTL functionality and layout checks (see: T403013). |
| 6 | +describe( 'wbui2025 language preferences and RTL functionality', () => { |
| 7 | + context( 'mobile view', () => { |
| 8 | + let propertyName: string; |
| 9 | + let itemId: string; |
| 10 | + |
| 11 | + const SELECTED_LANGUAGE = 'ar'; |
| 12 | + |
| 13 | + before( () => { |
| 14 | + cy.viewport( 375, 1280 ); |
| 15 | + |
| 16 | + // Note: Test data uses Arabic text. |
| 17 | + propertyName = Util.getTestString( 'خاصية' ); |
| 18 | + cy.task( 'MwApi:CreateProperty', { |
| 19 | + label: { |
| 20 | + [ SELECTED_LANGUAGE ]: { language: SELECTED_LANGUAGE, value: propertyName }, |
| 21 | + }, |
| 22 | + data: { datatype: 'string' }, |
| 23 | + } ).then( ( newPropertyId: string ) => { |
| 24 | + const statementData = { |
| 25 | + claims: [ { |
| 26 | + mainsnak: { |
| 27 | + snaktype: 'value', |
| 28 | + property: newPropertyId, |
| 29 | + datavalue: { |
| 30 | + value: 'مثال نصي', |
| 31 | + type: 'string', |
| 32 | + }, |
| 33 | + }, |
| 34 | + type: 'statement', |
| 35 | + rank: 'normal', |
| 36 | + } ], |
| 37 | + }; |
| 38 | + cy.task( 'MwApi:CreateItem', { |
| 39 | + label: { |
| 40 | + [ SELECTED_LANGUAGE ]: { |
| 41 | + language: SELECTED_LANGUAGE, |
| 42 | + value: Util.getTestString( 'مثال لعنصر بالعربي' ), |
| 43 | + }, |
| 44 | + }, |
| 45 | + data: statementData, |
| 46 | + } ).then( ( newItemId: string ) => { |
| 47 | + itemId = newItemId; |
| 48 | + } ); |
| 49 | + } ); |
| 50 | + } ); |
| 51 | + |
| 52 | + beforeEach( () => { |
| 53 | + cy.viewport( 375, 1280 ); |
| 54 | + } ); |
| 55 | + |
| 56 | + it.only( 'Checking RTL layout when editing statements', () => { |
| 57 | + const itemViewPage = new ItemViewPage( itemId ); |
| 58 | + const editFormPage = new EditStatementFormPage(); |
| 59 | + |
| 60 | + itemViewPage.open( SELECTED_LANGUAGE ); |
| 61 | + |
| 62 | + // Verify RTL layout is maintained |
| 63 | + cy.get( 'html' ).should( 'have.attr', 'dir', 'rtl' ); |
| 64 | + cy.get( 'html' ).should( 'have.attr', 'lang', SELECTED_LANGUAGE ); |
| 65 | + |
| 66 | + itemViewPage.statementsSection(); |
| 67 | + |
| 68 | + // Check if edit links exist and are clickable |
| 69 | + itemViewPage.editLinks().then( ( $links ) => { |
| 70 | + if ( $links.length > 0 ) { |
| 71 | + cy.wrap( $links.first() ).click(); |
| 72 | + |
| 73 | + // Verify RTL is maintained in edit mode |
| 74 | + cy.get( 'html' ).should( 'have.attr', 'dir', 'rtl' ); |
| 75 | + cy.get( 'html' ).should( 'have.attr', 'lang', SELECTED_LANGUAGE ); |
| 76 | + |
| 77 | + editFormPage.textInput() |
| 78 | + .should( 'be.visible' ) |
| 79 | + .should( 'have.value', 'مثال نصي' ); |
| 80 | + |
| 81 | + editFormPage.formHeading() |
| 82 | + .find( '.cdx-icon--flipped' ) |
| 83 | + .should( 'exist' ) |
| 84 | + .should( 'be.visible' ); |
| 85 | + |
| 86 | + editFormPage.formHeading() |
| 87 | + .find( '.cdx-icon--flipped' ) |
| 88 | + .then( ( $el ) => { |
| 89 | + const comp = getComputedStyle( $el[ 0 ] ); |
| 90 | + expect( parseFloat( comp.marginRight ) ).to.be.equal( 0 ); |
| 91 | + } ); |
| 92 | + |
| 93 | + editFormPage.cancelButton() |
| 94 | + .invoke( 'text' ) |
| 95 | + .should( 'match', /[\u0600-\u06FF]/ ); |
| 96 | + |
| 97 | + editFormPage.publishButton().then( ( $btn ) => { |
| 98 | + const { left, right } = $btn[ 0 ].getBoundingClientRect(); |
| 99 | + // In RTL, "end" is left; button should be closer to left than right padding. |
| 100 | + expect( left ).to.be.lessThan( right ); |
| 101 | + } ); |
| 102 | + } |
| 103 | + } ); |
| 104 | + } ); |
| 105 | + } ); |
| 106 | +} ); |
0 commit comments