Skip to content

Commit

Permalink
chromium
Browse files Browse the repository at this point in the history
  • Loading branch information
joaovictorino committed Mar 2, 2024
1 parent 67ef992 commit 73fc1f7
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 31 deletions.
27 changes: 27 additions & 0 deletions web/e2e/CriarContas.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { test, expect } from '@playwright/test';

test('Criar Conta', async ({ page }) => {
await page.goto('http://localhost:3000/');
await page.getByRole('link', { name: 'Acessar Contas' }).click();

await page.getByRole('link', { name: '+ Criar nova conta' }).click();
await page.getByLabel('Número:').click();
await page.getByLabel('Número:').fill("999999");
await page.getByLabel('Saldo (R$):').click();
await page.getByLabel('Saldo (R$):').fill("1000.0");
await page.getByRole('button', { name: 'Salvar' }).click();

await page.getByTestId('999999-ver').click();
await expect(page.getByText('Saldo:R$ 1000.00')).toBeVisible();
await page.getByRole('link', { name: 'Retornar' }).click();

await page.getByRole('link', { name: '+ Criar nova conta' }).click();
await page.getByLabel('Número:').click();
await page.getByLabel('Número:').fill("777777");
await page.getByLabel('Saldo (R$):').click();
await page.getByLabel('Saldo (R$):').fill("5000.0");
await page.getByRole('button', { name: 'Salvar' }).click();

await page.getByTestId('777777-ver').click();
await expect(page.getByText('Saldo:R$ 5000.00')).toBeVisible();
});
18 changes: 10 additions & 8 deletions web/features/steps/transferirPlay.step.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
import { binding, given, when, then } from "cucumber-tsflow";
import { expect } from '@playwright/test';
import {
ChromiumBrowser,
chromium
Browser,
chromium,
BrowserContext,
Page
} from '@playwright/test';

@binding()
class TransferirPlay {
private browser: ChromiumBrowser;
private context;
private page;
private browser: Browser;
private context: BrowserContext;
private page: Page;

@given("conta web {string} com saldo {float} e a conta web {string} com saldo {float}")
@given("conta web {string} com saldo {float} e a conta web {string} com saldo {float}", { timeout: -1 })
public async dadaDuasContas(numeroOrigem: string, saldoOrigem: number, numeroDestino: string, saldoDestino: number) {
this.browser = await chromium.launch();
this.context = await this.browser.newContext()
this.page = await this.context.newPage()
this.context = await this.browser.newContext();
this.page = await this.context.newPage();
await this.page.goto('http://localhost:3000/');
await this.page.getByRole('link', { name: 'Acessar Contas' }).click();

Expand Down
2 changes: 1 addition & 1 deletion web/pages/api/contas/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@ export default async function contas(req: NextApiRequest, res: NextApiResponse)
if(req.method === "GET") {
const contaRepositorio: ContaRepositorio = new ContaRepositorio();
const contas = await contaRepositorio.listar();
res.status(201).json(contas);
res.status(200).json(contas);
}
}
24 changes: 10 additions & 14 deletions web/pages/contas/[numero]/transferir.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,28 +13,24 @@ export default function ContaTransferir() {
if (error) return <div>Falha ao carregar</div>
if (!data) return <div>Carregando ...</div>

function handleSubmit (e: FormEvent<HTMLFormElement>) {
async function handleSubmit (e: FormEvent<HTMLFormElement>) {
e.preventDefault();
formState.origem = data.numero;
fetch("/api/contas/transferir", {
const response = await fetch("/api/contas/transferir", {
method: "POST",
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(formState)
})
.then((res) => {
if(res.ok)
return res.json();
else
return undefined;
})
.then((data) => {
if(data) {
alert(`Recibo ${data.recibo}`)
router.push("/contas")
}
});

const dataResponse = await response.json();
if (response.ok){
alert(`Recibo ${dataResponse.recibo}`)
router.push("/contas");
} else {
alert(dataResponse.mensagem);
}
}

return (
Expand Down
18 changes: 10 additions & 8 deletions web/pages/contas/criar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,23 @@ export default function ContaCriar() {
const [formState, setFormState] = useState({ numero: "",saldo: 0, })
const router = useRouter();

function handleSubmit (e: FormEvent<HTMLFormElement>) {
async function handleSubmit (e: FormEvent<HTMLFormElement>) {
e.preventDefault();
fetch("/api/contas", {
const response = await fetch("/api/contas", {
method: "POST",
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(formState)
})
.then((res) => {
if (res.ok) {
alert("Conta criada!")
router.push("/contas")
}
});

if (response.ok) {
alert("Conta criada!");
router.push("/contas");
} else {
const data = await response.json();
alert(data.mensagem);
}
}

return (
Expand Down

0 comments on commit 73fc1f7

Please sign in to comment.