@@ -3,41 +3,64 @@ import {getRegisteredTutorials, getDidactCategories, getTutorialsForCategory, ge
33import { before } from 'mocha' ;
44import * as vscode from 'vscode' ;
55import { ADD_TUTORIAL_TO_REGISTRY , getContext , REGISTER_TUTORIAL } from '../../extensionFunctions' ;
6- import { DEFAULT_TUTORIAL_CATEGORY , DEFAULT_TUTORIAL_NAME } from '../../extension' ;
6+ import { DEFAULT_TUTORIAL_CATEGORY , DEFAULT_TUTORIAL_NAME , didactTreeView , didactTutorialsProvider } from '../../extension' ;
7+ import { waitUntil } from 'async-wait-until' ;
78
89const name = 'new-tutorial' ;
910const category = 'some-category' ;
1011const source = 'my-uri' ;
1112const name2 = 'new-tutorial-2' ;
1213const category2 = 'some-category-2' ;
1314const source2 = 'my-uri-2' ;
15+ const name3 = 'new-tutorial-3' ;
16+ const category3 = 'some-category-3' ;
17+ const source3 = 'my-uri-3' ;
1418
1519suite ( 'Didact registry test suite' , ( ) => {
1620
17- before ( 'set up the registry tests' , async ( ) => {
21+ before ( 'Clear the registry tests' , async ( ) => {
1822 await clearRegisteredTutorials ( false ) ;
1923 } ) ;
2024
2125 test ( 'assert that clearing the registry made it empty' , async ( ) => {
2226 const registry = getRegisteredTutorials ( ) ;
23- assert . strictEqual ( registry , undefined ) ;
27+ assert . strictEqual ( registry , undefined , `Registry was expected undefined but got ${ registry } ` ) ;
2428
2529 // clean up and add one demo tutorial back in
2630 const tutorialUri = vscode . Uri . file ( getContext ( ) . asAbsolutePath ( './demos/markdown/didact-demo.didact.md' ) ) ;
27- await registerTutorialWithCategory ( DEFAULT_TUTORIAL_NAME , tutorialUri . fsPath , DEFAULT_TUTORIAL_CATEGORY ) ;
31+ await registerTutorialWithCategory ( DEFAULT_TUTORIAL_NAME , tutorialUri . fsPath , DEFAULT_TUTORIAL_CATEGORY , true ) ;
2832
2933 const addRegistry = getRegisteredTutorials ( ) ;
30- assert . notStrictEqual ( addRegistry , undefined ) ;
34+ assert . notStrictEqual ( addRegistry , undefined , `Registry was expected not to be undefined` ) ;
3135 } ) ;
3236
37+ test ( 'Add to registry without setting focus' , async ( ) => {
38+ await clearRegisteredTutorials ( false ) ;
39+ const selectedTutorialsBeforeTest = didactTreeView . selection ;
40+ assert . strictEqual ( selectedTutorialsBeforeTest . length , 0 , `There are unexpected selected Tutorials before test: ${ selectedTutorialsBeforeTest } ` ) ;
41+
42+ try {
43+ await registerTutorialWithArgs ( name3 , source3 , category3 ) ;
44+ } catch ( error ) {
45+ assert . fail ( 'We failed to create the new didact registry entry' ) ;
46+ }
47+
48+ const selectedTutorials = didactTreeView . selection ;
49+ assert . strictEqual ( selectedTutorials . length , 0 , `There are unexpected selected Tutorials: ${ selectedTutorials } ` ) ;
50+ } ) ;
51+
3352 test ( 'add to registry' , async ( ) => {
3453 try {
35- await registerTutorialWithArgs ( name , source , category ) . then ( ( ) => {
54+ await registerTutorialWithArgs ( name , source , category , true ) . then ( ( ) => {
3655 assert . ok ( 'No errors thrown while creating new didact registry entry' ) ;
3756 } ) ;
3857 } catch ( error ) {
3958 assert . fail ( 'We failed to create the new didact registry entry' ) ;
4059 }
60+
61+ const selectedTutorials = didactTreeView . selection ;
62+ assert . strictEqual ( selectedTutorials . length , 1 , `There are unexpected selected Tutorials: ${ selectedTutorials } ` ) ;
63+ assert . strictEqual ( selectedTutorials [ 0 ] . label , name ) ;
4164
4265 try {
4366 await registerTutorialWithCategory ( name , source , category ) ;
0 commit comments