Тест на создание нового квиза

This commit is contained in:
ArtChaos189 2024-01-10 21:02:14 +03:00
parent ec22f52a97
commit 5366ab6fce
8 changed files with 174 additions and 5 deletions

@ -0,0 +1,140 @@
import "cypress-file-upload";
describe("Тестирование полей главной страницы", () => {
beforeEach(() => {
cy.visit("http://localhost:3000");
cy.wait(1000);
cy.contains("Регистрация / Войти").click();
const login = "valid_user@exammple.com";
const password = "valid_password";
cy.get("#email").type(login);
cy.get("#password").type(password);
cy.get('button[type="submit"]').click();
});
it("Тест на создание нового квиза, заполнение полей главной странички,в превью тестовом просмотре и публикации", () => {
cy.get('[data-cy="create-quiz"]').click();
cy.wait(1000);
cy.get('button[data-cy="create-quiz-card"]').click();
cy.wait(1000);
cy.get('button[data-cy="select-quiz-layout-standard"]').click();
cy.get("#contentButton").click();
cy.get("#headingInput").type("Заголовок заголовка");
cy.get("#textInput").type("У нас тут какой-то текст");
cy.get("#buttonTextInput").type("Нажми на кнопку");
cy.get("#phoneInput").type("8-800-000-00-00");
cy.get("#companyInput").type("Наш слоган - слоган наш");
cy.get("#websiteInput").type("http://vk:3000/edit");
cy.get("#legalInformationInput").type("У наших документов есть данные");
cy.get(`button[data-cy="button-preview"]`).click();
cy.wait(2000);
// проверка введёных значений
cy.get(`[data-cy="heading"]`)
.should("exist")
.and("have.text", "Заголовок заголовка");
cy.get(`[data-cy="text"]`)
.should("exist")
.and("have.text", "У нас тут какой-то текст");
cy.get(`[data-cy="phonenumber"`)
.should("exist")
.and("have.text", "8-800-000-00-00");
cy.get(`[data-cy="startpage-button"]`)
.should("exist")
.and("have.text", "Нажми на кнопку");
cy.get(`[data-cy="company"]`)
.should("exist")
.and("have.text", "Наш слоган - слоган наш");
cy.get(`[data-cy="legalInformation"]`)
.should("exist")
.and("have.text", "У наших документов есть данные");
cy.get(`button[data-cy="button-preview"]`).click();
//создаём вопрос для тестового просмотра
cy.get('[data-cy="setup-questions"]').click();
cy.wait(500);
// cy.get('[data-cy="create-question"]').click();
cy.get(`[data-cy="select-questiontype-images"]`).click();
cy.get(
'[data-cy="checkbox-optional-question"] > .PrivateSwitchBase-input',
).click();
cy.get('[data-cy="quiz-variant-question-answer"]')
.eq(0)
.type("1")
.type("{enter}");
cy.get('button[data-cy="back-button"]').scrollIntoView().wait(500).click();
cy.wait(1000);
cy.visit("http://localhost:3000/view");
cy.wait(2000);
//проверка введёных значений
cy.get(`[data-cy="heading"]`)
.should("exist")
.and("have.text", "Заголовок заголовка");
cy.get(`[data-cy="text"]`)
.should("exist")
.and("have.text", "У нас тут какой-то текст");
cy.get(`[data-cy="phonenumber"`)
.should("exist")
.and("have.text", "8-800-000-00-00");
cy.get(`[data-cy="startpage-button"]`)
.should("exist")
.and("have.text", "Нажми на кнопку");
cy.get(`[data-cy="company"]`)
.should("exist")
.and("have.text", "Наш слоган - слоган наш");
cy.get(`[data-cy="legalInformation"]`)
.should("exist")
.and("have.text", "У наших документов есть данные");
cy.visit("http://localhost:3000/edit");
cy.wait(2000);
cy.get(`[data-cy="publish-button"]`).click();
cy.wait(500);
let linkText;
cy.get('[data-cy="link-test"]')
.invoke("text")
.then((text) => {
linkText = text;
});
cy.wait(2000).then(() => {
cy.visit(linkText);
});
cy.origin("https://hbpn.link", () => {
// <команды, направленные на https://hbpn.link, идут здесь>
cy.contains("p", "Заголовок заголовка").should("exist");
cy.wait(100);
cy.contains("p", "У нас тут какой-то текст").should("exist");
cy.wait(100);
cy.contains("p", "8-800-000-00-00").should("exist");
cy.wait(100);
cy.contains("p", "Наш слоган - слоган наш").should("exist");
cy.wait(100);
cy.contains("p", "У наших документов есть данные").should("exist");
cy.wait(100);
cy.get(`button`).should("exist").and("have.text", "Нажми на кнопку");
});
cy.visit("http://localhost:3000/list");
cy.wait(2000);
cy.get('[data-cy="quiz-card"] h5')
.should("exist")
.and("have.text", "Заголовок заголовка");
});
});

@ -127,6 +127,7 @@ export const StartPageViewPublication = ({ setVisualStartPage }: Props) => {
/> />
)} )}
<Typography <Typography
data-cy="company"
sx={{ sx={{
fontSize: "14px", fontSize: "14px",
color: color:
@ -167,6 +168,7 @@ export const StartPageViewPublication = ({ setVisualStartPage }: Props) => {
}} }}
> >
<Typography <Typography
data-cy="heading"
sx={{ sx={{
fontWeight: "bold", fontWeight: "bold",
fontSize: "26px", fontSize: "26px",
@ -188,6 +190,7 @@ export const StartPageViewPublication = ({ setVisualStartPage }: Props) => {
{quiz.name} {quiz.name}
</Typography> </Typography>
<Typography <Typography
data-cy="text"
sx={{ sx={{
fontSize: "16px", fontSize: "16px",
m: "16px 0", m: "16px 0",
@ -211,6 +214,7 @@ export const StartPageViewPublication = ({ setVisualStartPage }: Props) => {
} }
> >
<Button <Button
data-cy="startpage-button"
variant="contained" variant="contained"
sx={{ sx={{
fontSize: "16px", fontSize: "16px",
@ -244,6 +248,7 @@ export const StartPageViewPublication = ({ setVisualStartPage }: Props) => {
isMobileDevice ? ( isMobileDevice ? (
<Link href={`tel:${quiz.config.info.phonenumber}`}> <Link href={`tel:${quiz.config.info.phonenumber}`}>
<Typography <Typography
data-cy="phonenumber"
sx={{ sx={{
fontSize: "16px", fontSize: "16px",
color: theme.palette.primary.main, color: theme.palette.primary.main,
@ -255,6 +260,7 @@ export const StartPageViewPublication = ({ setVisualStartPage }: Props) => {
) : ( ) : (
<ButtonBase onClick={handleCopyNumber}> <ButtonBase onClick={handleCopyNumber}>
<Typography <Typography
data-cy="phonenumber"
sx={{ sx={{
fontSize: "16px", fontSize: "16px",
color: theme.palette.primary.main, color: theme.palette.primary.main,
@ -266,12 +272,14 @@ export const StartPageViewPublication = ({ setVisualStartPage }: Props) => {
) )
) : ( ) : (
<Typography <Typography
data-cy="phonenumber"
sx={{ fontSize: "16px", color: theme.palette.primary.main }} sx={{ fontSize: "16px", color: theme.palette.primary.main }}
> >
{quiz.config.info.phonenumber} {quiz.config.info.phonenumber}
</Typography> </Typography>
)} )}
<Typography <Typography
data-cy="legalInformation"
sx={{ sx={{
width: "100%", width: "100%",
overflowWrap: "break-word", overflowWrap: "break-word",

@ -69,6 +69,7 @@ export default function QuizCard({
return ( return (
<Box <Box
data-cy="quiz-card"
sx={{ sx={{
display: "flex", display: "flex",
flexDirection: "column", flexDirection: "column",

@ -177,6 +177,7 @@ export default function Main({ sidebar, header, footer, Page }: Props) {
{quiz?.status === "start" && {quiz?.status === "start" &&
(!isLinkButton ? ( (!isLinkButton ? (
<Box <Box
data-cy="link-test"
component={Link} component={Link}
sx={{ sx={{
whiteSpace: "nowrap", whiteSpace: "nowrap",
@ -193,6 +194,7 @@ export default function Main({ sidebar, header, footer, Page }: Props) {
</Box> </Box>
) : ( ) : (
<Box <Box
data-cy="link-test"
component={Link} component={Link}
sx={{ sx={{
cursor: "pointer", cursor: "pointer",
@ -215,6 +217,7 @@ export default function Main({ sidebar, header, footer, Page }: Props) {
{/* Маленькая кнопка ссылки */} {/* Маленькая кнопка ссылки */}
{isMobile && quiz?.status === "start" && ( {isMobile && quiz?.status === "start" && (
<Box <Box
data-cy="link-test"
component={Link} component={Link}
sx={{ sx={{
cursor: "pointer", cursor: "pointer",
@ -237,6 +240,7 @@ export default function Main({ sidebar, header, footer, Page }: Props) {
{currentStep <= 1 && ( {currentStep <= 1 && (
<Box sx={{ textAlign: "end", width: "100%" }}> <Box sx={{ textAlign: "end", width: "100%" }}>
<IconButton <IconButton
data-cy="button-preview"
onClick={toggleQuizPreview} onClick={toggleQuizPreview}
sx={{ sx={{
pointerEvents: "auto", pointerEvents: "auto",

@ -126,7 +126,7 @@ export default function StartPageSettings() {
Дизайн Дизайн
</Typography> </Typography>
</Button> </Button>
<Button onClick={() => setFormState("content")}> <Button id="contentButton" onClick={() => setFormState("content")}>
<Typography <Typography
sx={{ sx={{
fontWeight: 500, fontWeight: 500,
@ -616,6 +616,7 @@ export default function StartPageSettings() {
Заголовок Заголовок
</Typography> </Typography>
<CustomTextField <CustomTextField
id="headingInput"
placeholder="Имя заголовка опроса для подбора табуретки" placeholder="Имя заголовка опроса для подбора табуретки"
value={quiz.name} value={quiz.name}
onChange={(e) => onChange={(e) =>
@ -636,6 +637,7 @@ export default function StartPageSettings() {
Текст Текст
</Typography> </Typography>
<CustomTextField <CustomTextField
id="textInput"
placeholder="Внимательно заполняйте поля ответов" placeholder="Внимательно заполняйте поля ответов"
value={quiz.config.startpage.description} value={quiz.config.startpage.description}
onChange={(e) => onChange={(e) =>
@ -656,6 +658,7 @@ export default function StartPageSettings() {
Текст кнопки Текст кнопки
</Typography> </Typography>
<CustomTextField <CustomTextField
id="buttonTextInput"
placeholder="Начать опрос" placeholder="Начать опрос"
value={quiz.config.startpage.button} value={quiz.config.startpage.button}
onChange={(e) => onChange={(e) =>
@ -676,6 +679,7 @@ export default function StartPageSettings() {
Телефон Телефон
</Typography> </Typography>
<CustomTextField <CustomTextField
id="phoneInput"
placeholder="8-800-000-00-00" placeholder="8-800-000-00-00"
type="number" type="number"
value={quiz.config.info.phonenumber} value={quiz.config.info.phonenumber}
@ -707,6 +711,7 @@ export default function StartPageSettings() {
Название или слоган компании Название или слоган компании
</Typography> </Typography>
<CustomTextField <CustomTextField
id="companyInput"
placeholder="Только лучшее" placeholder="Только лучшее"
value={quiz.config.info.orgname} value={quiz.config.info.orgname}
onChange={(e) => onChange={(e) =>
@ -727,6 +732,7 @@ export default function StartPageSettings() {
Сайт Сайт
</Typography> </Typography>
<CustomTextField <CustomTextField
id="websiteInput"
placeholder="https://mysite.com" placeholder="https://mysite.com"
value={quiz.config.info.site} value={quiz.config.info.site}
onChange={(e) => onChange={(e) =>
@ -747,6 +753,7 @@ export default function StartPageSettings() {
Юридическая информация Юридическая информация
</Typography> </Typography>
<CustomTextField <CustomTextField
id="legalInformationInput"
placeholder="Данные наших документов" placeholder="Данные наших документов"
value={quiz.config.info.law} value={quiz.config.info.law}
onChange={(e) => onChange={(e) =>

@ -13,6 +13,7 @@ import type { InputProps, SxProps, Theme } from "@mui/material";
interface CustomTextFieldProps { interface CustomTextFieldProps {
placeholder: string; placeholder: string;
id?: string;
value?: string; value?: string;
error?: string; error?: string;
emptyError?: boolean; emptyError?: boolean;
@ -31,6 +32,7 @@ interface CustomTextFieldProps {
export default function CustomTextField({ export default function CustomTextField({
placeholder, placeholder,
id,
value = "", value = "",
onChange, onChange,
onKeyDown, onKeyDown,
@ -99,6 +101,7 @@ export default function CustomTextField({
</InputLabel> </InputLabel>
)} )}
<Input <Input
id={id}
defaultValue={text} defaultValue={text}
fullWidth fullWidth
value={inputValue} value={inputValue}

@ -84,7 +84,7 @@ export default function QuizPreviewLayout() {
alt="" alt=""
/> />
)} )}
<Typography sx={{ fontSize: "12px" }}> <Typography data-cy="company" sx={{ fontSize: "12px" }}>
{quiz.config.info.orgname} {quiz.config.info.orgname}
</Typography> </Typography>
</Box> </Box>
@ -105,12 +105,15 @@ export default function QuizPreviewLayout() {
: "start", : "start",
}} }}
> >
<Typography sx={{ fontWeight: "bold" }}>{quiz.name}</Typography> <Typography data-cy="heading" sx={{ fontWeight: "bold" }}>
<Typography sx={{ fontSize: "12px" }}> {quiz.name}
</Typography>
<Typography data-cy="text" sx={{ fontSize: "12px" }}>
{quiz.config.startpage.description} {quiz.config.startpage.description}
</Typography> </Typography>
<Box> <Box>
<Button <Button
data-cy="startpage-button"
variant="contained" variant="contained"
sx={{ sx={{
fontSize: "16px", fontSize: "16px",
@ -139,6 +142,7 @@ export default function QuizPreviewLayout() {
) : ( ) : (
<ButtonBase onClick={handleCopyNumber}> <ButtonBase onClick={handleCopyNumber}>
<Typography <Typography
data-cy="phonenumber"
sx={{ sx={{
fontSize: "16px", fontSize: "16px",
color: theme.palette.primary.main, color: theme.palette.primary.main,
@ -150,12 +154,13 @@ export default function QuizPreviewLayout() {
) )
) : ( ) : (
<Typography <Typography
data-cy="phonenumber"
sx={{ fontSize: "16px", color: theme.palette.primary.main }} sx={{ fontSize: "16px", color: theme.palette.primary.main }}
> >
{quiz.config.info.phonenumber} {quiz.config.info.phonenumber}
</Typography> </Typography>
)} )}
<Typography sx={{ fontSize: "12px" }}> <Typography data-cy="legalInformation" sx={{ fontSize: "12px" }}>
{quiz.config.info.law} {quiz.config.info.law}
</Typography> </Typography>
</Box> </Box>

@ -38,6 +38,7 @@ export const ButtonRecallQuiz = () => {
return ( return (
<Button <Button
data-cy="publish-button"
variant="contained" variant="contained"
sx={{ sx={{
fontSize: "14px", fontSize: "14px",