-
Notifications
You must be signed in to change notification settings - Fork 179
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
278 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
packages/e2e-tests/src/specs/dashboard/settings/adminUser/dataRemovalSettings.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/* | ||
* Copyright 2022 Google LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
/** | ||
* External dependencies | ||
*/ | ||
import { | ||
disableCheckbox, | ||
enableCheckbox, | ||
visitSettings, | ||
} from '@web-stories-wp/e2e-test-utils'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import { dataRemovalCheckboxSelector } from '../../../../utils'; | ||
|
||
describe('Admin User', () => { | ||
beforeEach(async () => { | ||
await visitSettings(); | ||
await enableCheckbox(dataRemovalCheckboxSelector); | ||
}); | ||
|
||
it('should let me see and update data removal settings', async () => { | ||
// verify that the data removal checkbox can be changed | ||
await expect(page).toMatchElement(`${dataRemovalCheckboxSelector}:checked`); | ||
|
||
await disableCheckbox(dataRemovalCheckboxSelector); | ||
|
||
// verify that the data removal checkbox can be changed | ||
await expect(page).toMatchElement(`${dataRemovalCheckboxSelector}:checked`); | ||
await disableCheckbox(dataRemovalCheckboxSelector); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
packages/wp-dashboard/src/components/editorSettings/dataRemoval/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
/* | ||
* Copyright 2022 Google LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
/** | ||
* External dependencies | ||
*/ | ||
import PropTypes from 'prop-types'; | ||
import { useCallback } from '@googleforcreators/react'; | ||
import { __ } from '@googleforcreators/i18n'; | ||
import { Checkbox, THEME_CONSTANTS } from '@googleforcreators/design-system'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import { | ||
SettingForm, | ||
SettingHeading, | ||
CheckboxLabel, | ||
CheckboxLabelText, | ||
} from '../components'; | ||
|
||
export default function DataRemovalSettings({ | ||
isEnabled = false, | ||
updateSettings, | ||
}) { | ||
const onChange = useCallback( | ||
() => updateSettings({ dataRemoval: !isEnabled }), | ||
[updateSettings, isEnabled] | ||
); | ||
|
||
return ( | ||
<SettingForm> | ||
<div> | ||
<SettingHeading>{__('Data removal', 'web-stories')}</SettingHeading> | ||
</div> | ||
<div> | ||
<CheckboxLabel forwardedAs="label" htmlFor="data-removal-settings"> | ||
<Checkbox | ||
id="data-removal-settings" | ||
data-testid="data-removal-settings-checkbox" | ||
onChange={onChange} | ||
checked={Boolean(isEnabled)} | ||
/> | ||
<CheckboxLabelText | ||
size={THEME_CONSTANTS.TYPOGRAPHY.PRESET_SIZES.SMALL} | ||
aria-checked={Boolean(isEnabled)} | ||
forwardedAs="span" | ||
> | ||
{__( | ||
'Remove data when uninstalling the Web Story plugin.', | ||
'web-stories' | ||
)} | ||
</CheckboxLabelText> | ||
</CheckboxLabel> | ||
</div> | ||
</SettingForm> | ||
); | ||
} | ||
|
||
DataRemovalSettings.propTypes = { | ||
isEnabled: PropTypes.bool, | ||
updateSettings: PropTypes.func.isRequired, | ||
}; |
35 changes: 35 additions & 0 deletions
35
packages/wp-dashboard/src/components/editorSettings/dataRemoval/stories/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* | ||
* Copyright 2021 Google LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import DataRemovalSettings from '..'; | ||
|
||
export default { | ||
title: 'Dashboard/Views/EditorSettings/DataRemovalSettings', | ||
component: DataRemovalSettings, | ||
args: { | ||
isEnabled: true, | ||
}, | ||
argTypes: { | ||
updateSettings: { action: 'updateSettings fired' }, | ||
}, | ||
}; | ||
|
||
export const _default = (args) => { | ||
return <DataRemovalSettings {...args} />; | ||
}; |
53 changes: 53 additions & 0 deletions
53
packages/wp-dashboard/src/components/editorSettings/dataRemoval/test/DataRemovalSettings.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/* | ||
* Copyright 2021 Google LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
/** | ||
* External dependencies | ||
*/ | ||
import { fireEvent, screen } from '@testing-library/react'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import DataRemovalSettings from '..'; | ||
import { renderWithProviders } from '../../../../testUtils'; | ||
|
||
describe('Editor Settings: <DataRemovalSettings />', function () { | ||
it('should render the data removal setting as checked when isEnabled', function () { | ||
renderWithProviders( | ||
<DataRemovalSettings updateSettings={jest.fn()} isEnabled /> | ||
); | ||
|
||
expect(screen.getByRole('checkbox')).toBeChecked(); | ||
}); | ||
|
||
it('should not render the data removal setting as checked when not isEnabled', function () { | ||
renderWithProviders(<DataRemovalSettings updateSettings={jest.fn()} />); | ||
|
||
expect(screen.getByRole('checkbox')).not.toBeChecked(); | ||
}); | ||
|
||
it('should update settings when the checkbox is clicked.', function () { | ||
const onChange = jest.fn(); | ||
renderWithProviders(<DataRemovalSettings updateSettings={onChange} />); | ||
|
||
const checkbox = screen.getByRole('checkbox'); | ||
fireEvent.click(checkbox); | ||
|
||
expect(onChange).toHaveBeenCalledTimes(1); | ||
expect(onChange).toHaveBeenCalledWith({ dataRemoval: true }); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.