Skip to content

Commit

Permalink
QA-15259 Use ce language if ctx not available (#1748)
Browse files Browse the repository at this point in the history
* QA-15259 Use ce language if ctx not available

* QA-15259 Fix test
  • Loading branch information
AKarmanov authored Sep 5, 2024
1 parent bc1dd9e commit 961aebc
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,13 @@ import {Constants} from '~/ContentEditor.constants';
import {useContentEditorContext} from '~/contexts';
import {useQuery} from '@apollo/react-hooks';
import {OpenInTabActionQuery} from '~/SelectorTypes/Picker/actions/openInTabAction.gql-queries';
import {useSelector} from 'react-redux';

export const OpenInTabActionComponent = ({render: Render, loading: Loading, path, field, inputContext, ...others}) => {
const {lang} = useContentEditorContext();
const {ceLang} = useSelector(state => ({
ceLang: state.contenteditor.ceLanguage
}));

let uuid;
if (path === undefined) {
Expand All @@ -31,7 +35,7 @@ export const OpenInTabActionComponent = ({render: Render, loading: Loading, path
<Render
{...others}
onClick={() => {
window.open(`${window.contextJsParameters.urlbase}/${Constants.appName}/${lang}/${Constants.routes.baseEditRoute}/${uuid}`, '_blank');
window.open(`${window.contextJsParameters.urlbase}/${Constants.appName}/${lang ? lang : ceLang}/${Constants.routes.baseEditRoute}/${uuid}`, '_blank');
}}
/>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {shallow} from '@jahia/test-framework';
import React from 'react';
import {setQueryResponseMock} from '@apollo/react-hooks';
import {useContentEditorContext} from '~/contexts';
import {useSelector} from 'react-redux';

jest.mock('@apollo/react-hooks', () => {
let queryresponsemock;
Expand All @@ -17,9 +18,25 @@ jest.mock('@apollo/react-hooks', () => {

jest.mock('~/contexts/ContentEditor/ContentEditor.context');

jest.mock('react-redux', () => ({
useSelector: jest.fn()
}));

const button = () => <button type="button"/>;

describe('openInTab action', () => {
beforeEach(() => {
useSelector.mockImplementation(callback => callback({
contenteditor: {
ceLang: 'fr'
}
}));
});

afterEach(() => {
useSelector.mockClear();
});

it('should open in new tab on click', () => {
window.open = jest.fn();

Expand Down

0 comments on commit 961aebc

Please sign in to comment.