update testing library settings and global functions

This commit is contained in:
Annie Huang committed 2024-02-14 16:16:01 +08:00
1 parent 5c17f5ea3c
commit 2b495f7cda
2 files changed
+27 -37

No files matched your search

+24 -35
View File
@@ -1,52 +1,41 @@
// import '@testing-library/cypress/add-commands' /// <reference types="cypress" />
import '@testing-library/cypress/add-commands'
declare global { declare global {
declare namespace Cypress { declare namespace Cypress {
interface Chainable { interface Chainable {
// 確保你有正確的泛型參數 // 確保你有正確的泛型參數
fillWith( LoginWithPassword(username: string, password: string): Chainable<void>
account: string, PrepareForGame(): Chainable<void>
password: string InitTerminal(): Chainable<void>
): Chainable<JQuery<HTMLElement>> typeInCommand(command: string): Chainable<void>
LoginWithPassword( getQuestInfo(id: string): Chainable<string>
username: string, checkHint(index: number, total: number): Chainable<void> // 修改類型
password: string checkTaskInit(): Chainable<void>
): Chainable<JQuery<HTMLElement>> waitUntilActive(last?: boolean): Chainable<void> // 注意小寫boolean,並且變量名應該是小寫
PrepareForGame(): Chainable<JQuery<HTMLElement>> checkPending(): Chainable<string>
InitTerminal(): Chainable<JQuery<HTMLElement>> CompleteStageWithCommands(stagename: string): Chainable<string>
typeInCommand(command: string): Chainable<JQuery<HTMLElement>>
getQuestInfo(id: string): Chainable<JQuery<HTMLElement>>
checkHint(index: number, total: number): Chainable<JQuery<HTMLElement>> // 修改類型
checkTaskInit(): Chainable<JQuery<HTMLElement>>
waitUntilActive(last: boolean): Chainable<JQuery<HTMLElement>> // 注意小寫boolean,並且變量名應該是小寫
checkPending(): Chainable<JQuery<HTMLElement>>
CompleteStageWithCommands(
stagename: string
): Chainable<JQuery<HTMLElement>>
CheckTextElement( CheckTextElement(
id: string, id: string,
chText: string, chText: string,
enText: string enText: string
): Chainable<JQuery<HTMLElement>> ): Chainable<string>
CheckPlaceholder( CheckPlaceholder(
id: string, id: string,
chText: string, chText: string,
enText: string enText: string
): Chainable<JQuery<HTMLElement>> ): Chainable<string>
CheckTreeElement(element: string): Chainable<JQuery<HTMLElement>> CheckTreeElement(element: string): Chainable<string>
} }
} }
} }
Cypress.Commands.add('LoginWithPassword', (username, password) => {
Cypress.Commands.add( cy.clearAllCookies()
'LoginWithPassword', cy.visit('/login')
(username: string, password: string) => { cy.get('#username').type(username)
cy.clearAllCookies({ domain: null }) cy.get('#password').type(password)
cy.visit('/login') cy.get('#LogInOrSignUp').click()
cy.get('#username').type(username) })
cy.get('#password').type(password)
cy.get('#LogInOrSignUp').click()
}
)
Cypress.Commands.add('PrepareForGame', () => { Cypress.Commands.add('PrepareForGame', () => {
cy.visit('/') cy.visit('/')
// make sure the login page is loaded // make sure the login page is loaded
@@ -110,7 +99,7 @@ Cypress.Commands.add('waitUntilActive', (last = false) => {
return return
} }
if (value === 'pending' && !last) { if (value === 'pending' && !last) {
cy.log(last) cy.log(`${last}`)
cy.typeInCommand('{enter}') cy.typeInCommand('{enter}')
cy.waitUntilActive() cy.waitUntilActive()
} }
+3 -2
View File
@@ -2,7 +2,8 @@
"compilerOptions": { "compilerOptions": {
"target": "es5", "target": "es5",
"lib": ["es5", "dom"], "lib": ["es5", "dom"],
"types": ["cypress", "node"] "types": ["cypress", "@testing-library/cypress"]
}, },
"include": ["**/*.ts"] "include": ["src", "node_modules/cypress", "**/*.ts"],
"exclude": ["node_modules/cypress"]
} }