Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New datepicker #148

Merged
merged 12 commits into from
Dec 20, 2023
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,11 @@ yarn-error.log*
dist
.env
build-storybook.log
/test-results/
/playwright-report/
/blob-report/
/playwright/.cache/
/test-results/
/playwright-report/
/blob-report/
/playwright/.cache/
2,942 changes: 2,625 additions & 317 deletions package-lock.json

Large diffs are not rendered by default.

6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
"release": "npx auto shipit --base-branch=main",
"storybook": "start-storybook -p 6006 -s public",
"build-storybook": "build-storybook -s public",
"test": "react-scripts test"
"test": "react-scripts test",
"test-ct": "playwright test -c playwright-ct.config.ts"
},
"eslintConfig": {
"extends": [
Expand Down Expand Up @@ -59,6 +60,8 @@
"devDependencies": {
"@babel/cli": "^7.14.3",
"@babel/preset-typescript": "^7.14.5",
"@playwright/experimental-ct-react17": "^1.40.1",
"@playwright/test": "^1.40.1",
"@rollup/plugin-image": "^2.1.1",
"@storybook/addon-actions": "^6.2.9",
"@storybook/addon-essentials": "^6.2.9",
Expand All @@ -79,6 +82,7 @@
"@types/react-transition-group": "^4.4.1",
"@types/styled-components": "^5.1.10",
"auto": "^10.29.2",
"babel-loader": "^8.1.0",
"chromatic": "^5.9.0",
"copyfiles": "^2.4.1",
"cross-env": "^7.0.3",
Expand Down
46 changes: 46 additions & 0 deletions playwright-ct.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import { defineConfig, devices } from "@playwright/experimental-ct-react17";

/**
* See https://playwright.dev/docs/test-configuration.
*/
export default defineConfig({
testDir: "./",
/* The base directory, relative to the config file, for snapshot files created with toMatchSnapshot and toHaveScreenshot. */
snapshotDir: "./__snapshots__",
/* Maximum time one test can run for. */
timeout: 10 * 1000,
/* Run tests in files in parallel */
fullyParallel: true,
/* Fail the build on CI if you accidentally left test.only in the source code. */
forbidOnly: !!process.env.CI,
/* Retry on CI only */
retries: process.env.CI ? 2 : 0,
/* Opt out of parallel tests on CI. */
workers: process.env.CI ? 1 : undefined,
/* Reporter to use. See https://playwright.dev/docs/test-reporters */
reporter: "html",
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
use: {
/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
trace: "on-first-retry",

/* Port to use for Playwright component endpoint. */
ctPort: 3100,
},

/* Configure projects for major browsers */
projects: [
{
name: "chromium",
use: { ...devices["Desktop Chrome"] },
},
{
name: "firefox",
use: { ...devices["Desktop Firefox"] },
},
{
name: "webkit",
use: { ...devices["Desktop Safari"] },
},
],
});
12 changes: 12 additions & 0 deletions playwright/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Testing Page</title>
</head>
<body>
<div id="root"></div>
<script type="module" src="./index.tsx"></script>
</body>
</html>
16 changes: 16 additions & 0 deletions playwright/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Import styles, initialize component theme here.
// import '../src/common.css';
import React from "react";
import { beforeMount } from "@playwright/experimental-ct-react17/hooks";
import GlobalStyle from "../src/shared/globalStyle";
import { ThemeProvider } from "styled-components";
import { aqBootstrapTheme } from "../src/stories/theme/defaultTheme";

beforeMount(async ({ App }) => {
return (
<ThemeProvider theme={aqBootstrapTheme}>
<GlobalStyle />
<App />
</ThemeProvider>
);
});
18 changes: 18 additions & 0 deletions src/stories/DateInput/DateInput.spec.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { test, expect } from "@playwright/experimental-ct-react17";
import DateInput from ".";

test.describe("DateInput", () => {
test("should render an input tag and a button to open a datepicker", async ({
page,
mount,
}) => {
const component = await mount(<DateInput id="datepicker" />);
component.locator("input").click();
expect(component).toBeTruthy();
});
test("should print a placeholder if any", async ({ page, mount }) => {});
test("should accept a date in a specific format", async ({
page,
mount,
}) => {});
});
22 changes: 22 additions & 0 deletions src/stories/DateInput/DateInput.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import DateInput from ".";
import { Story, Meta } from "@storybook/react";
import { DatepickerGlobalStyle } from "./_style";

export default {
title: "Inputs/DateInput",
component: DateInput,
} as Meta;

const DatepickerTemplate: Story = (args) => (
<>
<DatepickerGlobalStyle />
<h2>Seleziona una data nel formato gg-mm-aaaa</h2>
<DateInput {...args} id="test1" i18n={{ placeholder: "28-03-2013" }} />
</>
);
export const DatepickerInput = DatepickerTemplate.bind({});
DatepickerInput.args = {
onChange: ({ value }: { value: Date }) => {
console.log(value);
},
};
Loading
Loading