@@ -14,6 +14,14 @@ describe('Dashboards > Dashboard', () => {
1414 const organization = TestStubs . Organization ( {
1515 features : [ 'dashboards-basic' , 'dashboards-edit' , 'dashboard-grid-layout' ] ,
1616 } ) ;
17+ const organizationWithFlag = TestStubs . Organization ( {
18+ features : [
19+ 'dashboards-basic' ,
20+ 'dashboards-edit' ,
21+ 'dashboard-grid-layout' ,
22+ 'issues-in-dashboards' ,
23+ ] ,
24+ } ) ;
1725 const mockDashboard = {
1826 dateCreated : '2021-08-10T21:20:46.798237Z' ,
1927 id : '1' ,
@@ -101,6 +109,11 @@ describe('Dashboards > Dashboard', () => {
101109 } ,
102110 ] ,
103111 } ) ;
112+ MockApiClient . addMockResponse ( {
113+ url : '/organizations/org-slug/tags/' ,
114+ method : 'GET' ,
115+ body : TestStubs . Tags ( ) ,
116+ } ) ;
104117 } ) ;
105118
106119 it ( 'dashboard adds new widget if component is mounted with newWidget prop' , async ( ) => {
@@ -186,14 +199,6 @@ describe('Dashboards > Dashboard', () => {
186199 } ) ;
187200
188201 it ( 'dashboard displays issue widgets if the user has issue widgets feature flag' , async ( ) => {
189- const organizationWithFlag = TestStubs . Organization ( {
190- features : [
191- 'dashboards-basic' ,
192- 'dashboards-edit' ,
193- 'dashboard-grid-layout' ,
194- 'issues-in-dashboards' ,
195- ] ,
196- } ) ;
197202 const mockDashboardWithIssueWidget = {
198203 ...mockDashboard ,
199204 widgets : [ newWidget , issueWidget ] ,
@@ -204,14 +209,6 @@ describe('Dashboards > Dashboard', () => {
204209 } ) ;
205210
206211 it ( 'renders suggested assignees' , async ( ) => {
207- const organizationWithFlag = TestStubs . Organization ( {
208- features : [
209- 'dashboards-basic' ,
210- 'dashboards-edit' ,
211- 'dashboard-grid-layout' ,
212- 'issues-in-dashboards' ,
213- ] ,
214- } ) ;
215212 const mockDashboardWithIssueWidget = {
216213 ...mockDashboard ,
217214 widgets : [ { ...issueWidget } ] ,
@@ -225,4 +222,47 @@ describe('Dashboards > Dashboard', () => {
225222 expect ( await screen . findByText ( 'Matching Issue Owners Rule' ) ) . toBeInTheDocument ( ) ;
226223 } ) ;
227224 } ) ;
225+
226+ describe ( 'Edit mode' , ( ) => {
227+ let widgets : Widget [ ] ;
228+ const mount = dashboard => {
229+ const getDashboardComponent = ( ) => (
230+ < Dashboard
231+ paramDashboardId = "1"
232+ dashboard = { dashboard }
233+ organization = { initialData . organization }
234+ isEditing
235+ onUpdate = { newWidgets => {
236+ widgets . splice ( 0 , widgets . length , ...newWidgets ) ;
237+ } }
238+ handleUpdateWidgetList = { ( ) => undefined }
239+ handleAddCustomWidget = { ( ) => undefined }
240+ onSetWidgetToBeUpdated = { ( ) => undefined }
241+ router = { initialData . router }
242+ location = { initialData . location }
243+ widgetLimitReached = { false }
244+ />
245+ ) ;
246+ const { rerender} = rtlMountWithTheme ( getDashboardComponent ( ) ) ;
247+ return { rerender : ( ) => rerender ( getDashboardComponent ( ) ) } ;
248+ } ;
249+
250+ beforeEach ( ( ) => {
251+ widgets = [ newWidget ] ;
252+ } ) ;
253+
254+ it ( 'displays the copy widget button in edit mode' , ( ) => {
255+ const dashboardWithOneWidget = { ...mockDashboard , widgets} ;
256+ mount ( dashboardWithOneWidget ) ;
257+ expect ( screen . getByLabelText ( 'Duplicate Widget' ) ) . toBeInTheDocument ( ) ;
258+ } ) ;
259+
260+ it ( 'duplicates the widget' , async ( ) => {
261+ const dashboardWithOneWidget = { ...mockDashboard , widgets} ;
262+ const { rerender} = mount ( dashboardWithOneWidget ) ;
263+ userEvent . click ( screen . getByLabelText ( 'Duplicate Widget' ) ) ;
264+ rerender ( ) ;
265+ expect ( screen . getAllByText ( 'Test Discover Widget' ) ) . toHaveLength ( 2 ) ;
266+ } ) ;
267+ } ) ;
228268} ) ;
0 commit comments