Skip to content

Commit

Permalink
#30726 add computed property: isDefaultVariant
Browse files Browse the repository at this point in the history
  • Loading branch information
valentinogiardino committed Dec 20, 2024
1 parent 2f636df commit 18c7ea7
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ export interface ToolbarProps {
bookmarksUrl: string;
copyUrl: string;
apiUrl: string;
isDefaultVariant: boolean;
showInfoDisplay: boolean;
currentLanguage: DotLanguage;
runningExperiment?: DotExperiment;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,10 @@ export function withEditorToolbar() {
inode: pageAPIResponse?.page.inode,
loading: store.status() === UVE_STATUS.LOADING
};
const isDefaultVariant = getIsDefaultVariant(pageAPIResponse?.viewAs.variantId);

const shouldShowInfoDisplay =
!getIsDefaultVariant(pageAPIResponse?.viewAs.variantId) ||
!isDefaultVariant ||
!store.canEditPage() ||
isPageLocked ||
!!store.device() ||
Expand All @@ -94,6 +95,7 @@ export function withEditorToolbar() {
runningExperiment: isExperimentRunning ? experiment : null,
workflowActionsInode: store.canEditPage() ? pageAPIResponse?.page.inode : null,
unlockButton: shouldShowUnlock ? unlockButton : null,
isDefaultVariant,
showInfoDisplay: shouldShowInfoDisplay,
deviceSelector: {
apiLink: `${clientHost}${pageAPI}`,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ describe('withEditor', () => {
value: MOCK_RESPONSE_HEADLESS.viewAs.persona ?? DEFAULT_PERSONA
},
runningExperiment: null,
isDefaultVariant: true,
showInfoDisplay: false,
unlockButton: null,
urlContentMap: null,
Expand Down Expand Up @@ -331,6 +332,35 @@ describe('withEditor', () => {
expect(store.$toolbarProps().showInfoDisplay).toBe(false);
});
});

describe('isDefaultVariant', () => {
it('should have isDefaultVariant as true if the page variant is default', () => {
patchState(store, {
pageAPIResponse: {
...MOCK_RESPONSE_HEADLESS,
viewAs: {
...MOCK_RESPONSE_HEADLESS.viewAs,
variantId: DEFAULT_VARIANT_ID
}
}
});

expect(store.$toolbarProps().isDefaultVariant).toBe(true);
});
it('should have isDefaultVariant as false if the page is a variant different from default', () => {
patchState(store, {
pageAPIResponse: {
...MOCK_RESPONSE_HEADLESS,
viewAs: {
...MOCK_RESPONSE_HEADLESS.viewAs,
variantId: 'test'
}
}
});

expect(store.$toolbarProps().isDefaultVariant).toBe(false);
});
});
});

describe('$infoDisplayOptions', () => {
Expand Down

0 comments on commit 18c7ea7

Please sign in to comment.