-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
…8353) * introduce empty sidebarPanelTheme spec file * introduce sidebar theme test * add steps for opening the sidebar * finish failing test with green assertions * replace StylesheetsContext * replace StylesheetsContext provider and hooks usage * fix lint errors and add StylesheetsContext to strictnull * replace ephemeralformcontent logic * fix strict null error
- Loading branch information
Showing
7 changed files
with
220 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/* | ||
* Copyright (C) 2024 PixieBrix, Inc. | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
import { test, expect } from "../../fixtures/extensionBase"; | ||
import { ActivateModPage } from "../../pageObjects/extensionConsole/modsPage"; | ||
import { getSidebarPage, runModViaQuickBar } from "../../utils"; | ||
import type { Page } from "@playwright/test"; | ||
|
||
test("custom sidebar theme css file is applied to all levels of sidebar document", async ({ | ||
page, | ||
extensionId, | ||
}) => { | ||
const modId = "@pixies/testing/panel-theme"; | ||
|
||
const modActivationPage = new ActivateModPage(page, extensionId, modId); | ||
await modActivationPage.goto(); | ||
|
||
await modActivationPage.clickActivateAndWaitForModsPageRedirect(); | ||
|
||
await page.goto("/"); | ||
|
||
// Ensure the page is focused by clicking on an element before running the keyboard shortcut, see runModViaQuickbar | ||
await page.getByText("Index of /").click(); | ||
await runModViaQuickBar(page, "Show Sidebar"); | ||
|
||
const sidebarPage = (await getSidebarPage(page, extensionId)) as Page; | ||
await expect( | ||
sidebarPage.getByText("#8347: Theme Inheritance", { exact: true }), | ||
).toBeVisible(); | ||
|
||
const green = "rgb(0, 128, 0)"; | ||
const elementsThatShouldBeGreen = await sidebarPage | ||
.getByText("This should be green") | ||
.all(); | ||
await Promise.all( | ||
elementsThatShouldBeGreen.map(async (element) => | ||
expect(element).toHaveCSS("color", green), | ||
), | ||
); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
/* | ||
* Copyright (C) 2024 PixieBrix, Inc. | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
import React, { useContext } from "react"; | ||
import bootstrap from "@/vendors/bootstrapWithoutRem.css?loadAsUrl"; | ||
import bootstrapOverrides from "@/sidebar/sidebarBootstrapOverrides.scss?loadAsUrl"; | ||
import custom from "@/bricks/renderers/customForm.css?loadAsUrl"; | ||
|
||
export type StylesheetsContextType = { | ||
stylesheets: string[] | null; | ||
}; | ||
|
||
const StylesheetsContext = React.createContext<StylesheetsContextType>({ | ||
stylesheets: null, | ||
}); | ||
|
||
function useStylesheetsContextWithDefaultValues({ | ||
newStylesheets, | ||
defaultStylesheets, | ||
disableParentStyles, | ||
}: { | ||
newStylesheets: string[] | undefined; | ||
defaultStylesheets: string[]; | ||
disableParentStyles: boolean; | ||
}): { | ||
stylesheets: string[]; | ||
} { | ||
const { stylesheets: inheritedStylesheets } = useContext(StylesheetsContext); | ||
|
||
const stylesheets: string[] = []; | ||
|
||
if (!disableParentStyles) { | ||
if (inheritedStylesheets == null) { | ||
stylesheets.push(...defaultStylesheets); | ||
} else { | ||
stylesheets.push(...inheritedStylesheets); | ||
} | ||
} | ||
|
||
if (newStylesheets != null) { | ||
stylesheets.push(...newStylesheets); | ||
} | ||
|
||
return { stylesheets }; | ||
} | ||
|
||
export function useStylesheetsContextWithDocumentDefault({ | ||
newStylesheets, | ||
disableParentStyles, | ||
}: { | ||
newStylesheets: string[] | undefined; | ||
disableParentStyles: boolean; | ||
}): { | ||
stylesheets: string[]; | ||
} { | ||
return useStylesheetsContextWithDefaultValues({ | ||
newStylesheets, | ||
defaultStylesheets: [ | ||
bootstrap, | ||
bootstrapOverrides, | ||
// DocumentView.css is an artifact produced by webpack, see the DocumentView entrypoint included in | ||
// `webpack.config.mjs`. We build styles needed to render documents separately from the rest of the sidebar | ||
// in order to isolate the rendered document from the custom Bootstrap theme included in the Sidebar app | ||
"/DocumentView.css", | ||
// Required because it can be nested in the DocumentView. | ||
"/CustomFormComponent.css", | ||
], | ||
disableParentStyles, | ||
}); | ||
} | ||
|
||
export function useStylesheetsContextWithFormDefault({ | ||
newStylesheets, | ||
disableParentStyles, | ||
}: { | ||
newStylesheets: string[] | undefined; | ||
disableParentStyles: boolean; | ||
}): { | ||
stylesheets: string[]; | ||
} { | ||
return useStylesheetsContextWithDefaultValues({ | ||
newStylesheets, | ||
defaultStylesheets: [ | ||
bootstrap, | ||
bootstrapOverrides, | ||
// CustomFormComponent.css and EphemeralFormContent.css are artifacts produced by webpack, see the entrypoints. | ||
"/EphemeralFormContent.css", | ||
"/CustomFormComponent.css", | ||
custom, | ||
], | ||
disableParentStyles, | ||
}); | ||
} | ||
|
||
export default StylesheetsContext; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters