Skip to content

Commit

Permalink
autosolver test added
Browse files Browse the repository at this point in the history
  • Loading branch information
emrergin committed Apr 16, 2024
1 parent 7af53d5 commit b5a42c9
Show file tree
Hide file tree
Showing 8 changed files with 189 additions and 10 deletions.
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,8 @@ yarn-error.log*
next-env.d.ts

exporting.*
buildDate.*
buildDate.*
/test-results/
/playwright-report/
/blob-report/
/playwright/.cache/
60 changes: 60 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"scripts": {
"dev": "next dev",
"build": "next build",
"buildfordeploy":"prisma generate && next build",
"buildfordeploy": "prisma generate && next build",
"start": "next start",
"lint": "next lint",
"format": "npx prettier ./src -w"
Expand Down Expand Up @@ -36,6 +36,7 @@
"typescript": "4.9.5"
},
"devDependencies": {
"@playwright/test": "^1.43.1",
"prettier": "3.0.3",
"prisma": "^4.11.0"
}
Expand Down
85 changes: 85 additions & 0 deletions playwright.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
import { defineConfig, devices } from "@playwright/test";

/**
* Read environment variables from file.
* https://github.com/motdotla/dotenv
*/
// require('dotenv').config();

/**
* See https://playwright.dev/docs/test-configuration.
*/
export default defineConfig({
testDir: "./tests",
/* 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: {
/* Base URL to use in actions like `await page.goto('/')`. */
// baseURL: 'http://127.0.0.1:3000',

/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
trace: "on-first-retry",
},

/* Configure projects for major browsers */
projects: [
{
name: "chromium",
use: { ...devices["Desktop Chrome"] },
},

// {
// name: "firefox",
// use: { ...devices["Desktop Firefox"] },
// },

// {
// name: "webkit",
// use: { ...devices["Desktop Safari"] },
// },

/* Test against mobile viewports. */
// {
// name: 'Mobile Chrome',
// use: { ...devices['Pixel 5'] },
// },
// {
// name: 'Mobile Safari',
// use: { ...devices['iPhone 12'] },
// },

/* Test against branded browsers. */
// {
// name: 'Microsoft Edge',
// use: { ...devices['Desktop Edge'], channel: 'msedge' },
// },
// {
// name: 'Google Chrome',
// use: { ...devices['Desktop Chrome'], channel: 'chrome' },
// },
],

/* Run your local dev server before starting the tests */
// webServer: {
// command: 'npm run start',
// url: 'http://127.0.0.1:3000',
// reuseExistingServer: !process.env.CI,
// },

webServer: {
command: "npm run dev",
url: "http://127.0.0.1:3000",
reuseExistingServer: !process.env.CI,
stdout: "ignore",
stderr: "pipe",
},
});
8 changes: 4 additions & 4 deletions src/components/Experiment.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import styles from "@/styles/Home.module.css";

import Intro from "@/components/Intro";
import Intro2 from "@/components/IntroBayesian";
import IntroBayesian from "@/components/IntroBayesian";
import TopBar from "@/components/TopBar";

import { Participant } from "@prisma/client";
Expand All @@ -17,7 +17,7 @@ import {
SessionType2,
} from "@/utilities/types";
import Round from "./Round";
import Intro3 from "./IntroGuess";
import IntroGuess from "./IntroGuess";

function Experiment({ data }: { data: SessionType | SessionType2 }) {
const [participant, setParticipant] = useState<Participant | {}>({});
Expand Down Expand Up @@ -48,7 +48,7 @@ function Experiment({ data }: { data: SessionType | SessionType2 }) {
{phase === Phase.Intro && <Intro nameFunction={generateNewParticipant} />}
{phase === Phase.Intro2 &&
(data.treatment === "QSR" || data.treatment === "BSR") && (
<Intro2
<IntroBayesian
aBlue={data.num_of_blue_a}
bBlue={data.num_of_blue_b}
priors={data.prior as [number, number]}
Expand All @@ -59,7 +59,7 @@ function Experiment({ data }: { data: SessionType | SessionType2 }) {
)}
{phase === Phase.Intro2 &&
(data.treatment === "QSR2" || data.treatment === "BSR2") && (
<Intro3
<IntroGuess
treatment={data.treatment}
phaseFunction={setPhase}
numberOfRounds={data.round_parameters.length}
Expand Down
4 changes: 2 additions & 2 deletions src/components/IntroBayesian.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import Slide6QSR from "./intro2Components/Slide6QSR";
import Slide6BSR from "./intro2Components/Slide6BSR";
import Slide5 from "./intro2Components/Slide5";

function Intro2({
function IntroBayesian({
aBlue,
bBlue,
priors,
Expand Down Expand Up @@ -99,4 +99,4 @@ function Intro2({
);
}

export default Intro2;
export default IntroBayesian;
4 changes: 2 additions & 2 deletions src/components/IntroGuess.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import Slide3 from "./intro3Components/Slide3";
import Slide4QSR from "./intro3Components/Slide4QSR";
import Slide4BSR from "./intro3Components/Slide4BSR";

function Intro3({
function IntroGuess({
treatment,
numberOfRounds,
phaseFunction,
Expand Down Expand Up @@ -87,4 +87,4 @@ function Intro3({
);
}

export default Intro3;
export default IntroGuess;
29 changes: 29 additions & 0 deletions tests/example.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { test, expect } from "@playwright/test";
import { randomUUID } from "crypto";

test("the user can enter the website and solve rounds", async ({ page }) => {
await page.goto("http://localhost:3000");
await page.getByPlaceholder("Ad Soyad").fill("test" + randomUUID());
await page.getByText("Deneye başla!").click();

while (true) {
const startExperiment = page.getByText("Deneye Başla!", { exact: true });
const nextButton = page.getByText("Sonraki");
await expect(startExperiment.or(nextButton).first()).toBeVisible();
if (await startExperiment.isVisible()) {
await startExperiment.click();
break;
}
await nextButton.click();
}

while (true) {
await page.getByText("Tahmine hazırım!").click();
await page.getByText("Karar Verdim").click();
await page.getByText("Sonraki tur").click();

if (await page.isVisible("text='Devam'")) {
break;
}
}
});

0 comments on commit b5a42c9

Please sign in to comment.