Skip to content

Commit

Permalink
fix: respect namespace in url in single key view (#2291)
Browse files Browse the repository at this point in the history
  • Loading branch information
stepan662 committed Apr 29, 2024
1 parent 6346b5c commit f5c95ab
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 13 deletions.
21 changes: 15 additions & 6 deletions e2e/cypress/common/singleKey.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,22 @@
import { HOST } from './constants';

export const visitSingleKey = (
projectId: number,
keyName?: string,
languages?: string[]
) => {
type Props = {
projectId: number;
key?: string;
languages?: string[];
namespace?: string;
};

export const visitSingleKey = ({
projectId,
key,
languages,
namespace,
}: Props) => {
cy.visit(
`${HOST}/projects/${projectId}/translations/single?` +
(keyName ? `key=${keyName}&` : '') +
(key ? `key=${key}&` : '') +
(namespace ? `ns=${namespace}&` : '') +
(languages ? languages.map((l) => `languages=${l}&`).join('') : '')
);
return cy
Expand Down
35 changes: 34 additions & 1 deletion e2e/cypress/e2e/projects/settings.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,39 @@ describe('Projects Basics', () => {
expectDefaultNamespaceInModalCreation('test_namespace2');
});

it('default namespace works correctly with single key view', () => {
const key = 'test1';
const namespace = 'test_namespace1';
cy.visit(`${HOST}/projects/${projectId}/translations`);
createTranslation({ namespace, key, translation: 'In namespace' });
createTranslation({ key, translation: 'Without namespace' });

cy.visit(`${HOST}/projects/${projectId}/manage/edit`);
setDefaultNamespace(namespace);

visitSingleKey({ projectId, key, namespace, languages: ['en'] });

cy.gcy('namespaces-selector').contains(namespace).should('be.visible');
cy.gcy('translation-text').contains('In namespace').should('be.visible');

visitSingleKey({ projectId, key: key, languages: ['en'] });

cy.gcy('namespaces-selector').contains('<none>').should('be.visible');
cy.gcy('translation-text')
.contains('Without namespace')
.should('be.visible');

visitSingleKey({ projectId, key: 'new_key' });

cy.gcy('namespaces-selector').contains(namespace).should('be.visible');

visitSingleKey({ projectId, key: 'new_key', namespace: 'new_namespace' });

cy.gcy('namespaces-selector')
.contains('new_namespace')
.should('be.visible');
});

const setDefaultNamespace = (namespace: string) => {
cy.gcy('default-namespace-select').click();
cy.gcy('namespace-value').filter(`:contains("${namespace}")`).click();
Expand All @@ -109,7 +142,7 @@ describe('Projects Basics', () => {
};

const deleteNamespaceByDeletingAllKeys = (key: string) => {
visitSingleKey(projectId, key);
visitSingleKey({ projectId, key });
cy.gcy('translation-edit-delete-button').click();
cy.gcy('global-confirmation-confirm').click();
};
Expand Down
8 changes: 4 additions & 4 deletions e2e/cypress/e2e/translations/singleKeyForm.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ describe('Single key form', () => {

it("can't add key with TRANSLATE permissions", () => {
logInAs('jindra');
visitSingleKey(projectId, 'testkey');
visitSingleKey({ projectId, key: 'testkey' });
assertMessage('insufficient permissions');
});

Expand Down Expand Up @@ -70,7 +70,7 @@ describe('Single key form', () => {

// translation single view should take settings from localstorage
// but't not modify them
visitSingleKey(projectId, 'A key');
visitSingleKey({ projectId, key: 'A key' });
languageIsSelected('English');
languageIsNotSelected('Czech');
toggleLang('Czech');
Expand All @@ -97,7 +97,7 @@ describe('Single key form', () => {
}

function createKey() {
visitSingleKey(projectId, 'testkey', ['en']);
visitSingleKey({ projectId, key: 'testkey', languages: ['en'] });
cy.gcy('translation-field-label').contains('English').should('be.visible');
cy.gcy('translations-tag-input').type('cooltag');
cy.gcy('tag-autocomplete-option').contains('Add "cooltag"').click();
Expand All @@ -112,7 +112,7 @@ describe('Single key form', () => {
}

function visitEditKey() {
visitSingleKey(projectId, 'A key', ['en']);
visitSingleKey({ projectId, key: 'A key', languages: ['en'] });
}

function editKey() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ export const KeyCreateForm: React.FC<Props> = ({
const history = useHistory();

const keyName = useUrlSearch().key as string;
const namespace = project.defaultNamespace?.name;
const namespace =
(useUrlSearch().ns as string) ?? project.defaultNamespace?.name;

const createKey = useApiMutation({
url: '/v2/projects/{projectId}/keys/create',
Expand Down
2 changes: 1 addition & 1 deletion webapp/src/views/projects/translations/SingleKeyView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export const SingleKeyView = () => {
const project = useProject();
const keyId = Number(useUrlSearch().id as string);
const keyName = useUrlSearch().key as string;
const keyNamespace = project.defaultNamespace?.name;
const keyNamespace = useUrlSearch().ns as string;

return (
<TranslationsContextProvider
Expand Down

0 comments on commit f5c95ab

Please sign in to comment.