@@ -4,6 +4,7 @@ import {OrganizationFixture} from 'sentry-fixture/organization';
44import { ProjectFixture } from 'sentry-fixture/project' ;
55import { ReleaseFixture } from 'sentry-fixture/release' ;
66import { RouteComponentPropsFixture } from 'sentry-fixture/routeComponentPropsFixture' ;
7+ import { TeamFixture } from 'sentry-fixture/team' ;
78import { UserFixture } from 'sentry-fixture/user' ;
89import { WidgetFixture } from 'sentry-fixture/widget' ;
910
@@ -21,6 +22,7 @@ import * as modals from 'sentry/actionCreators/modal';
2122import ConfigStore from 'sentry/stores/configStore' ;
2223import PageFiltersStore from 'sentry/stores/pageFiltersStore' ;
2324import ProjectsStore from 'sentry/stores/projectsStore' ;
25+ import TeamStore from 'sentry/stores/teamStore' ;
2426import { browserHistory } from 'sentry/utils/browserHistory' ;
2527import CreateDashboard from 'sentry/views/dashboards/create' ;
2628import { handleUpdateDashboardSplit } from 'sentry/views/dashboards/detail' ;
@@ -1667,7 +1669,7 @@ describe('Dashboards > Detail', function () {
16671669
16681670 await userEvent . click ( await screen . findByText ( 'Edit Access:' ) ) ;
16691671 expect ( screen . getByText ( 'Creator' ) ) . toBeInTheDocument ( ) ;
1670- expect ( screen . getByText ( 'Everyone ' ) ) . toBeInTheDocument ( ) ;
1672+ expect ( screen . getByText ( 'All users ' ) ) . toBeInTheDocument ( ) ;
16711673 } ) ;
16721674
16731675 it ( 'creates and updates new permissions for dashboard with no edit perms initialized' , async function ( ) {
@@ -1699,28 +1701,27 @@ describe('Dashboards > Detail', function () {
16991701 ) ;
17001702 await userEvent . click ( await screen . findByText ( 'Edit Access:' ) ) ;
17011703
1702- // deselects 'Everyone ' so only creator has edit access
1703- expect ( await screen . findByText ( 'Everyone ' ) ) . toBeEnabled ( ) ;
1704- expect ( await screen . findByRole ( 'option' , { name : 'Everyone ' } ) ) . toHaveAttribute (
1704+ // deselects 'All users ' so only creator has edit access
1705+ expect ( await screen . findByText ( 'All users ' ) ) . toBeEnabled ( ) ;
1706+ expect ( await screen . findByRole ( 'option' , { name : 'All users ' } ) ) . toHaveAttribute (
17051707 'aria-selected' ,
17061708 'true'
17071709 ) ;
1708- await userEvent . click ( screen . getByRole ( 'option' , { name : 'Everyone ' } ) ) ;
1709- expect ( await screen . findByRole ( 'option' , { name : 'Everyone ' } ) ) . toHaveAttribute (
1710+ await userEvent . click ( screen . getByRole ( 'option' , { name : 'All users ' } ) ) ;
1711+ expect ( await screen . findByRole ( 'option' , { name : 'All users ' } ) ) . toHaveAttribute (
17101712 'aria-selected' ,
17111713 'false'
17121714 ) ;
17131715
1714- // clicks out of dropdown to trigger onClose()
1715- await userEvent . click ( await screen . findByText ( 'Edit Access:' ) ) ;
1716+ await userEvent . click ( await screen . findByText ( 'Save Changes' ) ) ;
17161717
17171718 await waitFor ( ( ) => {
17181719 expect ( mockPUT ) . toHaveBeenCalledTimes ( 1 ) ;
17191720 expect ( mockPUT ) . toHaveBeenCalledWith (
17201721 '/organizations/org-slug/dashboards/1/' ,
17211722 expect . objectContaining ( {
17221723 data : expect . objectContaining ( {
1723- permissions : { isCreatorOnlyEditable : true } ,
1724+ permissions : { isEditableByEveryone : false , teamsWithEditAccess : [ ] } ,
17241725 } ) ,
17251726 } )
17261727 ) ;
@@ -1739,7 +1740,7 @@ describe('Dashboards > Detail', function () {
17391740 id : '1' ,
17401741 title : 'Custom Errors' ,
17411742 createdBy : UserFixture ( { id : '781629' } ) ,
1742- permissions : { isCreatorOnlyEditable : true } ,
1743+ permissions : { isEditableByEveryone : false } ,
17431744 } ) ,
17441745 } ) ;
17451746
@@ -1768,28 +1769,111 @@ describe('Dashboards > Detail', function () {
17681769 ) ;
17691770 await userEvent . click ( await screen . findByText ( 'Edit Access:' ) ) ;
17701771
1771- // selects 'Everyone ' so everyone has edit access
1772- expect ( await screen . findByText ( 'Everyone ' ) ) . toBeEnabled ( ) ;
1773- expect ( await screen . findByRole ( 'option' , { name : 'Everyone ' } ) ) . toHaveAttribute (
1772+ // selects 'All users ' so everyone has edit access
1773+ expect ( await screen . findByText ( 'All users ' ) ) . toBeEnabled ( ) ;
1774+ expect ( await screen . findByRole ( 'option' , { name : 'All users ' } ) ) . toHaveAttribute (
17741775 'aria-selected' ,
17751776 'false'
17761777 ) ;
1777- await userEvent . click ( screen . getByRole ( 'option' , { name : 'Everyone ' } ) ) ;
1778- expect ( await screen . findByRole ( 'option' , { name : 'Everyone ' } ) ) . toHaveAttribute (
1778+ await userEvent . click ( screen . getByRole ( 'option' , { name : 'All users ' } ) ) ;
1779+ expect ( await screen . findByRole ( 'option' , { name : 'All users ' } ) ) . toHaveAttribute (
17791780 'aria-selected' ,
17801781 'true'
17811782 ) ;
17821783
1783- // clicks out of dropdown to trigger onClose()
1784+ await userEvent . click ( await screen . findByText ( 'Save Changes' ) ) ;
1785+
1786+ await waitFor ( ( ) => {
1787+ expect ( mockPUT ) . toHaveBeenCalledTimes ( 1 ) ;
1788+ expect ( mockPUT ) . toHaveBeenCalledWith (
1789+ '/organizations/org-slug/dashboards/1/' ,
1790+ expect . objectContaining ( {
1791+ data : expect . objectContaining ( {
1792+ permissions : { isEditableByEveryone : true , teamsWithEditAccess : [ ] } ,
1793+ } ) ,
1794+ } )
1795+ ) ;
1796+ } ) ;
1797+ } ) ;
1798+
1799+ it ( 'creator can update permissions with teams for dashboard' , async function ( ) {
1800+ const mockPUT = MockApiClient . addMockResponse ( {
1801+ url : '/organizations/org-slug/dashboards/1/' ,
1802+ method : 'PUT' ,
1803+ body : DashboardFixture ( [ ] , { id : '1' , title : 'Custom Errors' } ) ,
1804+ } ) ;
1805+ MockApiClient . addMockResponse ( {
1806+ url : '/organizations/org-slug/dashboards/1/' ,
1807+ body : DashboardFixture ( [ ] , {
1808+ id : '1' ,
1809+ title : 'Custom Errors' ,
1810+ createdBy : UserFixture ( { id : '781629' } ) ,
1811+ permissions : { isEditableByEveryone : false } ,
1812+ } ) ,
1813+ } ) ;
1814+
1815+ const currentUser = UserFixture ( { id : '781629' } ) ;
1816+ ConfigStore . set ( 'user' , currentUser ) ;
1817+
1818+ const teamData = [
1819+ {
1820+ id : '1' ,
1821+ slug : 'team1' ,
1822+ name : 'Team 1' ,
1823+ } ,
1824+ {
1825+ id : '2' ,
1826+ slug : 'team2' ,
1827+ name : 'Team 2' ,
1828+ } ,
1829+ {
1830+ id : '3' ,
1831+ slug : 'team3' ,
1832+ name : 'Team 3' ,
1833+ } ,
1834+ ] ;
1835+ const teams = teamData . map ( data => TeamFixture ( data ) ) ;
1836+
1837+ TeamStore . loadInitialData ( teams ) ;
1838+
1839+ render (
1840+ < ViewEditDashboard
1841+ { ...RouteComponentPropsFixture ( ) }
1842+ organization = { {
1843+ ...initialData . organization ,
1844+ features : [ 'dashboards-edit-access' , ...initialData . organization . features ] ,
1845+ } }
1846+ params = { { orgId : 'org-slug' , dashboardId : '1' } }
1847+ router = { initialData . router }
1848+ location = { initialData . router . location }
1849+ >
1850+ { null }
1851+ </ ViewEditDashboard > ,
1852+ {
1853+ router : initialData . router ,
1854+ organization : {
1855+ features : [ 'dashboards-edit-access' , ...initialData . organization . features ] ,
1856+ } ,
1857+ }
1858+ ) ;
17841859 await userEvent . click ( await screen . findByText ( 'Edit Access:' ) ) ;
17851860
1861+ expect ( await screen . findByText ( 'All users' ) ) . toBeEnabled ( ) ;
1862+ expect ( await screen . findByRole ( 'option' , { name : 'All users' } ) ) . toHaveAttribute (
1863+ 'aria-selected' ,
1864+ 'false'
1865+ ) ;
1866+ await userEvent . click ( screen . getByRole ( 'option' , { name : '#team1' } ) ) ;
1867+ await userEvent . click ( screen . getByRole ( 'option' , { name : '#team2' } ) ) ;
1868+ await userEvent . click ( await screen . findByText ( 'Save Changes' ) ) ;
1869+
17861870 await waitFor ( ( ) => {
17871871 expect ( mockPUT ) . toHaveBeenCalledTimes ( 1 ) ;
17881872 expect ( mockPUT ) . toHaveBeenCalledWith (
17891873 '/organizations/org-slug/dashboards/1/' ,
17901874 expect . objectContaining ( {
17911875 data : expect . objectContaining ( {
1792- permissions : { isCreatorOnlyEditable : false } ,
1876+ permissions : { isEditableByEveryone : false , teamsWithEditAccess : [ 1 , 2 ] } ,
17931877 } ) ,
17941878 } )
17951879 ) ;
@@ -1804,7 +1888,7 @@ describe('Dashboards > Detail', function () {
18041888 id : '1' ,
18051889 title : 'Custom Errors' ,
18061890 createdBy : UserFixture ( { id : '238900' } ) ,
1807- permissions : { isCreatorOnlyEditable : true } ,
1891+ permissions : { isEditableByEveryone : false } ,
18081892 } ) ,
18091893 ] ,
18101894 } ) ;
@@ -1814,7 +1898,7 @@ describe('Dashboards > Detail', function () {
18141898 id : '1' ,
18151899 title : 'Custom Errors' ,
18161900 createdBy : UserFixture ( { id : '238900' } ) ,
1817- permissions : { isCreatorOnlyEditable : true } ,
1901+ permissions : { isEditableByEveryone : false } ,
18181902 } ) ,
18191903 } ) ;
18201904
0 commit comments