Skip to content

Commit

Permalink
Merge branch 'main' into feature/images-format
Browse files Browse the repository at this point in the history
  • Loading branch information
HugoVS26 authored Nov 3, 2023
2 parents 31b4ba0 + feb75c3 commit 03b08a1
Show file tree
Hide file tree
Showing 9 changed files with 75 additions and 8 deletions.
Binary file added public/images/logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
28 changes: 28 additions & 0 deletions src/components/Loading/Loading.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { render, screen } from "@testing-library/react";
import Loading from "./Loading";
import { ThemeProvider } from "styled-components";
import mainTheme from "../../styles/mainTheme";
import { BrowserRouter } from "react-router-dom";
import UiContextWrapper from "../../features/Ui/store/UiContextWrapper";

describe("Given a Loading component", () => {
describe("When is render", () => {
test("Then it should show `logo loading page`", () => {
const expectedAltText = "logo loading page";
const expectedImageSrc = "public/images/logo.png";

render(
<BrowserRouter>
<UiContextWrapper>
<ThemeProvider theme={mainTheme}>
<Loading />
</ThemeProvider>
</UiContextWrapper>
</BrowserRouter>,
);

const loadImage = screen.getByAltText(expectedAltText);
expect(loadImage).toHaveAttribute("src", expectedImageSrc);
});
});
});
9 changes: 9 additions & 0 deletions src/components/Loading/Loading.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const Loading = (): React.ReactElement => {
return (
<div>
<img src="public/images/logo.png" alt="logo loading page"></img>
</div>
);
};

export default Loading;
6 changes: 6 additions & 0 deletions src/features/Ui/store/UiContext.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { createContext } from "react";
import UiContextStructure from "./types";

const UiContext = createContext<UiContextStructure>({} as UiContextStructure);

export default UiContext;
13 changes: 13 additions & 0 deletions src/features/Ui/store/UiContextWrapper.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import UiContext from "./UiContext";
import { PropsWithChildren, useMemo, useState } from "react";

const UiContextWrapper = ({
children,
}: PropsWithChildren): React.ReactElement => {
const [isLoading, setIsLoading] = useState<boolean>(false);
const uiValue = useMemo(() => ({ isLoading, setIsLoading }), [isLoading]);

return <UiContext.Provider value={uiValue}>{children}</UiContext.Provider>;
};

export default UiContextWrapper;
6 changes: 6 additions & 0 deletions src/features/Ui/store/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
interface UiContextStructure {
isLoading: boolean;
setIsLoading: (isLoading: boolean) => void;
}

export default UiContextStructure;
19 changes: 11 additions & 8 deletions src/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,19 @@ import mainTheme from "./styles/mainTheme";
import CharacarterWrapper from "./features/characters/store/CharactersWrapper";
import GlobalStyle from "./styles/GlobalStyle";
import "@fontsource-variable/changa";
import UiContextWrapper from "./features/Ui/store/UiContextWrapper";

ReactDOM.createRoot(document.getElementById("root")!).render(
<React.StrictMode>
<CharacarterWrapper>
<ThemeProvider theme={mainTheme}>
<BrowserRouter>
<GlobalStyle />
<App />
</BrowserRouter>
</ThemeProvider>
</CharacarterWrapper>
<UiContextWrapper>
<CharacarterWrapper>
<ThemeProvider theme={mainTheme}>
<BrowserRouter>
<GlobalStyle />
<App />
</BrowserRouter>
</ThemeProvider>
</CharacarterWrapper>
</UiContextWrapper>
</React.StrictMode>,
);
1 change: 1 addition & 0 deletions src/styles/mainTheme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const mainTheme: DefaultTheme = {
mainFont: "#000",
secondaryFont: "#fff",
inputBackground: "#fff",
logoMain: "#FF000",
},
typography: {
mainFontFamily: "Verdana, Geneva, Tahoma, sans-serif",
Expand Down
1 change: 1 addition & 0 deletions src/styles/styled.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ declare module "styled-components" {
mainFont: string;
secondaryFont: string;
inputBackground: string;
logoMain: string;
};
typography: {
mainFontFamily: string;
Expand Down

0 comments on commit 03b08a1

Please sign in to comment.