import withTestAnkiCollection from "./__fixtures__/withTestAnkiCollection" ; import { AnkiCollectionDBHandle , Collection , readCollection } from "./ankiPkg" ; import { getModelMapping } from "./modelMapping" ; let collection ; beforeAll ( async ( ) => { await withTestAnkiCollection ( async ( handle ) => { collection = await readCollection ( handle ) ; } ) ; } ) ; function getModelByName ( modelName ) { return Number . parseInt ( Object . keys ( collection . models ) . find ( ( modelID ) => collection . models [ modelID ] . name === modelName ) ! ) ; } test ( "basic model maps" , ( ) => { expect ( getModelMapping ( collection , getModelByName ( "Basic" ) ) ) . toMatchInlineSnapshot ( `
    Object {
      "answerFieldIndex": 1,
      "questionFieldIndex": 0,
      "type": "basic",
    }
  ` ) ; expect ( getModelMapping ( collection , getModelByName ( "Basic (type in the answer)" ) ) ) . toMatchInlineSnapshot ( `
    Object {
      "answerFieldIndex": 1,
      "questionFieldIndex": 0,
      "type": "basic",
    }
  ` ) ; } ) ; test ( "cloze model maps" , ( ) => { expect ( getModelMapping ( collection , getModelByName ( "Cloze" ) ) ) . toMatchInlineSnapshot ( `
    Object {
      "contentsFieldIndex": 0,
      "type": "cloze",
    }
  ` ) ; } ) ; test ( "basic with reverse doesn't map" , ( ) => { expect ( getModelMapping ( collection , getModelByName ( "Basic (and reversed card)" ) ) ) . toBe ( "unknown" ) ; } ) ; test ( "missing model doesn't map" , ( ) => { expect ( getModelMapping ( collection , 2295802 ) ) . toBe ( "missing" ) ; } ) ; test ( "fancy IR3 model doesn't map" , ( ) => { expect ( getModelMapping ( collection , getModelByName ( "IR3" ) ) ) . toBe ( "unknown" ) ; } ) ;