Skip to content

Commit

Permalink
test(refactor): ✅ Remove Shared Variables in Tests
Browse files Browse the repository at this point in the history
  • Loading branch information
krsiakdaniel committed Dec 26, 2024
1 parent bccde7d commit e87119c
Show file tree
Hide file tree
Showing 43 changed files with 147 additions and 195 deletions.
4 changes: 2 additions & 2 deletions __tests__/jest/generateUrls.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { URL_PERSONAL_PROJECTS, URL_WORK_EXPERIENCE } from '@/utils/constants/urls/pageUrls'
import { URL_PERSONAL_PROJECTS } from '@/utils/constants/urls/pageUrls'
import { getUrlPersonalProject, getUrlWorkExperience } from '@/utils/helpers/getPageUrls'

describe('getUrlWorkExperience', () => {
it('should return the correct URL for a given company', () => {
const company = 'exampleCompany'
const expectedUrl = `${URL_WORK_EXPERIENCE}/${company}`
const expectedUrl = `/work-experience/${company}`
const result = getUrlWorkExperience(company)
expect(result).toBe(expectedUrl)
})
Expand Down
6 changes: 2 additions & 4 deletions __tests__/playwright/about-me/aboutMe.spec.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
import { expect, test } from '@playwright/test'

import { getDataTestId } from '@/__tests__/playwright/utils/helpers/getDataTestId'
import { TEXT } from '@/localization/english'
import { DATA_TEST_IDS } from '@/utils/constants/ids/dataTestIds'
import { PAGES_URL } from '@/utils/constants/urls/pageUrls'

test.describe('About Me Page - Tests', () => {
test('Heading + text', async ({ page }) => {
await test.step('Go to page About me', async () => {
await page.goto(PAGES_URL.aboutMe)
await page.goto('/about-me')
})

await test.step('Check that the Heading text is correct', async () => {
const heading = await page.textContent('h1')
expect(heading).toBe(TEXT.aboutMe)
expect(heading).toBe('👨‍💻 About Me')
})

await test.step('Check that the paragraph text is correct', async () => {
Expand Down
7 changes: 3 additions & 4 deletions __tests__/playwright/breadcrumbs/aboutMe.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@ import { expect, test } from '@playwright/test'

import { getDataTestId } from '@/__tests__/playwright/utils/helpers/getDataTestId'
import { DATA_TEST_IDS } from '@/utils/constants/ids/dataTestIds'
import { PAGES_URL } from '@/utils/constants/urls/pageUrls'

test.describe('Links', () => {
test('should navigate correctly', async ({ page }) => {
await test.step('Go to About Me page', async () => {
await page.goto(PAGES_URL.aboutMe)
await page.goto('/about-me')
})

const breadcrumbs = page.locator(getDataTestId(DATA_TEST_IDS.breadcrumbs))
Expand All @@ -19,9 +18,9 @@ test.describe('Links', () => {
})

await test.step('Check the About Me link', async () => {
const aboutLink = breadcrumbs.locator(`a[href="${PAGES_URL.aboutMe}"]`)
const aboutLink = breadcrumbs.locator('a[href="/about-me"]')
expect(await aboutLink.count()).toBe(1)
expect(await aboutLink.getAttribute('href')).toBe(PAGES_URL.aboutMe)
expect(await aboutLink.getAttribute('href')).toBe('/about-me')
})
})
})
7 changes: 3 additions & 4 deletions __tests__/playwright/breadcrumbs/personalProjects.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@ import { expect, test } from '@playwright/test'

import { getDataTestId } from '@/__tests__/playwright/utils/helpers/getDataTestId'
import { DATA_TEST_IDS } from '@/utils/constants/ids/dataTestIds'
import { PAGES_URL } from '@/utils/constants/urls/pageUrls'

test.describe('Links', () => {
test('should navigate correctly', async ({ page }) => {
await test.step('Go to Personal projects page', async () => {
await page.goto(PAGES_URL.personal.mainUrl)
await page.goto('/personal-projects')
})

const breadcrumbs = page.locator(getDataTestId(DATA_TEST_IDS.breadcrumbs))
Expand All @@ -19,9 +18,9 @@ test.describe('Links', () => {
})

await test.step('Check the Personal Projects link', async () => {
const personalProjectsLink = breadcrumbs.locator(`a[href="${PAGES_URL.personal.mainUrl}"]`)
const personalProjectsLink = breadcrumbs.locator('a[href="/personal-projects"]')
expect(await personalProjectsLink.count()).toBe(1)
expect(await personalProjectsLink.getAttribute('href')).toBe(PAGES_URL.personal.mainUrl)
expect(await personalProjectsLink.getAttribute('href')).toBe('/personal-projects')
})
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@ import { expect, test } from '@playwright/test'

import { getDataTestId } from '@/__tests__/playwright/utils/helpers/getDataTestId'
import { DATA_TEST_IDS } from '@/utils/constants/ids/dataTestIds'
import { PAGES_URL } from '@/utils/constants/urls/pageUrls'

test.describe('Links', () => {
test('should navigate correctly', async ({ page }) => {
await test.step('Go to Cryptomania subpage', async () => {
await page.goto(PAGES_URL.personal.cryptoMania)
await page.goto('/personal-projects/cryptomania')
})

const breadcrumbs = page.locator(getDataTestId(DATA_TEST_IDS.breadcrumbs))
Expand All @@ -19,15 +18,15 @@ test.describe('Links', () => {
})

await test.step('Check the Personal Projects link', async () => {
const personalProjectsLink = breadcrumbs.locator(`a[href="${PAGES_URL.personal.mainUrl}"]`)
const personalProjectsLink = breadcrumbs.locator('a[href="/personal-projects"]')
expect(await personalProjectsLink.count()).toBe(1)
expect(await personalProjectsLink.getAttribute('href')).toBe(PAGES_URL.personal.mainUrl)
expect(await personalProjectsLink.getAttribute('href')).toBe('/personal-projects')
})

await test.step('Check the Cryptomania link', async () => {
const cryptomaniaLink = breadcrumbs.locator(`a[href="${PAGES_URL.personal.cryptoMania}"]`)
const cryptomaniaLink = breadcrumbs.locator('a[href="/personal-projects/cryptomania"]')
expect(await cryptomaniaLink.count()).toBe(1)
expect(await cryptomaniaLink.getAttribute('href')).toBe(PAGES_URL.personal.cryptoMania)
expect(await cryptomaniaLink.getAttribute('href')).toBe('/personal-projects/cryptomania')
})
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@ import { expect, test } from '@playwright/test'

import { getDataTestId } from '@/__tests__/playwright/utils/helpers/getDataTestId'
import { DATA_TEST_IDS } from '@/utils/constants/ids/dataTestIds'
import { PAGES_URL } from '@/utils/constants/urls/pageUrls'

test.describe('Links', () => {
test('should navigate correctly', async ({ page }) => {
await test.step('Go to Portfolio Website subpage', async () => {
await page.goto(PAGES_URL.personal.krsiak)
await page.goto('personal-projects/krsiak')
})

const breadcrumbs = page.locator(getDataTestId(DATA_TEST_IDS.breadcrumbs))
Expand All @@ -19,15 +18,15 @@ test.describe('Links', () => {
})

await test.step('Check the Personal Projects link', async () => {
const personalProjectsLink = breadcrumbs.locator(`a[href="${PAGES_URL.personal.mainUrl}"]`)
const personalProjectsLink = breadcrumbs.locator('a[href="/personal-projects"]')
expect(await personalProjectsLink.count()).toBe(1)
expect(await personalProjectsLink.getAttribute('href')).toBe(PAGES_URL.personal.mainUrl)
expect(await personalProjectsLink.getAttribute('href')).toBe('/personal-projects')
})

await test.step('Check the Portfolio Website link', async () => {
const portfolioWebsiteLink = breadcrumbs.locator(`a[href="${PAGES_URL.personal.krsiak}"]`)
const portfolioWebsiteLink = breadcrumbs.locator('a[href="/personal-projects/krsiak"]')
expect(await portfolioWebsiteLink.count()).toBe(1)
expect(await portfolioWebsiteLink.getAttribute('href')).toBe(PAGES_URL.personal.krsiak)
expect(await portfolioWebsiteLink.getAttribute('href')).toBe('/personal-projects/krsiak')
})
})
})
11 changes: 5 additions & 6 deletions __tests__/playwright/breadcrumbs/projects/work/groupon.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@ import { expect, test } from '@playwright/test'

import { getDataTestId } from '@/__tests__/playwright/utils/helpers/getDataTestId'
import { DATA_TEST_IDS } from '@/utils/constants/ids/dataTestIds'
import { PAGES_URL } from '@/utils/constants/urls/pageUrls'

test.describe('Links', () => {
test('should navigate correctly', async ({ page }) => {
await test.step('Go to Groupon subpage', async () => {
await page.goto(PAGES_URL.work.groupon)
await page.goto('/work-experience/groupon')
})

const breadcrumbs = page.locator(getDataTestId(DATA_TEST_IDS.breadcrumbs))
Expand All @@ -19,15 +18,15 @@ test.describe('Links', () => {
})

await test.step('Check the Work Experience link', async () => {
const workExperienceLink = breadcrumbs.locator(`a[href="${PAGES_URL.work.mainUrl}"]`)
const workExperienceLink = breadcrumbs.locator('a[href="/work-experience"]')
expect(await workExperienceLink.count()).toBe(1)
expect(await workExperienceLink.getAttribute('href')).toBe(PAGES_URL.work.mainUrl)
expect(await workExperienceLink.getAttribute('href')).toBe('/work-experience')
})

await test.step('Check the Groupon link', async () => {
const grouponLink = breadcrumbs.locator(`a[href="${PAGES_URL.work.groupon}"]`)
const grouponLink = breadcrumbs.locator('a[href="/work-experience/groupon"]')
expect(await grouponLink.count()).toBe(1)
expect(await grouponLink.getAttribute('href')).toBe(PAGES_URL.work.groupon)
expect(await grouponLink.getAttribute('href')).toBe('/work-experience/groupon')
})
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@ import { expect, test } from '@playwright/test'

import { getDataTestId } from '@/__tests__/playwright/utils/helpers/getDataTestId'
import { DATA_TEST_IDS } from '@/utils/constants/ids/dataTestIds'
import { PAGES_URL } from '@/utils/constants/urls/pageUrls'

test.describe('Links', () => {
test('should navigate correctly', async ({ page }) => {
await test.step('Go to Komercni Banka subpage', async () => {
await page.goto(PAGES_URL.work.komercniBanka)
await page.goto('/work-experience/komercni-banka')
})

const breadcrumbs = page.locator(getDataTestId(DATA_TEST_IDS.breadcrumbs))
Expand All @@ -19,15 +18,15 @@ test.describe('Links', () => {
})

await test.step('Check the Work Experience link', async () => {
const workExperienceLink = breadcrumbs.locator(`a[href="${PAGES_URL.work.mainUrl}"]`)
const workExperienceLink = breadcrumbs.locator('a[href="/work-experience"]')
expect(await workExperienceLink.count()).toBe(1)
expect(await workExperienceLink.getAttribute('href')).toBe(PAGES_URL.work.mainUrl)
expect(await workExperienceLink.getAttribute('href')).toBe('/work-experience')
})

await test.step('Check the Komercni Banka link', async () => {
const komercniBankaLink = breadcrumbs.locator(`a[href="${PAGES_URL.work.komercniBanka}"]`)
const komercniBankaLink = breadcrumbs.locator('a[href="/work-experience/komercni-banka"]')
expect(await komercniBankaLink.count()).toBe(1)
expect(await komercniBankaLink.getAttribute('href')).toBe(PAGES_URL.work.komercniBanka)
expect(await komercniBankaLink.getAttribute('href')).toBe('/work-experience/komercni-banka')
})
})
})
11 changes: 5 additions & 6 deletions __tests__/playwright/breadcrumbs/projects/work/moravia.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@ import { expect, test } from '@playwright/test'

import { getDataTestId } from '@/__tests__/playwright/utils/helpers/getDataTestId'
import { DATA_TEST_IDS } from '@/utils/constants/ids/dataTestIds'
import { PAGES_URL } from '@/utils/constants/urls/pageUrls'

test.describe('Links', () => {
test('should navigate correctly', async ({ page }) => {
await test.step('Go to Moravia subpage', async () => {
await page.goto(PAGES_URL.work.moravia)
await page.goto('/work-experience/moravia')
})

const breadcrumbs = page.locator(getDataTestId(DATA_TEST_IDS.breadcrumbs))
Expand All @@ -19,15 +18,15 @@ test.describe('Links', () => {
})

await test.step('Check the Work Experience link', async () => {
const workExperienceLink = breadcrumbs.locator(`a[href="${PAGES_URL.work.mainUrl}"]`)
const workExperienceLink = breadcrumbs.locator('a[href="/work-experience"]')
expect(await workExperienceLink.count()).toBe(1)
expect(await workExperienceLink.getAttribute('href')).toBe(PAGES_URL.work.mainUrl)
expect(await workExperienceLink.getAttribute('href')).toBe('/work-experience')
})

await test.step('Check the Moravia link', async () => {
const moraviaLink = breadcrumbs.locator(`a[href="${PAGES_URL.work.moravia}"]`)
const moraviaLink = breadcrumbs.locator('a[href="/work-experience/moravia"]')
expect(await moraviaLink.count()).toBe(1)
expect(await moraviaLink.getAttribute('href')).toBe(PAGES_URL.work.moravia)
expect(await moraviaLink.getAttribute('href')).toBe('/work-experience/moravia')
})
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@ import { expect, test } from '@playwright/test'

import { getDataTestId } from '@/__tests__/playwright/utils/helpers/getDataTestId'
import { DATA_TEST_IDS } from '@/utils/constants/ids/dataTestIds'
import { PAGES_URL } from '@/utils/constants/urls/pageUrls'

test.describe('Links', () => {
test('should navigate correctly', async ({ page }) => {
await test.step('Go to Smartsupp dashboard subpage', async () => {
await page.goto(PAGES_URL.work.smartsupp.dashboard)
await page.goto('/work-experience/smartsupp-dashboard')
})

const breadcrumbs = page.locator(getDataTestId(DATA_TEST_IDS.breadcrumbs))
Expand All @@ -19,15 +18,15 @@ test.describe('Links', () => {
})

await test.step('Check the Work Experience link', async () => {
const workExperienceLink = breadcrumbs.locator(`a[href="${PAGES_URL.work.mainUrl}"]`)
const workExperienceLink = breadcrumbs.locator('a[href="/work-experience"]')
expect(await workExperienceLink.count()).toBe(1)
expect(await workExperienceLink.getAttribute('href')).toBe(PAGES_URL.work.mainUrl)
expect(await workExperienceLink.getAttribute('href')).toBe('/work-experience')
})

await test.step('Check the Smartsupp Dashboard link', async () => {
const smartsuppDashboardLink = breadcrumbs.locator(`a[href="${PAGES_URL.work.smartsupp.dashboard}"]`)
const smartsuppDashboardLink = breadcrumbs.locator('a[href="/work-experience/smartsupp-dashboard"]')
expect(await smartsuppDashboardLink.count()).toBe(1)
expect(await smartsuppDashboardLink.getAttribute('href')).toBe(PAGES_URL.work.smartsupp.dashboard)
expect(await smartsuppDashboardLink.getAttribute('href')).toBe('/work-experience/smartsupp-dashboard')
})
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@ import { expect, test } from '@playwright/test'

import { getDataTestId } from '@/__tests__/playwright/utils/helpers/getDataTestId'
import { DATA_TEST_IDS } from '@/utils/constants/ids/dataTestIds'
import { PAGES_URL } from '@/utils/constants/urls/pageUrls'

test.describe('Links', () => {
test('should navigate correctly', async ({ page }) => {
await test.step('Go to Smartsupp HELP subpage', async () => {
await page.goto(PAGES_URL.work.smartsupp.help)
await page.goto('/work-experience/smartsupp-help')
})

const breadcrumbs = page.locator(getDataTestId(DATA_TEST_IDS.breadcrumbs))
Expand All @@ -19,15 +18,15 @@ test.describe('Links', () => {
})

await test.step('Check the Work Experience link', async () => {
const workExperienceLink = breadcrumbs.locator(`a[href="${PAGES_URL.work.mainUrl}"]`)
const workExperienceLink = breadcrumbs.locator('a[href="/work-experience"]')
expect(await workExperienceLink.count()).toBe(1)
expect(await workExperienceLink.getAttribute('href')).toBe(PAGES_URL.work.mainUrl)
expect(await workExperienceLink.getAttribute('href')).toBe('/work-experience')
})

await test.step('Check the Smartsupp HELP link', async () => {
const smartsuppHelpLink = breadcrumbs.locator(`a[href="${PAGES_URL.work.smartsupp.help}"]`)
const smartsuppHelpLink = breadcrumbs.locator('a[href="/work-experience/smartsupp-help"]')
expect(await smartsuppHelpLink.count()).toBe(1)
expect(await smartsuppHelpLink.getAttribute('href')).toBe(PAGES_URL.work.smartsupp.help)
expect(await smartsuppHelpLink.getAttribute('href')).toBe('/work-experience/smartsupp-help')
})
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@ import { expect, test } from '@playwright/test'

import { getDataTestId } from '@/__tests__/playwright/utils/helpers/getDataTestId'
import { DATA_TEST_IDS } from '@/utils/constants/ids/dataTestIds'
import { PAGES_URL } from '@/utils/constants/urls/pageUrls'

test.describe('Links', () => {
test('should navigate correctly', async ({ page }) => {
await test.step('Go to Smartsupp web subpage', async () => {
await page.goto(PAGES_URL.work.smartsupp.web)
await page.goto('/work-experience/smartsupp-web')
})

const breadcrumbs = page.locator(getDataTestId(DATA_TEST_IDS.breadcrumbs))
Expand All @@ -19,15 +18,15 @@ test.describe('Links', () => {
})

await test.step('Check the Work Experience link', async () => {
const workExperienceLink = breadcrumbs.locator(`a[href="${PAGES_URL.work.mainUrl}"]`)
const workExperienceLink = breadcrumbs.locator('a[href="/work-experience"]')
expect(await workExperienceLink.count()).toBe(1)
expect(await workExperienceLink.getAttribute('href')).toBe(PAGES_URL.work.mainUrl)
expect(await workExperienceLink.getAttribute('href')).toBe('/work-experience')
})

await test.step('Check the Smartsupp Web link', async () => {
const smartsuppWebLink = breadcrumbs.locator(`a[href="${PAGES_URL.work.smartsupp.web}"]`)
const smartsuppWebLink = breadcrumbs.locator('a[href="/work-experience/smartsupp-web"]')
expect(await smartsuppWebLink.count()).toBe(1)
expect(await smartsuppWebLink.getAttribute('href')).toBe(PAGES_URL.work.smartsupp.web)
expect(await smartsuppWebLink.getAttribute('href')).toBe('/work-experience/smartsupp-web')
})
})
})
7 changes: 3 additions & 4 deletions __tests__/playwright/breadcrumbs/resume.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@ import { expect, test } from '@playwright/test'

import { getDataTestId } from '@/__tests__/playwright/utils/helpers/getDataTestId'
import { DATA_TEST_IDS } from '@/utils/constants/ids/dataTestIds'
import { PAGES_URL } from '@/utils/constants/urls/pageUrls'

test.describe('Links', () => {
test('should navigate correctly', async ({ page }) => {
await test.step('Go to Resume page', async () => {
await page.goto(PAGES_URL.resume)
await page.goto('/resume')
})

const breadcrumbs = page.locator(getDataTestId(DATA_TEST_IDS.breadcrumbs))
Expand All @@ -19,9 +18,9 @@ test.describe('Links', () => {
})

await test.step('Check the Resume link', async () => {
const aboutLink = breadcrumbs.locator(`a[href="${PAGES_URL.resume}"]`)
const aboutLink = breadcrumbs.locator('a[href="/resume"]')
expect(await aboutLink.count()).toBe(1)
expect(await aboutLink.getAttribute('href')).toBe(PAGES_URL.resume)
expect(await aboutLink.getAttribute('href')).toBe('/resume')
})
})
})
Loading

0 comments on commit e87119c

Please sign in to comment.