-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: added building cancellation feature, added building scheduling …
…feature, refactored test env, added building interface tests
- Loading branch information
Showing
37 changed files
with
887 additions
and
392 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
87 changes: 0 additions & 87 deletions
87
src/app/[game]/[map]/components/__tests__/map-controls.test.tsx
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
192 changes: 192 additions & 0 deletions
192
src/app/[game]/[village]/components/__tests__/building-actions.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,192 @@ | ||
import { QueryClient } from '@tanstack/react-query'; | ||
import { screen } from '@testing-library/react'; | ||
import { BuildingActions } from 'app/[game]/[village]/components/building-actions'; | ||
import { villagesCacheKey } from 'app/[game]/hooks/use-villages'; | ||
import type { Resources } from 'interfaces/models/game/resource'; | ||
import type { BuildingField, Village } from 'interfaces/models/game/village'; | ||
import { serverPathMock } from 'mocks/game/server-mock'; | ||
import { villageMock } from 'mocks/game/village/village-mock'; | ||
import { renderWithGameContext } from 'test-utils'; | ||
import { describe } from 'vitest'; | ||
|
||
const level1MainBuildingBuildingField: BuildingField = { | ||
buildingId: 'MAIN_BUILDING', | ||
id: 38, | ||
level: 1, | ||
}; | ||
|
||
const level10MainBuildingBuildingField: BuildingField = { | ||
buildingId: 'MAIN_BUILDING', | ||
id: 38, | ||
level: 10, | ||
}; | ||
|
||
const level1CrannyBuildingField: BuildingField = { | ||
buildingId: 'MAIN_BUILDING', | ||
id: 37, | ||
level: 1, | ||
}; | ||
|
||
const level10CrannyBuildingField: BuildingField = { | ||
buildingId: 'MAIN_BUILDING', | ||
id: 37, | ||
level: 10, | ||
}; | ||
|
||
const noResources: Resources = { | ||
wood: 0, | ||
clay: 0, | ||
iron: 0, | ||
wheat: 0, | ||
}; | ||
|
||
describe('Main building level 1 on building field with cranny already built', () => { | ||
const queryClient = new QueryClient(); | ||
|
||
const buildingFields: BuildingField[] = [level1MainBuildingBuildingField, level1CrannyBuildingField]; | ||
|
||
const villageMockWithLevel1MainBuilding: Village = { | ||
...villageMock, | ||
buildingFields, | ||
}; | ||
queryClient.setQueryData<Village[]>([villagesCacheKey], [villageMockWithLevel1MainBuilding]); | ||
|
||
test('Upgrade button should be rendered and enabled', () => { | ||
renderWithGameContext(<BuildingActions buildingId="CRANNY" />, { queryClient, path: `${serverPathMock}/v-1/village/37` }); | ||
const upgradeButton = screen.getByTestId('building-actions-upgrade-building-button'); | ||
|
||
expect(upgradeButton).toBeInTheDocument(); | ||
expect(upgradeButton).not.toBeDisabled(); | ||
}); | ||
|
||
test('Max level cranny should not have upgrade button rendered', () => { | ||
const queryClient = new QueryClient(); | ||
|
||
const buildingFields: BuildingField[] = [level1MainBuildingBuildingField, level10CrannyBuildingField]; | ||
|
||
const villageMockWithLevel1MainBuilding: Village = { | ||
...villageMock, | ||
buildingFields, | ||
}; | ||
|
||
queryClient.setQueryData<Village[]>([villagesCacheKey], [villageMockWithLevel1MainBuilding]); | ||
|
||
renderWithGameContext(<BuildingActions buildingId="CRANNY" />, { queryClient, path: `${serverPathMock}/v-1/village/37` }); | ||
const upgradeButton = screen.queryByTestId('building-actions-upgrade-building-button'); | ||
|
||
expect(upgradeButton).not.toBeInTheDocument(); | ||
}); | ||
|
||
test('Upgrade button should be rendered and enabled', () => { | ||
renderWithGameContext(<BuildingActions buildingId="CRANNY" />, { queryClient, path: `${serverPathMock}/v-1/village/37` }); | ||
const upgradeButton = screen.getByTestId('building-actions-upgrade-building-button'); | ||
|
||
expect(upgradeButton).toBeInTheDocument(); | ||
expect(upgradeButton).not.toBeDisabled(); | ||
}); | ||
|
||
test('Downgrade and demolish buttons should not be rendered', () => { | ||
renderWithGameContext(<BuildingActions buildingId="CRANNY" />, { queryClient, path: `${serverPathMock}/v-1/village/37` }); | ||
const downgradeButton = screen.queryByTestId('building-actions-downgrade-building-button'); | ||
const demolishButton = screen.queryByTestId('building-actions-demolish-building-button'); | ||
|
||
expect(downgradeButton).not.toBeInTheDocument(); | ||
expect(demolishButton).not.toBeInTheDocument(); | ||
}); | ||
|
||
test('Construct button should not be rendered', () => { | ||
renderWithGameContext(<BuildingActions buildingId="CRANNY" />, { queryClient, path: `${serverPathMock}/v-1/village/37` }); | ||
const upgradeButton = screen.queryByTestId('building-actions-construct-building-button'); | ||
|
||
expect(upgradeButton).not.toBeInTheDocument(); | ||
}); | ||
}); | ||
|
||
describe('Main building level 10 on building field with cranny already built', () => { | ||
const queryClient = new QueryClient(); | ||
|
||
const buildingFields: BuildingField[] = [level10MainBuildingBuildingField, level1CrannyBuildingField]; | ||
|
||
const villageMockWithLevel10MainBuilding: Village = { | ||
...villageMock, | ||
buildingFields, | ||
}; | ||
queryClient.setQueryData<Village[]>([villagesCacheKey], [villageMockWithLevel10MainBuilding]); | ||
|
||
test('Downgrade should not be rendered if building is level 1', () => { | ||
renderWithGameContext(<BuildingActions buildingId="CRANNY" />, { queryClient, path: `${serverPathMock}/v-1/village/37` }); | ||
const downgradeButton = screen.queryByTestId('building-actions-downgrade-building-button'); | ||
|
||
expect(downgradeButton).not.toBeInTheDocument(); | ||
}); | ||
|
||
test('Demolish button should be rendered', () => { | ||
renderWithGameContext(<BuildingActions buildingId="CRANNY" />, { queryClient, path: `${serverPathMock}/v-1/village/37` }); | ||
const demolishButton = screen.getByTestId('building-actions-demolish-building-button'); | ||
|
||
expect(demolishButton).toBeInTheDocument(); | ||
}); | ||
}); | ||
|
||
describe('Different building field', () => { | ||
const queryClient = new QueryClient(); | ||
|
||
const buildingFields: BuildingField[] = [level10MainBuildingBuildingField]; | ||
|
||
const villageMockWithLevel10MainBuilding: Village = { | ||
...villageMock, | ||
buildingFields, | ||
}; | ||
queryClient.setQueryData<Village[]>([villagesCacheKey], [villageMockWithLevel10MainBuilding]); | ||
|
||
test('Only construct button should be rendered', () => { | ||
renderWithGameContext(<BuildingActions buildingId="CRANNY" />, { queryClient, path: `${serverPathMock}/v-1/village/36` }); | ||
const upgradeButton = screen.queryByTestId('building-actions-upgrade-building-button'); | ||
const downgradeButton = screen.queryByTestId('building-actions-downgrade-building-button'); | ||
const constructButton = screen.getByTestId('building-actions-construct-building-button'); | ||
const demolishButton = screen.queryByTestId('building-actions-demolish-building-button'); | ||
|
||
expect(upgradeButton).not.toBeInTheDocument(); | ||
expect(downgradeButton).not.toBeInTheDocument(); | ||
expect(demolishButton).not.toBeInTheDocument(); | ||
expect(constructButton).toBeInTheDocument(); | ||
}); | ||
}); | ||
|
||
test('Construct button should be disabled with insufficient resources', () => { | ||
const queryClient = new QueryClient(); | ||
|
||
const buildingFields: BuildingField[] = [level10MainBuildingBuildingField]; | ||
|
||
const villageMockWithLevel10MainBuilding: Village = { | ||
...villageMock, | ||
buildingFields, | ||
resources: noResources, | ||
}; | ||
queryClient.setQueryData<Village[]>([villagesCacheKey], [villageMockWithLevel10MainBuilding]); | ||
|
||
renderWithGameContext(<BuildingActions buildingId="CRANNY" />, { queryClient, path: `${serverPathMock}/v-1/village/36` }); | ||
const constructButton = screen.getByTestId('building-actions-construct-building-button'); | ||
|
||
expect(constructButton).toBeInTheDocument(); | ||
expect(constructButton).toBeDisabled(); | ||
}); | ||
|
||
test('Upgrade button should be disabled with insufficient resources', () => { | ||
const queryClient = new QueryClient(); | ||
const buildingFields: BuildingField[] = [level10MainBuildingBuildingField, level1CrannyBuildingField]; | ||
|
||
const villageMockWithLevel10MainBuilding: Village = { | ||
...villageMock, | ||
buildingFields, | ||
resources: noResources, | ||
}; | ||
|
||
queryClient.setQueryData<Village[]>([villagesCacheKey], [villageMockWithLevel10MainBuilding]); | ||
|
||
renderWithGameContext(<BuildingActions buildingId="CRANNY" />, { queryClient, path: `${serverPathMock}/v-1/village/37` }); | ||
const upgradeButton = screen.getByTestId('building-actions-upgrade-building-button'); | ||
|
||
expect(upgradeButton).toBeInTheDocument(); | ||
expect(upgradeButton).toBeDisabled(); | ||
}); |
Oops, something went wrong.