Skip to content

Commit

Permalink
chore: Fix more E2E tests
Browse files Browse the repository at this point in the history
  • Loading branch information
JanCizmar committed Jan 29, 2025
1 parent 1e1743a commit c5eb197
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 5 deletions.
4 changes: 2 additions & 2 deletions e2e/cypress/common/permissions/keys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { waitForGlobalLoading } from '../loading';
import { confirmStandard } from '../shared';
import { getCell } from '../state';
import { createTag } from '../tags';
import { createTranslation, editCell } from '../translations';
import { createTranslation, editKeyName } from '../translations';
import { getLanguageId, getLanguages, ProjectInfo } from './shared';

export function testKeys(info: ProjectInfo) {
Expand All @@ -30,7 +30,7 @@ export function testKeys(info: ProjectInfo) {
cy.focused().type('{esc}', { force: true });

if (scopes.includes('keys.edit')) {
editCell('key-1', 'new-key');
editKeyName('key-1', 'new-key');
createTag('Test tag');
}

Expand Down
33 changes: 30 additions & 3 deletions e2e/cypress/common/translations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
import { HOST } from './constants';
import { ProjectDTO } from '../../../webapp/src/service/response.types';
import { waitForGlobalLoading } from './loading';
import { assertMessage, dismissMenu, gcyAdvanced } from './shared';
import { assertMessage, dismissMenu, gcy, gcyAdvanced } from './shared';
import { selectNamespace } from './namespace';
import { buildXpath } from './XpathBuilder';
import Chainable = Cypress.Chainable;
Expand Down Expand Up @@ -127,6 +127,25 @@ export const visitTranslations = (projectId: number) => {
return cy.visit(`${HOST}/projects/${projectId}/translations`);
};

export const editKeyName = (keyName: string, newName?: string) => {
getKeyCell(keyName).click();

// wait for editor to appear
cy.gcy('global-editor').should('be.visible');
cy.contains(keyName).first().should('be.visible');
cy.wait(10);

if (newName !== undefined) {
// select all, delete and type new text
gcy('translations-key-edit-key-field')
.find('[contenteditable]')
.clear()
.type(newName);
getCellSaveButton().click();
waitForGlobalLoading();
}
};

export const editCell = (oldValue: string, newValue?: string, save = true) => {
getCell(oldValue).click();

Expand Down Expand Up @@ -155,12 +174,20 @@ export function getTranslationEditor() {
.getElement();
}

export function getTranslationCell(key: string, languageTag: string) {
function getKeyCellXpath(key: string) {
return buildXpath()
.descendant()
.withDataCy('translations-key-name')
.descendantOrSelf()
.hasText(key)
.hasText(key);
}

function getKeyCell(key: string) {
return getKeyCellXpath(key).getElement();
}

export function getTranslationCell(key: string, languageTag: string) {
return getKeyCellXpath(key)
.closestAncestor()
.withDataCy('translations-row')
.descendant()
Expand Down

0 comments on commit c5eb197

Please sign in to comment.