11classdef (SharedTestFixtures = { % add 'fixtures' folder as test fixture
22 matlab .unittest .fixtures .PathFixture(' fixtures' ),...
3- matlab .unittest .fixtures .PathFixture([' fixtures' filesep ' util ' ])}) ...
4- ExpPanelTest < matlab .mock .TestCase
3+ matlab .unittest .fixtures .PathFixture([' fixtures' filesep ' expDefinitions ' ])}) ...
4+ ExpPanelTest < matlab .unittest .TestCase
55
66 properties (SetAccess = protected )
77 % The figure that contains the ExpPanel
88 Parent
99 % Handle for ExpPanel
1010 Panel eui.ExpPanel
11+ % Remote Rig object
12+ Remote srv.StimulusControl
13+ % A parameters structure
14+ Parameters
15+ % An experiment reference string
16+ Ref
1117 end
12-
18+
19+ properties (MethodSetupParameter )
20+ % Experiment type under test
21+ ExpType = {' Base' , ' Signals' } % TODO Add tests for ChoiceWorld, etc.
22+ end
23+
1324 methods (TestClassSetup )
1425 function setup(testCase )
15- % SETUP TODO Document
26+ % SETUP Set up test case
27+ % The following occurs during setup:
28+ % 1. Creating parent figure, turn off figure visability and delete
29+ % on taredown.
30+ % 2. Set test flag to true to avoid path in test assertion error.
31+ % 3. Applies repos fixture and create a test subject and expRef.
32+ % 4. Instantiates a StimulusControl object for event listeners.
1633
1734 % Hide figures and add teardown function to restore settings
1835 def = get(0 ,' DefaultFigureVisible' );
@@ -21,24 +38,115 @@ function setup(testCase)
2138
2239 % Create figure for panel
2340 testCase.Parent = figure();
41+ testCase .addTeardown(@delete , testCase .Parent )
2442
2543 % Set INTEST flag to true
2644 setTestFlag(true );
2745 testCase .addTeardown(@setTestFlag , false )
46+
47+ % Ensure we're using the correct test paths and add teardowns to
48+ % remove any folders we create
49+ testCase .applyFixture(ReposFixture )
50+
51+ % Now create a single subject folder for testing the log
52+ subject = ' test' ;
53+ mainRepo = dat .reposPath(' main' , ' master' );
54+ assert(mkdir(fullfile(mainRepo , subject )), ...
55+ ' Failed to create subject folder' )
56+ testCase.Ref = dat .constructExpRef(subject , now , 1 );
57+
58+ % Set up a StimulusControl object for simulating rig events
59+ testCase.Remote = srv .StimulusControl .create(' testRig' );
2860 end
2961 end
3062
3163 methods (TestMethodSetup )
32- function setupPanel(testCase )
33- % testCase.ExpPanel = eui.ExpPanel.live();
64+ function setupParams(testCase , ExpType )
65+ % SETUPPARAMS Set up parameters struct
66+ % Create a parameters structure depending of the ExpType.
67+
68+ switch lower(ExpType )
69+ case ' signals'
70+ % A Signals experiment without the custom ExpPanel. Instantiates
71+ % the eui.SignalsExpPanel class
72+ testCase.Parameters = struct(' type' , ' custom' , ' defFunction' , @nop );
73+ case ' choiceworld'
74+ % ChoiceWorld experiment params. Instantiates the
75+ % eui.ChoiceExpPanel class
76+ testCase.Parameters = exp .choiceWorldParams ;
77+ case ' custom'
78+ % Signals experiment params with the expPanelFun parameter.
79+ % Calls the function defined in that parameter
80+ testCase.Parameters = exp .inferParameters(@advancedChoiceWorld );
81+ case ' base'
82+ % Instantiates the eui.ExpPanel base class
83+ testCase.Parameters = struct(...
84+ ' experimentFun' , @(pars , rig ) nop , ...
85+ ' type' , ' unknown' );
86+ case ' barmapping'
87+ % Instantiates the eui.MappingExpPanel class
88+ testCase.Parameters = exp .barMappingParams ;
89+ otherwise
90+ testCase.Parameters = [];
91+ end
92+ end
93+ end
94+
95+ methods (TestMethodTeardown )
96+ function clearFigure(testCase )
97+ % Completely reset the figure on taredown
98+ testCase.Parent = clf(testCase .Parent , ' reset' );
3499 end
35100 end
36101
37102 methods (Test )
38- function test_panel(testCase )
39- % TODO Write tests for ExpPanel
103+ function test_live(testCase )
104+ % Test the live constructor method for various experiment types. The
105+ % following things are tested:
106+ % 1. Default update labels
107+ % 2. ActivateLog parameter functionality
108+ % 3. Comments box context menu functionality
109+ % 4. TODO Test comments changed callback
110+ % 5. TODO Check params button function
111+ inputs = {
112+ testCase .Parent ;
113+ testCase .Ref ;
114+ testCase .Remote ;
115+ testCase .Parameters };
116+ testCase.Panel = eui .ExpPanel .live(inputs{: }, ' ActivateLog' , false );
117+
118+ testCase .fatalAssertTrue(isvalid(testCase .Panel ))
119+ % Test the default labels have been created
120+ % Find all labels
121+ labels = findall(testCase .Parent , ' Style' , ' text' );
122+ expected = {' 0' , ' -:--' , ' Pending' , ' Trial count' , ' Elapsed' , ' Status' };
123+ testCase .verifyEqual({labels .String }, expected , ' Default labels incorrect' )
124+ comments = findall(testCase .Parent , ' Style' , ' edit' );
125+ testCase .assertEmpty(comments , ' Unexpected comments box' );
126+
127+ % Test build with log activated
128+ delete(testCase .Panel ) % Delete previous panel
129+ testCase.Panel = eui .ExpPanel .live(inputs{: }, ' ActivateLog' , true );
130+ % Check Comments label exists
131+ labels = findall(testCase .Parent , ' Style' , ' text' );
132+ commentsLabel = labels(strcmp({labels .String }, ' Comments' ));
133+ testCase .assertNotEmpty(commentsLabel )
134+ % Check comments box exits
135+ comments = findall(testCase .Parent , ' Style' , ' edit' );
136+ testCase .assertNotEmpty(comments , ' Failed to create comments box' );
137+ % Test comments box hiding
138+ testCase .assertTrue(strcmp(comments .Visible , ' on' ))
139+ menuOption = commentsLabel .UIContextMenu .Children(1 );
140+ menuOption .MenuSelectedFcn(menuOption ) % Trigger menu callback
141+ testCase .assertTrue(strcmp(comments .Visible , ' off' ), ' Failed to hide comments' )
142+ menuOption .MenuSelectedFcn(menuOption ) % Trigger menu callback
143+ testCase .assertTrue(strcmp(comments .Visible , ' on' ), ' Failed to show comments' )
40144 end
41145
146+ % function test_starttime(testCase)
147+ % % TODO Test Start time input as input (i.e. for reconnect)
148+ % end
149+
42150 end
43151
44152end
0 commit comments