@@ -30,6 +30,7 @@ import SplitPane from "react-split-pane";
30
30
import EditorSideBar from "./editorSideBar" ;
31
31
import Alert from "../../common/alert/alert" ;
32
32
import registerMixins from "../../../../registerMixins" ;
33
+ import { TagInput } from "../../common/tagInput/tagInput" ;
33
34
34
35
function createComponent ( store , props : IEditorPageProps ) : ReactWrapper < IEditorPageProps , IEditorPageState , EditorPage > {
35
36
return mount (
@@ -162,7 +163,7 @@ describe("Editor Page Component", () => {
162
163
} ) ;
163
164
} ) ;
164
165
165
- it ( "Raises onAssetSelected handler when an asset is selected from the sidebar " , async ( ) => {
166
+ it ( "Default asset is loaded and saved during initial page rendering " , async ( ) => {
166
167
// create test project and asset
167
168
const testProject = MockFactory . createTestProject ( "TestProject" ) ;
168
169
const defaultAsset = testAssets [ 0 ] ;
@@ -180,6 +181,7 @@ describe("Editor Page Component", () => {
180
181
const editorPage = wrapper . find ( EditorPage ) . childAt ( 0 ) as ReactWrapper < IEditorPageProps , IEditorPageState > ;
181
182
182
183
await MockFactory . flushUi ( ) ;
184
+ wrapper . update ( ) ;
183
185
184
186
const expectedAsset = editorPage . state ( ) . assets [ 0 ] ;
185
187
const partialProject = {
@@ -669,26 +671,31 @@ describe("Editor Page Component", () => {
669
671
} ) ;
670
672
671
673
const wrapper = createComponent ( store , MockFactory . editorPageProps ( ) ) ;
672
- expect ( wrapper . props ( ) . project . tags ) . toEqual ( project . tags ) ;
674
+ expect ( wrapper . find ( TagInput ) . props ( ) . tags ) . toEqual ( project . tags ) ;
673
675
} ) ;
674
676
675
- it ( "create a new tag from text box" , ( ) => {
677
+ it ( "create a new tag updates project tags" , async ( ) => {
676
678
const project = MockFactory . createTestProject ( ) ;
677
679
const store = createReduxStore ( {
678
680
...MockFactory . initialState ( ) ,
679
681
currentProject : project ,
680
682
} ) ;
683
+
681
684
const wrapper = createComponent ( store , MockFactory . editorPageProps ( ) ) ;
682
- expect ( wrapper . props ( ) . project . tags ) . toEqual ( project . tags ) ;
685
+ await waitForSelectedAsset ( wrapper ) ;
683
686
684
- const newTagName = "My new tag" ;
685
- wrapper . find ( "div.tag-input-toolbar-item.plus" ) . simulate ( "click" ) ;
686
- wrapper . find ( ".tag-input-box" ) . simulate ( "keydown" , { key : "Enter" , target : { value : newTagName } } ) ;
687
+ const newTag = MockFactory . createTestTag ( "NewTag" ) ;
688
+ const updatedTags = [ ...project . tags , newTag ] ;
689
+ wrapper . find ( TagInput ) . props ( ) . onChange ( updatedTags ) ;
690
+
691
+ await MockFactory . flushUi ( ) ;
692
+ wrapper . update ( ) ;
687
693
688
- const projectTags = wrapper . props ( ) . project . tags ;
694
+ const editorPage = wrapper . find ( EditorPage ) . childAt ( 0 ) as ReactWrapper < IEditorPageProps > ;
695
+ const projectTags = editorPage . props ( ) . project . tags ;
689
696
690
- expect ( projectTags ) . toHaveLength ( project . tags . length + 1 ) ;
691
- expect ( projectTags [ projectTags . length - 1 ] . name ) . toEqual ( newTagName ) ;
697
+ expect ( projectTags ) . toHaveLength ( updatedTags . length ) ;
698
+ expect ( projectTags [ projectTags . length - 1 ] . name ) . toEqual ( newTag . name ) ;
692
699
} ) ;
693
700
694
701
it ( "Remove a tag" , async ( ) => {
@@ -701,14 +708,19 @@ describe("Editor Page Component", () => {
701
708
const wrapper = createComponent ( store , MockFactory . editorPageProps ( ) ) ;
702
709
await waitForSelectedAsset ( wrapper ) ;
703
710
704
- expect ( wrapper . props ( ) . project . tags ) . toEqual ( project . tags ) ;
705
- wrapper . find ( ".tag-content" ) . last ( ) . simulate ( "click" ) ;
706
- wrapper . find ( "i.tag-input-toolbar-icon.fas.fa-trash" ) . simulate ( "click" ) ;
707
- wrapper . find ( "button.btn.btn-danger" ) . simulate ( "click" ) ;
711
+ const tagToDelete = project . tags [ project . tags . length - 1 ] ;
712
+ wrapper . find ( TagInput ) . props ( ) . onTagDeleted ( tagToDelete . name ) ;
713
+
714
+ // Accept the modal delete warning
715
+ wrapper . update ( ) ;
716
+ wrapper . find ( ".modal-footer button" ) . first ( ) . simulate ( "click" ) ;
708
717
709
718
await MockFactory . flushUi ( ) ;
719
+ wrapper . update ( ) ;
720
+
721
+ const editorPage = wrapper . find ( EditorPage ) . childAt ( 0 ) as ReactWrapper < IEditorPageProps > ;
722
+ const projectTags = editorPage . props ( ) . project . tags ;
710
723
711
- const projectTags = wrapper . props ( ) . project . tags ;
712
724
expect ( projectTags ) . toHaveLength ( project . tags . length - 1 ) ;
713
725
} ) ;
714
726
0 commit comments