Skip to content

Commit

Permalink
test: Add tests for trips history (#1046)
Browse files Browse the repository at this point in the history
Co-authored-by: Noam Gaash <noam.gaash@gmail.com>
  • Loading branch information
YaelChen and NoamGaash authored Feb 26, 2025
1 parent 0dd173d commit d2ce4fb
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 1 deletion.
31 changes: 31 additions & 0 deletions tests/singlelineTest.spec.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import moment from 'moment'
import SinglelinePage from '../src/test_pages/SinglelinePage'
import { getPastDate, test, expect, urlMatcher } from './utils'

Expand Down Expand Up @@ -97,3 +98,33 @@ test.describe('Single line page tests', () => {
})
})
})

test('verify API call to gtfs_agencies/list - "Map by line"', async ({ page }) => {
let apiCallMade = false
page.on('request', (request) => {
if (request.url().includes('gtfs_agencies/list')) {
apiCallMade = true
}
})

await page.goto('/')
await page.getByRole('link', { name: 'מפה לפי קו' }).click()
await page.getByLabel('חברה מפעילה').click()
expect(apiCallMade).toBeTruthy()
})

test('Verify date_from parameter from "Map by line"', async ({ page }) => {
const apiRequest = page.waitForRequest((request) => request.url().includes('gtfs_agencies/list'))

await page.goto('/')
await page.getByRole('link', { name: 'מפה לפי קו' }).click()

const request = await apiRequest
const url = new URL(request.url())
const dateFromParam = url.searchParams.get('date_from')
const dateFrom = moment(dateFromParam)
const daysAgo = moment().diff(dateFrom, 'days')

expect(daysAgo).toBeGreaterThanOrEqual(0)
expect(daysAgo).toBeLessThanOrEqual(3)
})
35 changes: 34 additions & 1 deletion tests/timeline.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import i18next from 'i18next'
import Backend from 'i18next-fs-backend'
import moment from 'moment'
import TimelinePage from '../src/test_pages/TimelinePage'
import { getPastDate, test, urlMatcher } from './utils'
import { getPastDate, test, expect, urlMatcher } from './utils'

test.describe('Timeline Page Tests', () => {
let timelinePage: TimelinePage
Expand Down Expand Up @@ -138,3 +139,35 @@ test.describe('Timeline Page Tests', () => {
await timelinePage.verifyRouteSelectionVisible(timelinePage.timelineGraph, true, 100000)
})
})

test('verify API call to gtfs_agencies/list - "Trips history"', async ({ page }) => {
let apiCallMade = false
page.on('request', (request) => {
if (request.url().includes('gtfs_agencies/list')) {
apiCallMade = true
}
})

await page.goto('/')
await page.getByRole('link', { name: 'היסטוריית נסיעות' }).click()
await page.getByLabel('חברה מפעילה').click()
expect(apiCallMade).toBeTruthy()
})

test('the dateFrom parameter should be recent when visiting the "Trips history"', async ({
page,
}) => {
const apiRequest = page.waitForRequest((request) => request.url().includes('gtfs_agencies/list'))

await page.goto('/')
await page.getByRole('link', { name: 'היסטוריית נסיעות' }).click()

const request = await apiRequest
const url = new URL(request.url())
const dateFromParam = url.searchParams.get('date_from')
const dateFrom = moment(dateFromParam)
const daysAgo = moment().diff(dateFrom, 'days')

expect(daysAgo).toBeGreaterThanOrEqual(0)
expect(daysAgo).toBeLessThanOrEqual(3)
})

0 comments on commit d2ce4fb

Please sign in to comment.