|
1 | 1 | import { |
2 | 2 | Priority, |
3 | 3 | RouteDirectionEnum, |
| 4 | + RouteInsertInput, |
4 | 5 | } from '@hsl/jore4-test-db-manager/dist/CypressSpecExports'; |
| 6 | +import identity from 'lodash/identity'; |
| 7 | +import range from 'lodash/range'; |
5 | 8 | import { DateTime } from 'luxon'; |
6 | 9 | import { |
7 | 10 | buildInfraLinksAlongRoute, |
8 | 11 | buildStopsOnInfraLinks, |
9 | 12 | getClonedBaseDbResources, |
10 | 13 | testInfraLinkExternalIds, |
11 | 14 | } from '../datasets/base'; |
| 15 | +import { getClonedBaseStopRegistryData } from '../datasets/stopRegistry'; |
12 | 16 | import { Tag } from '../enums'; |
13 | 17 | import { |
| 18 | + BasicDetailsViewCard, |
14 | 19 | ConfirmationDialog, |
15 | 20 | EditRoutePage, |
16 | 21 | LineChangeHistory, |
17 | 22 | LineDetailsPage, |
| 23 | + LineForm, |
| 24 | + LineRouteList, |
18 | 25 | RouteRow, |
| 26 | + StopsNeedingUpdateModal, |
19 | 27 | TerminusNameInputs, |
20 | 28 | Toast, |
21 | 29 | ValidityPeriodForm, |
22 | 30 | } from '../pageObjects'; |
23 | 31 | import { UUID } from '../types'; |
24 | | -import { SupportedResources, insertToDbHelper } from '../utils'; |
| 32 | +import { SupportedResources, insertToDbHelper, mapAt } from '../utils'; |
25 | 33 | import { expectGraphQLCallToSucceed } from '../utils/assertions'; |
| 34 | +import { InsertedStopRegistryIds } from './utils'; |
26 | 35 |
|
27 | 36 | describe('Route editing', { tags: [Tag.Routes] }, () => { |
28 | 37 | let dbResources: SupportedResources; |
@@ -338,4 +347,167 @@ describe('Route editing', { tags: [Tag.Routes] }, () => { |
338 | 347 | ); |
339 | 348 | }); |
340 | 349 | }); |
| 350 | + |
| 351 | + describe('Trunk Line bus Route', () => { |
| 352 | + const { lineRouteListItem } = LineRouteList; |
| 353 | + const { routeRow, routeStopListItem } = lineRouteListItem; |
| 354 | + |
| 355 | + function buildTestData(infraLinkIds: ReadonlyArray<UUID>) { |
| 356 | + const stops = buildStopsOnInfraLinks(infraLinkIds); |
| 357 | + const infraLinksAlongRoute = buildInfraLinksAlongRoute(infraLinkIds); |
| 358 | + |
| 359 | + return { |
| 360 | + ...getClonedBaseDbResources(), |
| 361 | + stops, |
| 362 | + infraLinksAlongRoute, |
| 363 | + }; |
| 364 | + } |
| 365 | + |
| 366 | + function initTrunkLineTest( |
| 367 | + editResources: ( |
| 368 | + resources: ReturnType<typeof buildTestData>, |
| 369 | + ) => SupportedResources = identity, |
| 370 | + ) { |
| 371 | + cy.task<UUID[]>( |
| 372 | + 'getInfrastructureLinkIdsByExternalIds', |
| 373 | + testInfraLinkExternalIds, |
| 374 | + ) |
| 375 | + .then(buildTestData) |
| 376 | + .then(editResources) |
| 377 | + .then((testResources) => { |
| 378 | + cy.task('resetDbs'); |
| 379 | + insertToDbHelper(testResources); |
| 380 | + |
| 381 | + cy.task<InsertedStopRegistryIds>( |
| 382 | + 'insertStopRegistryData', |
| 383 | + getClonedBaseStopRegistryData(), |
| 384 | + ); |
| 385 | + |
| 386 | + cy.setupTests(); |
| 387 | + cy.mockLogin(); |
| 388 | + }); |
| 389 | + } |
| 390 | + |
| 391 | + function setRouteToDraft(route: RouteInsertInput): RouteInsertInput { |
| 392 | + return { ...route, priority: Priority.Draft }; |
| 393 | + } |
| 394 | + |
| 395 | + function setLineTypeToTrunkLineType() { |
| 396 | + LineDetailsPage.getEditLineButton().click(); |
| 397 | + LineForm.selectLineType('Runkolinja'); |
| 398 | + LineForm.save(); |
| 399 | + } |
| 400 | + |
| 401 | + function addExcludedStopToRoute() { |
| 402 | + LineRouteList.getShowUnusedStopsSwitch().click(); |
| 403 | + |
| 404 | + LineRouteList.getNthLineRouteListItem(1).within(() => { |
| 405 | + routeRow.getToggleAccordionButton().click(); |
| 406 | + |
| 407 | + lineRouteListItem |
| 408 | + .getNthRouteStopListItem(4) |
| 409 | + .should('contain', 'E2E010') |
| 410 | + .and('contain', 'Ei reitin käytössä'); |
| 411 | + |
| 412 | + // Add E2E010 to the route |
| 413 | + lineRouteListItem.getNthRouteStopListItem(4).within(() => { |
| 414 | + routeStopListItem.getStopActionsDropdown().click(); |
| 415 | + cy.withinHeadlessPortal(() => |
| 416 | + routeStopListItem.stopActionsDropdown |
| 417 | + .getAddStopToRouteButton() |
| 418 | + .click(), |
| 419 | + ); |
| 420 | + }); |
| 421 | + }); |
| 422 | + } |
| 423 | + |
| 424 | + function assertStopsAreTrunkLine(areTrunkLine: boolean) { |
| 425 | + const expectedContent = areTrunkLine ? 'Runkolinjapysäkki' : '-'; |
| 426 | + |
| 427 | + LineRouteList.getNthLineRouteListItem(1).within(() => { |
| 428 | + lineRouteListItem |
| 429 | + .getNthRouteStopListItem(0) |
| 430 | + .within(() => lineRouteListItem.getLabel().click()); |
| 431 | + }); |
| 432 | + |
| 433 | + BasicDetailsViewCard.getStopType() |
| 434 | + .shouldBeVisible() |
| 435 | + .shouldHaveText(expectedContent); |
| 436 | + cy.go(-1); |
| 437 | + |
| 438 | + LineRouteList.getNthLineRouteListItem(1).within(() => { |
| 439 | + routeRow.getToggleAccordionButton().click(); |
| 440 | + |
| 441 | + lineRouteListItem |
| 442 | + .getNthRouteStopListItem(4) |
| 443 | + .within(() => lineRouteListItem.getLabel().click()); |
| 444 | + }); |
| 445 | + |
| 446 | + BasicDetailsViewCard.getStopType() |
| 447 | + .shouldBeVisible() |
| 448 | + .shouldHaveText(expectedContent); |
| 449 | + } |
| 450 | + |
| 451 | + it('Should not update stop Trunk Line status for Draft route', () => { |
| 452 | + cy.section('Init test data', () => { |
| 453 | + initTrunkLineTest((resources) => ({ |
| 454 | + ...resources, |
| 455 | + routes: mapAt(resources.routes, { |
| 456 | + 0: setRouteToDraft, |
| 457 | + 1: setRouteToDraft, |
| 458 | + }), |
| 459 | + })); |
| 460 | + }); |
| 461 | + |
| 462 | + LineDetailsPage.visit(baseDbResources.lines[0].line_id); |
| 463 | + |
| 464 | + cy.section('Change line type to Trunk Line', () => { |
| 465 | + setLineTypeToTrunkLineType(); |
| 466 | + LineForm.checkLineSubmitSuccess(); |
| 467 | + }); |
| 468 | + |
| 469 | + LineDetailsPage.getShowDraftsButton().click(); |
| 470 | + |
| 471 | + cy.section('Toggle a stop onto a Trunk Line', () => { |
| 472 | + addExcludedStopToRoute(); |
| 473 | + Toast.expectSuccessToast('Reitti tallennettu'); |
| 474 | + }); |
| 475 | + |
| 476 | + cy.section('Assert stop Trunk Line status', () => |
| 477 | + assertStopsAreTrunkLine(false), |
| 478 | + ); |
| 479 | + }); |
| 480 | + |
| 481 | + it('Should update stop Trunk Line status for non Draft route', () => { |
| 482 | + cy.section('Init test data', () => initTrunkLineTest()); |
| 483 | + |
| 484 | + LineDetailsPage.visit(baseDbResources.lines[0].line_id); |
| 485 | + |
| 486 | + cy.section('Change line type to Trunk Line', () => { |
| 487 | + setLineTypeToTrunkLineType(); |
| 488 | + |
| 489 | + StopsNeedingUpdateModal.getModal().shouldBeVisible(); |
| 490 | + range(1, 10).forEach((i) => |
| 491 | + StopsNeedingUpdateModal.getStopLink(`E2E00${i}`).shouldBeVisible(), |
| 492 | + ); |
| 493 | + StopsNeedingUpdateModal.getConfirmButton().click(); |
| 494 | + |
| 495 | + LineForm.checkLineSubmitSuccess(); |
| 496 | + }); |
| 497 | + |
| 498 | + cy.section('Toggle a stop onto a Trunk Line', () => { |
| 499 | + addExcludedStopToRoute(); |
| 500 | + |
| 501 | + StopsNeedingUpdateModal.getModal().shouldBeVisible(); |
| 502 | + StopsNeedingUpdateModal.getStopLink('E2E010').shouldBeVisible(); |
| 503 | + StopsNeedingUpdateModal.getConfirmButton().click(); |
| 504 | + |
| 505 | + Toast.expectSuccessToast('Reitti tallennettu'); |
| 506 | + }); |
| 507 | + |
| 508 | + cy.section('Assert stop Trunk Line status', () => |
| 509 | + assertStopsAreTrunkLine(true), |
| 510 | + ); |
| 511 | + }); |
| 512 | + }); |
341 | 513 | }); |
0 commit comments