-
Notifications
You must be signed in to change notification settings - Fork 237
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Fix team exim * opttarget test * format * remove console.log
- Loading branch information
Showing
3 changed files
with
97 additions
and
16 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
77 changes: 77 additions & 0 deletions
77
libs/gi/db/src/Database/DataManagers/TeamDataManager.test.ts
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,77 @@ | ||
import { DBLocalStorage } from '@genshin-optimizer/common/database' | ||
import { ArtCharDatabase } from '../ArtCharDatabase' | ||
import { initCharTC } from './BuildTcDataManager' | ||
import type { LoadoutDatum } from './TeamDataManager' | ||
|
||
describe('export and import test', () => { | ||
const dbStorage = new DBLocalStorage(localStorage) | ||
const dbIndex = 1 | ||
let database = new ArtCharDatabase(dbIndex, dbStorage) | ||
|
||
beforeEach(() => { | ||
dbStorage.clear() | ||
database = new ArtCharDatabase(dbIndex, dbStorage) | ||
}) | ||
test('exim', () => { | ||
// Create a team [Raiden, null, bennett, null] | ||
|
||
const raidenId = database.teamChars.new('RaidenShogun', { | ||
buildIds: [database.builds.new()], | ||
buildTcIds: [database.buildTcs.new(initCharTC('EngulfingLightning'))], | ||
optConfigId: database.optConfigs.new({ | ||
optimizationTarget: ['test'], | ||
}), | ||
}) | ||
expect(database.teamChars.get(raidenId)?.buildIds.length).toEqual(1) | ||
expect(database.teamChars.get(raidenId)?.buildTcIds.length).toEqual(1) | ||
const bennettId = database.teamChars.new('Bennett', { | ||
buildIds: [database.builds.new()], | ||
buildTcIds: [database.buildTcs.new(initCharTC('SapwoodBlade'))], | ||
}) | ||
const teamId = database.teams.new({ | ||
loadoutData: [ | ||
{ teamCharId: raidenId } as LoadoutDatum, | ||
undefined, | ||
{ teamCharId: bennettId } as LoadoutDatum, | ||
], | ||
}) | ||
|
||
const dbTeam = database.teams.get(teamId)! | ||
expect(dbTeam).toBeTruthy() | ||
expect(dbTeam.loadoutData[0]?.teamCharId).toEqual(raidenId) | ||
expect(dbTeam.loadoutData[2]?.teamCharId).toEqual(bennettId) | ||
|
||
const exp = database.teams.export(teamId) | ||
expect(exp).toBeTruthy() | ||
expect((exp as any).loadoutData[0].key).toEqual('RaidenShogun') | ||
expect((exp as any).loadoutData[0].optConfig.optimizationTarget).toEqual([ | ||
'test', | ||
]) | ||
|
||
let res: object | undefined = undefined | ||
expect(() => { | ||
const json = JSON.stringify(exp) | ||
res = JSON.parse(json) | ||
}).not.toThrow() | ||
expect(res).toBeTruthy() | ||
const importTeamId = database.teams.import(exp) | ||
const importTeam = database.teams.get(importTeamId)! | ||
expect(importTeam).toBeTruthy() | ||
|
||
const raidenTeamChar = database.teamChars.get( | ||
importTeam.loadoutData[0]?.teamCharId | ||
) | ||
expect(raidenTeamChar?.key).toEqual('RaidenShogun') | ||
expect(raidenTeamChar?.buildIds.length).toEqual(0) | ||
expect(raidenTeamChar?.buildTcIds.length).toEqual(1) | ||
expect( | ||
database.optConfigs.get(raidenTeamChar?.optConfigId)?.optimizationTarget | ||
).toEqual(['test']) | ||
const bennettTeamChar = database.teamChars.get( | ||
importTeam.loadoutData[2]?.teamCharId | ||
) | ||
expect(bennettTeamChar?.key).toEqual('Bennett') | ||
expect(bennettTeamChar?.buildIds.length).toEqual(0) | ||
expect(bennettTeamChar?.buildTcIds.length).toEqual(1) | ||
}) | ||
}) |
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