Skip to content
This repository was archived by the owner on Feb 25, 2024. It is now read-only.

Commit

Permalink
Only show controls when control=1 (#319)
Browse files Browse the repository at this point in the history
* only show controls when control=1

* Fix embed mode tests by latest changes

* ignore cypress screenshots
  • Loading branch information
farskid authored Nov 18, 2021
1 parent 452a9c8 commit 7e0c490
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 15 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,5 @@ yarn-error.log*
*.generated.*
public/monaco-editor
cypress/videos
cypress/screenshots
.next
28 changes: 16 additions & 12 deletions cypress/integration/embedded-mode.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,22 @@ createMachine({
};

describe('Embedded mode', () => {
describe('default controls', () => {
before(() => {
cy.interceptGraphQL({
getSourceFile: sourceFileFixture,
});
cy.visitEmbedWithNextPageProps({
sourceFile: sourceFileFixture,
controls: true,
});
});

it('RESET and fit_to_content button should be visible regardless of the mode only if constols is enabled', () => {
cy.getResetButton().should('be.visible');
cy.getFitToContentButton().should('be.visible');
});
});
describe('default (mode:viz)1', () => {
before(() => {
cy.interceptGraphQL({
Expand All @@ -32,10 +48,6 @@ describe('Embedded mode', () => {
it('canvas header should be hidden', () => {
cy.getCanvasHeader().should('not.exist');
});
it('RESET and fit_to_content should be visible', () => {
cy.getResetButton().should('be.visible');
cy.getFitToContentButton().should('be.visible');
});
});

describe('mode:panels', () => {
Expand All @@ -44,10 +56,6 @@ describe('Embedded mode', () => {
getSourceFile: sourceFileFixture,
});
});
it('RESET and fit_to_content should be visible', () => {
cy.getResetButton().should('be.visible');
cy.getFitToContentButton().should('be.visible');
});
it('should show panels view', () => {
cy.visitEmbedWithNextPageProps({
sourceFile: sourceFileFixture,
Expand Down Expand Up @@ -152,10 +160,6 @@ describe('Embedded mode', () => {
mode: EmbedMode.Full,
});
});
it('RESET and fit_to_content should be visible', () => {
cy.getResetButton().should('be.visible');
cy.getFitToContentButton().should('be.visible');
});
it('should show both canvas and panels', () => {
cy.getCanvasGraph().should('be.visible');
cy.getPanelsView().should('be.visible');
Expand Down
5 changes: 4 additions & 1 deletion cypress/support/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,9 @@ const visitEmbedWithNextPageProps = ({
searchParams.set('zoom', String(Number(zoom)));
}
if (typeof showOriginalLink === 'boolean') {
searchParams.set('showOriginalLink', String(Number(showOriginalLink)));
}
if (typeof controls === 'boolean') {
searchParams.set('controls', String(Number(controls)));
}
cy.visit(`${path}?${searchParams}`);
Expand Down Expand Up @@ -223,7 +226,7 @@ const getResizeHandle = () => {
};

const getResetButton = () => cy.findByText('RESET')
const getFitToContentButton = () => cy.findByLabelText('Fit to view')
const getFitToContentButton = () => cy.findByLabelText('Fit to content')

type DeepPartial<T> = T extends Function
? T
Expand Down
6 changes: 4 additions & 2 deletions src/CanvasView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ export const CanvasView: React.FC = () => {

const canShowWelcomeMessage = sourceState.hasTag('canShowWelcomeMessage');

const showControls = useMemo(() => !embed?.isEmbedded || embed.controls, [embed])

const showZoomButtonsInEmbed = useMemo(
() => !embed?.isEmbedded || (embed.controls && embed.zoom),
[embed],
Expand Down Expand Up @@ -104,7 +106,7 @@ export const CanvasView: React.FC = () => {
{isEmpty && canShowWelcomeMessage && <WelcomeArea />}
</CanvasContainer>

<Box
{showControls && <Box
display="flex"
flexDirection="row"
alignItems="center"
Expand Down Expand Up @@ -223,7 +225,7 @@ export const CanvasView: React.FC = () => {
</Portal>
</Menu>
)}
</Box>
</Box>}
</Box>
);
};

0 comments on commit 7e0c490

Please sign in to comment.