refactor: เพิ่มการทดสอบ สร้างไฟล์

This commit is contained in:
somnetsak123 2023-12-15 14:59:32 +07:00
parent 544fb16def
commit da5e51f9c6

View file

@ -19,10 +19,10 @@ test.afterAll(async () => {
}) })
test('Login', async () => { test('Login', async () => {
await page.goto('http://localhost:3010/admin') await page.goto('https://edm.frappet.synology.me/admin')
await expect(page).toHaveTitle('Sign in to EDM') await expect(page).toHaveTitle('Sign in to EDM')
await page.fill("input[name='username']", 'oom') await page.fill("input[name='username']", 'net')
await page.fill("input[name='password']", 'oom') await page.fill("input[name='password']", 'P@ssw0rd')
await page.click("input[name='login']") await page.click("input[name='login']")
await page.waitForTimeout(2000) await page.waitForTimeout(2000)
@ -31,18 +31,13 @@ test('Login', async () => {
test('Create Cabinet', async () => { test('Create Cabinet', async () => {
await page.waitForTimeout(2000) await page.waitForTimeout(2000)
await page.click("//div[@id='triggerFolderCreateFileItem']") await page.click("//div[@id='triggerFolderCreateFileItem']")
await page.fill( await page.fill("//input[@placeholder='กรอกชื่อ']", cabinet)
"//input[@placeholder='กรอกชื่อ']",
cabinet,
)
await page.click("//button[@type='submit']") await page.click("//button[@type='submit']")
await page.waitForTimeout(300) await page.waitForTimeout(300)
await expect( await expect(page.locator("(//div[@class='col'])[3]")).toContainText(cabinet)
page.locator("(//div[contains(@class,'bg-white rounded-borders')])[2]"),
).toContainText(cabinet)
await page.waitForTimeout(300) await page.waitForTimeout(300)
}) })
@ -53,74 +48,159 @@ test('Go to Cabinet', async () => {
test('Create drawer', async () => { test('Create drawer', async () => {
await page.click("//div[@id='triggerFolderCreateFileItem']") await page.click("//div[@id='triggerFolderCreateFileItem']")
await page.fill( await page.fill("//input[@placeholder='กรอกชื่อ']", drawer)
"//input[@placeholder='กรอกชื่อ']",
drawer,
)
await page.click("//button[@type='submit']") await page.click("//button[@type='submit']")
await page.waitForTimeout(300) await page.waitForTimeout(300)
await expect( await expect(page.locator("(//div[@class='col'])[3]")).toContainText(drawer)
page.locator("(//div[contains(@class,'bg-white rounded-borders')])[2]"),
).toContainText(drawer)
await page.waitForTimeout(300) await page.waitForTimeout(300)
}) })
test('Go into drawer', async () => { test('Go into drawer', async () => {
await page.click(`(//div[text()='${drawer}'])[2]`) await page.click(`(//div[text()='${drawer}'])[2]`)
await expect( await expect(page.locator("(//div[@class='col'])[3]")).not.toHaveText(drawer)
page.locator("(//div[contains(@class,'bg-white rounded-borders')])[2]"),
).not.toHaveText(drawer)
}) })
test('Create Folder', async () => { test('Create Folder', async () => {
await page.click("//div[@id='triggerFolderCreateFileItem']") await page.click("//div[@id='triggerFolderCreateFileItem']")
await page.fill( await page.fill("//input[@placeholder='กรอกชื่อ']", folder)
"//input[@placeholder='กรอกชื่อ']",
folder,
)
await page.click("//button[@type='submit']") await page.click("//button[@type='submit']")
await page.waitForTimeout(300) await page.waitForTimeout(300)
await expect( await expect(page.locator("(//div[@class='col'])[3]")).toContainText(folder)
page.locator("(//div[contains(@class,'bg-white rounded-borders')])[2]"),
).toContainText(folder)
}) })
test('Go into Folder', async () => { test('Go into Folder', async () => {
await page.click(`(//div[text()='${folder}'])[2]`) await page.click(`(//div[text()='${folder}'])[2]`)
await expect( await expect(page.locator("(//div[@class='col'])[3]")).not.toHaveText(folder)
page.locator("(//div[contains(@class,'bg-white rounded-borders')])[2]"),
).not.toHaveText(folder)
}) })
test('Create Subfolder', async () => { test('Create Subfolder', async () => {
await page.click("//div[@id='triggerFolderCreateFileItem']") await page.click("//div[@id='triggerFolderCreateFileItem']")
await page.fill( await page.fill("//input[@placeholder='กรอกชื่อ']", subfolder)
"//input[@placeholder='กรอกชื่อ']", await page.click("//button[@type='submit']")
await page.waitForTimeout(300)
await expect(page.locator("(//div[@class='col'])[3]")).toContainText(
subfolder, subfolder,
) )
await page.click("(//button[@type='submit'])[3]")
await page.waitForTimeout(300)
await expect(
page.locator("(//div[contains(@class,'bg-white rounded-borders')])[2]"),
).toContainText(subfolder)
}) })
test('Go into Subfolder', async () => { test('Go into Subfolder', async () => {
await page.click(`(//div[text()='${subfolder}'])[2]`)
await page.click(`//div[text()='${subfolder}']`)
await expect( await expect(page.locator("(//div[@class='col'])[3]")).not.toHaveText(folder)
page.locator("(//div[contains(@class,'bg-white rounded-borders')])[2]"), })
).not.toHaveText(folder)
test('Upload File in SubFolder Level', async () => {
await page.click("//span[text()='สร้างเอกสาร']")
await page
.locator("//input[@type='file']")
.setInputFiles('tests/searchtest.txt')
await page.fill("//input[@placeholder='กรอกชื่อเรื่อง']", 'testtext')
await page.click("(//button[@type='submit'])[1]")
await page.waitForTimeout(2500)
await page.click('button#getFolder')
await page.waitForTimeout(1000)
await expect(page.locator("(//div[@class='col'])[3]")).toContainText(
'testtext',
)
})
test('Go into Text File', async () => {
await page.click("//div[text()='testtext']")
})
test('Download File Text', async () => {
await page.click("//span[text()='ดาวน์โหลด']")
await page.waitForTimeout(2000)
})
test('Go back to SubFolder Level Again', async () => {
await page.click("//i[text()='arrow_back']")
})
test('Delete file Cancel', async () => {
await page.click(
`//button[@data-testid='action${cabinet}/${drawer}/${folder}/${subfolder}/searchtest.txt']`,
)
await page.click("(//div[@role='listitem'])[2]")
await page.click("(//div[@class='q-space']/following-sibling::button)[2]")
await expect(page.locator("(//div[@class='col'])[3]")).toContainText(
'testtext',
)
})
test('Delete file Confirm', async () => {
await page.click(
`//button[@data-testid='action${cabinet}/${drawer}/${folder}/${subfolder}/searchtest.txt']`,
)
await page.click("(//div[@role='listitem'])[2]")
await page.click(
"(//div[contains(@class,'q-card__actions justify-end')]//button)[2]",
)
await expect(page.locator("(//div[@class='col'])[3]")).not.toHaveText(
'testtext',
)
}) })
test('Back to Folder', async () => { test('Back to Folder', async () => {
await page.click("//i[text()='arrow_back']") await page.click("//i[text()='arrow_back']")
await expect( await expect(page.locator("(//div[@class='col'])[3]")).toContainText(
page.locator("(//div[contains(@class,'bg-white rounded-borders')])[2]"), subfolder,
).toContainText(subfolder) )
})
test('Upload File in Folder Level', async () => {
await page.click("//span[text()='สร้างเอกสาร']")
await page
.locator("//input[@type='file']")
.setInputFiles('tests/searchtest.txt')
await page.fill("//input[@placeholder='กรอกชื่อเรื่อง']", 'testtext')
await page.click("(//button[@type='submit'])[1]")
await page.waitForTimeout(2500)
await page.click('button#getFolder')
await page.waitForTimeout(1000)
await expect(page.locator("(//div[@class='col'])[3]")).toContainText(
'testtext',
)
})
test('Go into Text File in Folder', async () => {
await page.click("//div[text()='testtext']")
})
test('Download File Text in Folder', async () => {
await page.click("//span[text()='ดาวน์โหลด']")
await page.waitForTimeout(2000)
})
test('Go back to Folder Level Again', async () => {
await page.click("//i[text()='arrow_back']")
})
test('Delete file Cancel in Folder', async () => {
await page.click(
`//button[@data-testid='action${cabinet}/${drawer}/${folder}/searchtest.txt']`,
)
await page.click("(//div[@role='listitem'])[2]")
await page.click("(//div[@class='q-space']/following-sibling::button)[2]")
await expect(page.locator("(//div[@class='col'])[3]")).toContainText(
'testtext',
)
})
test('Delete file Confirm in Folder', async () => {
await page.click(
`//button[@data-testid='action${cabinet}/${drawer}/${folder}/searchtest.txt']`,
)
await page.click("(//div[@role='listitem'])[2]")
await page.click(
"(//div[contains(@class,'q-card__actions justify-end')]//button)[2]",
)
await expect(page.locator("(//div[@class='col'])[3]")).not.toHaveText(
'testtext',
)
}) })
test('Edit Subfolder', async () => { test('Edit Subfolder', async () => {
@ -130,9 +210,7 @@ test('Edit Subfolder', async () => {
await page.click("(//div[@role='listitem'])[1]") await page.click("(//div[@role='listitem'])[1]")
await page.fill("(//input[@placeholder='กรอกชื่อ'])[1]", newName) await page.fill("(//input[@placeholder='กรอกชื่อ'])[1]", newName)
await page.click("(//button[@id='FoldeSubmit'])[1]") await page.click("(//button[@id='FoldeSubmit'])[1]")
await expect( await expect(page.locator("(//div[@class='col'])[3]")).toContainText(newName)
page.locator("(//div[contains(@class,'bg-white rounded-borders')])[2]"),
).toContainText(newName)
}) })
test('Delete Subfolder Cancel', async () => { test('Delete Subfolder Cancel', async () => {
@ -141,9 +219,7 @@ test('Delete Subfolder Cancel', async () => {
) )
await page.click("(//div[@role='listitem'])[2]") await page.click("(//div[@role='listitem'])[2]")
await page.click("(//div[@class='q-space']/following-sibling::button)[2]") await page.click("(//div[@class='q-space']/following-sibling::button)[2]")
await expect( await expect(page.locator("(//div[@class='col'])[3]")).toContainText(newName)
page.locator("(//div[contains(@class,'bg-white rounded-borders')])[2]"),
).toContainText(newName)
}) })
test('Delete Subfolder Confirm', async () => { test('Delete Subfolder Confirm', async () => {
@ -154,16 +230,12 @@ test('Delete Subfolder Confirm', async () => {
await page.click( await page.click(
"(//div[contains(@class,'q-card__actions justify-end')]//button)[2]", "(//div[contains(@class,'q-card__actions justify-end')]//button)[2]",
) )
await expect( await expect(page.locator("(//div[@class='col'])[3]")).not.toHaveText(newName)
page.locator("(//div[contains(@class,'bg-white rounded-borders')])[2]"),
).not.toHaveText(newName)
}) })
test('Back to drawer', async () => { test('Back to drawer', async () => {
await page.click("//i[text()='arrow_back']") await page.click("//i[text()='arrow_back']")
await expect( await expect(page.locator("(//div[@class='col'])[3]")).toContainText(folder)
page.locator("(//div[contains(@class,'bg-white rounded-borders')])[2]"),
).toContainText(folder)
}) })
test('Edit Folder', async () => { test('Edit Folder', async () => {
@ -173,9 +245,7 @@ test('Edit Folder', async () => {
await page.click("(//div[@role='listitem'])[1]") await page.click("(//div[@role='listitem'])[1]")
await page.fill("(//input[@placeholder='กรอกชื่อ'])[1]", newName) await page.fill("(//input[@placeholder='กรอกชื่อ'])[1]", newName)
await page.click("(//button[@id='FoldeSubmit'])[1]") await page.click("(//button[@id='FoldeSubmit'])[1]")
await expect( await expect(page.locator("(//div[@class='col'])[3]")).toContainText(newName)
page.locator("(//div[contains(@class,'bg-white rounded-borders')])[2]"),
).toContainText(newName)
}) })
test('Delete Folder Cancel', async () => { test('Delete Folder Cancel', async () => {
@ -184,9 +254,7 @@ test('Delete Folder Cancel', async () => {
) )
await page.click("(//div[@role='listitem'])[2]") await page.click("(//div[@role='listitem'])[2]")
await page.click("(//div[@class='q-space']/following-sibling::button)[2]") await page.click("(//div[@class='q-space']/following-sibling::button)[2]")
await expect( await expect(page.locator("(//div[@class='col'])[3]")).toContainText(newName)
page.locator("(//div[contains(@class,'bg-white rounded-borders')])[2]"),
).toContainText(newName)
}) })
test('Delete Folder Confirm', async () => { test('Delete Folder Confirm', async () => {
@ -197,16 +265,12 @@ test('Delete Folder Confirm', async () => {
await page.click( await page.click(
"(//div[contains(@class,'q-card__actions justify-end')]//button)[2]", "(//div[contains(@class,'q-card__actions justify-end')]//button)[2]",
) )
await expect( await expect(page.locator("(//div[@class='col'])[3]")).not.toHaveText(newName)
page.locator("(//div[contains(@class,'bg-white rounded-borders')])[2]"),
).not.toHaveText(newName)
}) })
test('Back to Cabinet', async () => { test('Back to Cabinet', async () => {
await page.click("//i[text()='arrow_back']") await page.click("//i[text()='arrow_back']")
await expect( await expect(page.locator("(//div[@class='col'])[3]")).toContainText(drawer)
page.locator("(//div[contains(@class,'bg-white rounded-borders')])[2]"),
).toContainText(drawer)
}) })
test('Edit drawer', async () => { test('Edit drawer', async () => {
@ -214,18 +278,14 @@ test('Edit drawer', async () => {
await page.click("(//div[@role='listitem'])[1]") await page.click("(//div[@role='listitem'])[1]")
await page.fill("(//input[@placeholder='กรอกชื่อ'])[1]", newName) await page.fill("(//input[@placeholder='กรอกชื่อ'])[1]", newName)
await page.click("(//button[@id='FoldeSubmit'])[1]") await page.click("(//button[@id='FoldeSubmit'])[1]")
await expect( await expect(page.locator("(//div[@class='col'])[3]")).toContainText(newName)
page.locator("(//div[contains(@class,'bg-white rounded-borders')])[2]"),
).toContainText(newName)
}) })
test('Delete Drawer Cancel', async () => { test('Delete Drawer Cancel', async () => {
await page.click(`//button[@data-testid='action${cabinet}/${newName}/']`) await page.click(`//button[@data-testid='action${cabinet}/${newName}/']`)
await page.click("(//div[@role='listitem'])[2]") await page.click("(//div[@role='listitem'])[2]")
await page.click("(//div[@class='q-space']/following-sibling::button)[2]") await page.click("(//div[@class='q-space']/following-sibling::button)[2]")
await expect( await expect(page.locator("(//div[@class='col'])[3]")).toContainText(newName)
page.locator("(//div[contains(@class,'bg-white rounded-borders')])[2]"),
).toContainText(newName)
}) })
test('Delete Drawer Confirm', async () => { test('Delete Drawer Confirm', async () => {
@ -234,35 +294,30 @@ test('Delete Drawer Confirm', async () => {
await page.click( await page.click(
"(//div[contains(@class,'q-card__actions justify-end')]//button)[2]", "(//div[contains(@class,'q-card__actions justify-end')]//button)[2]",
) )
await expect( await expect(page.locator("(//div[@class='col'])[3]")).not.toHaveText(newName)
page.locator("(//div[contains(@class,'bg-white rounded-borders')])[2]"),
).not.toHaveText(newName)
}) })
test('Back to Home', async () => { test('Back to Home', async () => {
await page.click("//i[text()='arrow_back']") await page.click("//i[text()='arrow_back']")
await expect( await expect(page.locator("(//div[@class='col'])[3]")).toContainText(cabinet)
page.locator("(//div[contains(@class,'bg-white rounded-borders')])[2]"),
).toContainText(cabinet)
}) })
test('Edit Cabinet', async () => { test('Edit Cabinet', async () => {
await page.click(`//button[@data-testid='action${cabinet}/']`) console.log(cabinet)
await page.click("(//div[@role='listitem'])[1]")
await page.fill("(//input[@placeholder='กรอกชื่อ'])[1]", newName) await page.click(`"//button[@data-testid='action${cabinet}/']"`)
await page.click("(//button[@id='FoldeSubmit'])[1]") //button[@data-testid='actionI0Xc50SHxGe4kYehU4t2B/']
await expect( await page.click("(//div[@role='listitem'])[2]")
page.locator("(//div[contains(@class,'bg-white rounded-borders')])[2]"), await page.fill("(//input[@placeholder='กรอกชื่อ'])2]", newName)
).toContainText(newName) await page.click("(//button[@id='FoldeSubmit'])[2]")
await expect(page.locator("(//div[@class='col'])[3]")).toContainText(newName)
}) })
test('Delete Cabinet Cancel', async () => { test('Delete Cabinet Cancel', async () => {
await page.click(`//button[@data-testid='action${newName}/']`) await page.click(`//button[@data-testid='action${newName}/']`)
await page.click("(//div[@role='listitem'])[2]") await page.click("(//div[@role='listitem'])[2]")
await page.click("(//div[@class='q-space']/following-sibling::button)[2]") await page.click("(//div[@class='q-space']/following-sibling::button)[2]")
await expect( await expect(page.locator("(//div[@class='col'])[3]")).toContainText(newName)
page.locator("(//div[contains(@class,'bg-white rounded-borders')])[2]"),
).toContainText(newName)
}) })
test('Delete Cabinet Confirm', async () => { test('Delete Cabinet Confirm', async () => {
@ -271,7 +326,5 @@ test('Delete Cabinet Confirm', async () => {
await page.click( await page.click(
"(//div[contains(@class,'q-card__actions justify-end')]//button)[2]", "(//div[contains(@class,'q-card__actions justify-end')]//button)[2]",
) )
await expect( await expect(page.locator("(//div[@class='col'])[3]")).not.toHaveText(newName)
page.locator("(//div[contains(@class,'bg-white rounded-borders')])[2]"),
).not.toHaveText(newName)
}) })