Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(cypress): upgrade cypress to v10 and migrate to ts #991

Merged
merged 31 commits into from
Aug 15, 2022
Merged
Show file tree
Hide file tree
Changes from 30 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
6d6cb2f
chore(package): update cypress
seaerchin Jul 21, 2022
6062f37
chore(cypress): removed unused plugins index file
seaerchin Jul 21, 2022
8b2036d
chore(cypress): ran automatic migration tool
seaerchin Jul 21, 2022
6daee50
chore(cypress.config): update cypress config
seaerchin Jul 21, 2022
47d6ca3
chore(cypress): add support for component testing
seaerchin Jul 21, 2022
7e81303
chore(editpage): migrate to ts
seaerchin Jul 21, 2022
b4141d7
refactor(cypress commands): shift to ts
seaerchin Jul 21, 2022
5920eff
chore(waitfordom): remove waitfordom and related files
seaerchin Jul 21, 2022
12d1db8
refactor(files.spec): migrate to ts
seaerchin Jul 21, 2022
2941e95
refactor(folders): migrate to ts
seaerchin Jul 21, 2022
24c99b6
refactor(homepage.spec): migrate to ts
seaerchin Jul 21, 2022
ea2a172
refactor(images.spec): migrate to ts
seaerchin Jul 21, 2022
8e40a36
refactor(move.spec): migrate to ts
seaerchin Jul 21, 2022
5e22843
chore(support/index.d.ts): remove outdated function declartation
seaerchin Jul 21, 2022
83fabf4
refactor(resourceacategory): migrate to ts
seaerchin Jul 21, 2022
afbe38f
refactor(resources.spec): migrate to ts
seaerchin Jul 21, 2022
2e98804
refactor(settings.spec): migrate custom commands to own file and migr…
seaerchin Jul 21, 2022
1975277
feat(cypress.config): shift to transpiling ts
seaerchin Jul 21, 2022
651fb4c
refactor(cypress): migrate remaining specs from js to ts and add allo…
seaerchin Jul 21, 2022
1d65946
docs(cypress/support): shift JSDocs for commands to index.d.ts so TS …
seaerchin Jul 21, 2022
e2a3899
refactor(legacy): shift utils to utils/ and renamed it legacy to avoi…
seaerchin Aug 1, 2022
5f0cba2
build(cypress/tsconfig): update cypress tsconfig to point to the base…
seaerchin Aug 1, 2022
6cb88f5
chore(cypress/e2e): shorten imports
seaerchin Aug 1, 2022
030fe2e
chore(toasts): change to ts from jsx
seaerchin Aug 1, 2022
da35f19
chore(utils): split some util functions into scoped file
seaerchin Aug 1, 2022
439ec09
chore(utils/index): add index
seaerchin Aug 1, 2022
f92768e
fix(api): change import to avoid dep cycle
seaerchin Aug 1, 2022
a052cac
fix(leftnavgeneration): change export to deslugifyDirectory
seaerchin Aug 1, 2022
672db3e
fix(validators): fixed deps cycle
seaerchin Aug 1, 2022
575f14e
fix(jest.config): specify setup files to enable mockign for testdecoder
seaerchin Aug 1, 2022
261fc5f
fix(context-menu): update context menu styling to fix UI breakage (#998)
seaerchin Aug 15, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions cypress.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { defineConfig } from "cypress"

export default defineConfig({
chromeWebSecurity: false,
viewportHeight: 768,
viewportWidth: 1366,
projectId: "nxbty1",

e2e: {
specPattern: "cypress/e2e/**/*.{js,jsx,ts,tsx}",
},

component: {
devServer: {
framework: "create-react-app",
bundler: "webpack",
},
},
})
6 changes: 0 additions & 6 deletions cypress.json

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import {
slugifyCategory,
generateResourceFileName,
titleToPageFileName,
} from "../../src/utils"
} from "utils"

import {
E2E_CHANGE_WAIT_TIME,
E2E_DEFAULT_WAIT_TIME,
Expand Down Expand Up @@ -54,7 +55,10 @@ describe("Edit unlinked page", () => {

before(() => {
cy.setCookie(COOKIE_NAME, COOKIE_VALUE)
window.localStorage.setItem(LOCAL_STORAGE_USER_KEY, E2E_USER)
window.localStorage.setItem(
LOCAL_STORAGE_USER_KEY,
JSON.stringify(E2E_USER)
)
window.localStorage.setItem(LOCAL_STORAGE_USERID_KEY, E2E_USER.userId)

// Set colour
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ describe("Files", () => {

const MISSING_EXTENSION = "singapore"
const INVALID_CHARACTER = "%%%%.pdf"
const ACTION_DISABLED = "true"
const ACTION_DISABLED = true

describe("Create file, delete file, edit file settings in Files", () => {
beforeEach(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import {
titleToPageFileName,
pageFileNameToTitle,
deslugifyDirectory,
} from "../../src/utils"
} from "utils"

import {
E2E_DEFAULT_WAIT_TIME,
E2E_EXTENDED_TIMEOUT,
Expand Down
File renamed without changes.
File renamed without changes.
37 changes: 19 additions & 18 deletions cypress/integration/move.spec.js → cypress/e2e/move.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { slugifyCategory } from "../../src/utils"
import { slugifyCategory } from "utils"

import { E2E_EXTENDED_TIMEOUT } from "../fixtures/constants"

describe("Move flow", () => {
Expand Down Expand Up @@ -100,7 +101,7 @@ describe("Move flow", () => {
"Workspace",
TITLE_WORKSPACE_TO_FOLDER,
])
cy.get("u").last().getFirstSiblingAs("moveFolderUpdatedBreadcrumb", [])
cy.get("u").last().getFirstSiblingAs("moveFolderUpdatedBreadcrumb")
cy.verifyBreadcrumb("@moveFolderUpdatedBreadcrumb", [
"Workspace",
TEST_REPO_FOLDER_NAME,
Expand Down Expand Up @@ -128,7 +129,7 @@ describe("Move flow", () => {

cy.contains(`Move Here`)

cy.contains("button", "Move Here").clickAndWait()
cy.contains("button", "Move Here").click()

cy.contains("File is already in this folder", {
timeout: E2E_EXTENDED_TIMEOUT,
Expand All @@ -151,7 +152,7 @@ describe("Move flow", () => {
// Navigate to Move folder
cy.get("button[id^=moveModal-forwardButton-]")
.eq(1)
.clickAndWait({ force: true })
.click({ force: true })

// Assert
cy.get("u").first().getFirstSiblingAs("moveFolderCurrentBreadcrumb")
Expand All @@ -166,7 +167,7 @@ describe("Move flow", () => {
TITLE_WORKSPACE_TO_FOLDER,
])

cy.contains("button", "Move Here").clickAndWait()
cy.contains("button", "Move Here").click()

cy.contains("Successfully moved file", {
timeout: E2E_EXTENDED_TIMEOUT,
Expand Down Expand Up @@ -208,10 +209,10 @@ describe("Move flow", () => {
// Navigate to Move folder
cy.get("button[id^=moveModal-forwardButton-]")
.eq(1)
.clickAndWait({ force: true })
.click({ force: true })

// Navigate to Move subfolder
cy.get("button[id^=moveModal-forwardButton-]").clickAndWait({
cy.get("button[id^=moveModal-forwardButton-]").click({
force: true,
})

Expand All @@ -229,7 +230,7 @@ describe("Move flow", () => {
TITLE_WORKSPACE_TO_SUBFOLDER,
])

cy.contains("button", "Move Here").clickAndWait()
cy.contains("button", "Move Here").click()

cy.contains("Successfully moved file", {
timeout: E2E_EXTENDED_TIMEOUT,
Expand Down Expand Up @@ -363,7 +364,7 @@ describe("Move flow", () => {
TITLE_FOLDER_TO_WORKSPACE,
])

cy.get("#moveModal-backButton").clickAndWait({ force: true })
cy.get("#moveModal-backButton").click({ force: true })

// Assert
cy.get("u").last().getFirstSiblingAs("movedLocationBreadcrumb")
Expand All @@ -372,7 +373,7 @@ describe("Move flow", () => {
TITLE_FOLDER_TO_WORKSPACE,
])

cy.contains("button", "Move Here").clickAndWait()
cy.contains("button", "Move Here").click()

cy.contains("Successfully moved file", {
timeout: E2E_EXTENDED_TIMEOUT,
Expand Down Expand Up @@ -404,7 +405,7 @@ describe("Move flow", () => {
TITLE_FOLDER_TO_SUBFOLDER,
])

cy.get("button[id^=moveModal-forwardButton-]").clickAndWait({
cy.get("button[id^=moveModal-forwardButton-]").click({
force: true,
})

Expand All @@ -417,7 +418,7 @@ describe("Move flow", () => {
TITLE_FOLDER_TO_SUBFOLDER,
])

cy.contains("button", "Move Here").clickAndWait()
cy.contains("button", "Move Here").click()

cy.contains("Successfully moved file", {
timeout: E2E_EXTENDED_TIMEOUT,
Expand Down Expand Up @@ -512,7 +513,7 @@ describe("Move flow", () => {
.should("exist")
cy.clickContextMenuItem("@folderItem", "Move to")

cy.contains("button", "Move Here").clickAndWait()
cy.contains("button", "Move Here").click()

cy.contains("File is already in this folder", {
timeout: E2E_EXTENDED_TIMEOUT,
Expand Down Expand Up @@ -543,7 +544,7 @@ describe("Move flow", () => {
TITLE_SUBFOLDER_TO_WORKSPACE,
])

cy.get("#moveModal-backButton").clickAndWait({ force: true })
cy.get("#moveModal-backButton").click({ force: true })

// Assert
cy.get("u").last().getFirstSiblingAs("folderBreadcrumb")
Expand All @@ -553,7 +554,7 @@ describe("Move flow", () => {
TITLE_SUBFOLDER_TO_WORKSPACE,
])

cy.get("#moveModal-backButton").clickAndWait({ force: true })
cy.get("#moveModal-backButton").click({ force: true })

// Assert
cy.get("u").last().getFirstSiblingAs("workspaceBreadcrumb")
Expand All @@ -562,7 +563,7 @@ describe("Move flow", () => {
TITLE_SUBFOLDER_TO_WORKSPACE,
])

cy.contains("button", "Move Here").clickAndWait()
cy.contains("button", "Move Here").click()

cy.contains("Successfully moved file", {
timeout: E2E_EXTENDED_TIMEOUT,
Expand Down Expand Up @@ -605,7 +606,7 @@ describe("Move flow", () => {
TITLE_SUBFOLDER_TO_FOLDER,
])

cy.contains("button", "Move Here").clickAndWait()
cy.contains("button", "Move Here").click()

cy.contains("Successfully moved file", {
timeout: E2E_EXTENDED_TIMEOUT,
Expand Down Expand Up @@ -729,7 +730,7 @@ describe("Move flow", () => {
TITLE_RESOURCE_PAGE,
])

cy.contains("button", "Move Here").clickAndWait()
cy.contains("button", "Move Here").click()

cy.contains("Successfully moved file", {
timeout: E2E_EXTENDED_TIMEOUT,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import "cypress-file-upload"
import { slugifyCategory, generateResourceFileName } from "../../src/utils" // 30 seconds
import { slugifyCategory, generateResourceFileName } from "utils"

import {
E2E_EXTENDED_TIMEOUT,
E2E_DEFAULT_WAIT_TIME,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { slugifyCategory } from "../../src/utils"
import { slugifyCategory } from "utils"

import {
E2E_DEFAULT_WAIT_TIME,
E2E_EXTENDED_TIMEOUT,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,21 +46,8 @@ describe("Settings page", () => {
const SAMPLE_PAGE = "editPage/faq.md"
const HOMEPAGE = "homepage"

// Reusable save command
Cypress.Commands.add("saveSettings", () => {
cy.intercept("POST", "/v2/sites/e2e-test-repo/settings").as("awaitSave")
cy.contains("button", "Save").click()
cy.wait("@awaitSave")
})

// Reusable visit command
Cypress.Commands.add("visitLoadSettings", (sitePath) => {
cy.intercept("GET", `/v2/sites/${TEST_REPO_NAME}/settings`).as(
"awaitSettings"
)
cy.visit(sitePath)
cy.wait("@awaitSettings")
})
const visitLoadSettings = (sitePath: string) =>
cy.visitLoadSettings(TEST_REPO_NAME, sitePath)

Cypress.Cookies.defaults({
preserve: COOKIE_NAME,
Expand All @@ -72,7 +59,7 @@ describe("Settings page", () => {
cy.contains(TEST_REPO_NAME).click()

window.localStorage.setItem("userId", "test")
cy.visitLoadSettings(`/sites/${TEST_REPO_NAME}/settings`)
visitLoadSettings(`/sites/${TEST_REPO_NAME}/settings`)

// Reset page input field states
cy.get("#title").clear().type(BASE_TITLE)
Expand Down Expand Up @@ -131,7 +118,7 @@ describe("Settings page", () => {

beforeEach(() => {
window.localStorage.setItem("userId", "test")
cy.visitLoadSettings(`/sites/${TEST_REPO_NAME}/settings`)
visitLoadSettings(`/sites/${TEST_REPO_NAME}/settings`)
// Double check that settings are loaded before running tests cos sometimes the tests run too quickly
cy.get("#title").should((elem) => {
expect(elem.val()).to.have.length.greaterThan(0)
Expand Down Expand Up @@ -220,7 +207,7 @@ describe("Settings page", () => {
})

// [r, g, b] -> #RRGGBB
function rgbToHex(r, g, b) {
const rgbToHex = ([r, g, b, ...rest]: number[]) => {
// eslint-disable-next-line no-bitwise
return `#${((1 << 24) + (r << 16) + (g << 8) + b).toString(16).slice(1)}`
}
Expand Down Expand Up @@ -257,9 +244,9 @@ describe("Settings page", () => {

// Check if selected colors are reflected upon save
const rgbPrimary = `rgb(${TEST_PRIMARY_COLOR.join(", ")})`
const hexPrimary = rgbToHex(...TEST_PRIMARY_COLOR)
const hexPrimary = rgbToHex(TEST_PRIMARY_COLOR)
const rgbSecondary = `rgb(${TEST_SECONDARY_COLOR.join(", ")})`
const hexSecondary = rgbToHex(...TEST_SECONDARY_COLOR)
const hexSecondary = rgbToHex(TEST_SECONDARY_COLOR)
cy.contains("label", "Primary")
.parent()
.find("input")
Expand All @@ -280,13 +267,13 @@ describe("Settings page", () => {
.and("eq", rgbSecondary)

// Check if page previews reflect color change
cy.visitLoadSettings(`/sites/${TEST_REPO_NAME}/${SAMPLE_PAGE}`)
visitLoadSettings(`/sites/${TEST_REPO_NAME}/${SAMPLE_PAGE}`)
cy.get("section.bp-section-pagetitle") // Page title banner
.should("have.css", "background-color", rgbPrimary)

// Check if home page reflects color change
cy.visit(`/sites/${TEST_REPO_NAME}/workspace`) // Somehow colors won't load on homepage if visiting directly
cy.visitLoadSettings(`/sites/${TEST_REPO_NAME}/${HOMEPAGE}`)
visitLoadSettings(`/sites/${TEST_REPO_NAME}/${HOMEPAGE}`)
cy.get("#notification-bar")
.first() // Notification bar
.should("have.css", "background-color", rgbSecondary)
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
import {
deslugifyDirectory,
slugifyCategory,
titleToPageFileName,
} from "../../src/utils"
import { slugifyCategory, titleToPageFileName, deslugifyDirectory } from "utils"

import {
E2E_DEFAULT_WAIT_TIME,
E2E_EXTENDED_TIMEOUT,
Expand Down
File renamed without changes.
53 changes: 0 additions & 53 deletions cypress/plugins/index.js

This file was deleted.

3 changes: 3 additions & 0 deletions cypress/plugins/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import tsConfigPaths from "tsconfig-paths"

tsConfigPaths.register()
Loading