Skip to content

Commit

Permalink
Merge pull request #52 from ttsukagoshi/main
Browse files Browse the repository at this point in the history
v1.1.0 release
  • Loading branch information
ttsukagoshi authored Jul 12, 2022
2 parents cbfe574 + 6e82eae commit 115809c
Show file tree
Hide file tree
Showing 26 changed files with 6,744 additions and 1,167 deletions.
16 changes: 16 additions & 0 deletions .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: 'coverage'
on:
pull_request:
branches:
- main
- release
jobs:
coverage:
permissions:
checks: write
pull-requests: write
contents: write
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: ArtiomTr/jest-coverage-report-action@v2
2 changes: 1 addition & 1 deletion .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
node-version: '16'

- name: Cache node modules
uses: actions/cache@v3.0.3
uses: actions/cache@v3.0.4
env:
cache-name: cache-node-modules
with:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/linter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ jobs:
# Run Linter against code base #
################################
- name: Lint Code Base
uses: docker://ghcr.io/github/super-linter:slim-v4 # uses: github/super-linter@v4 See https://github.com/github/super-linter#images
uses: github/super-linter/slim@v4 # uses: github/super-linter@v4 See https://github.com/github/super-linter#images
env:
VALIDATE_ALL_CODEBASE: true
LINTER_RULES_PATH: /
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,6 @@ node_modules/

# clasp
.clasp.json

# jest
coverage/
107 changes: 107 additions & 0 deletions __test__/buildConfirmationPage.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
const { buildConfirmationPage } = require('../src/unshare');
const {
EVENT_DRIVE_SELECTED,
EVENT_SHEETS,
EVENT_DRIVE_SELECTED_NOT_OWNER_FILE,
} = require('../src/__mocks__/mockEvents');

const patterns = [
{
testName: 'Check buildConfirmationPage: files selected on Drive',
input: EVENT_DRIVE_SELECTED,
expectedOutput: {
sections: [
{
widgets: [
{
// localizedMessage.replaceConfirmationMessage(targetFilesSummary, ignoredFilesSummary)
// localizedMessage.messageList.userAccessEditor
// localizedMessage.messageList.userAccessViewer
// localizedMessage.messageList.userAccessCommenter
text: 'Are you sure you want to proceed with Unshare? You will be permanently removing all editors and viewers (including commenters) from these file/folder(s):\n<b>mock_sheets_file1</b>\n - sheetsTestEditor1@test.com (editor)\n - sheetsTextEditor2@test.com (editor)\n - sheetsTestViewer1@test.app (viewer/commenter)\n\n<b>mock_docs_file</b>\n - docsTestEditor1@test.com (editor)\n - docsTextEditor2@test.com (editor)\n - docsTestViewer1@test.app (viewer/commenter)\n\n<b>mock_slides_file</b>\n - slidesTestEditor1@test.com (editor)\n - slidesTextEditor2@test.com (editor)\n - slidesTestViewer1@test.app (viewer/commenter)\n\n<b>mock_form_file</b>\n - formTestEditor1@test.com (editor)\n - formTextEditor2@test.com (editor)\n - formTestViewer1@test.app (viewer/commenter)\n\n<b>mock_subfolder</b>\n - folderTestEditor1@test.com (editor)\n - folderTextEditor2@test.com (editor)\n - folderTestViewer1@test.app (viewer/commenter)\n\n<b>THIS ACTION CANNOT BE UNDONE</b>.\n\nNote that the file/folder(s) below will be ignored since you are not the owner:\n * mock_sheets_file2_not_owner',
},
],
},
],
fixedFooter: {
primaryButton: {
text: 'CANCEL', // localizedMessage.messageList.buttonCancel
textButtonStyle: 'FILLED',
onClickAction: { functionName: 'buildDriveHomepage' },
openLink: '',
},
secondaryButton: {
text: 'UNSHARE', // localizedMessage.messageList.buttonExecuteUnshare
textButtonStyle: '',
onClickAction: { functionName: 'unshare' },
openLink: '',
},
},
},
},
{
testName: 'Check buildConfirmationPage: Sheet file with owner privilege',
input: EVENT_SHEETS,
expectedOutput: {
sections: [
{
widgets: [
{
// localizedMessage.replaceConfirmationMessage(targetFilesSummary, ignoredFilesSummary)
// localizedMessage.messageList.userAccessEditor
// localizedMessage.messageList.userAccessViewer
// localizedMessage.messageList.userAccessCommenter
text: 'Are you sure you want to proceed with Unshare? You will be permanently removing all editors and viewers (including commenters) from these file/folder(s):\n<b>mock_sheets_file1</b>\n - sheetsTestEditor1@test.com (editor)\n - sheetsTextEditor2@test.com (editor)\n - sheetsTestViewer1@test.app (viewer/commenter)\n\n<b>THIS ACTION CANNOT BE UNDONE</b>.\n\n',
},
],
},
],
fixedFooter: {
primaryButton: {
text: 'CANCEL', // localizedMessage.messageList.buttonCancel
textButtonStyle: 'FILLED',
onClickAction: { functionName: 'buildHomepage' },
openLink: '',
},
secondaryButton: {
text: 'UNSHARE', // localizedMessage.messageList.buttonExecuteUnshare
textButtonStyle: '',
onClickAction: { functionName: 'unshare' },
openLink: '',
},
},
},
},
{
testName: 'Check buildConfirmationPage: not-owner file selected on Drive',
input: EVENT_DRIVE_SELECTED_NOT_OWNER_FILE,
expectedOutput: {
sections: [
{
widgets: [
{
text: '[ERROR] You must be the owner of the file/folder(s) to execute Unshare:\n * mock_sheets_file2_not_owner',
},
],
},
],
fixedFooter: {
primaryButton: {
text: 'Return Home', // localizedMessage.messageList.buttonReturnHome
textButtonStyle: 'FILLED',
onClickAction: { functionName: 'buildDriveHomepage' },
openLink: '',
},
secondaryButton: {},
},
},
},
];

patterns.forEach((pattern) => {
test(pattern.testName, () => {
expect(buildConfirmationPage(pattern.input)).toEqual(
pattern.expectedOutput
);
});
});
28 changes: 28 additions & 0 deletions __test__/buildDriveHomepage.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
const { buildDriveHomepage } = require('../src/unshare');
const input = {
testName: 'Check buildDriveHomepage in en',
event: {
commonEventObject: {
platform: 'WEB',
hostApp: 'DRIVE',
userLocale: 'en',
},
},
};

const expectedOutput = {
sections: [
{
widgets: [
{
// localizedMessage.messageList.homepageDriveText
text: 'Select file(s) that you want to "un"share. Only the file/folder(s) that you own can be processed.',
},
],
},
],
};

test(input.testName, () => {
expect(buildDriveHomepage(input.event)).toEqual(expectedOutput);
});
57 changes: 57 additions & 0 deletions __test__/buildHomepage.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
const { buildHomepage, buildDriveItemsSelected } = require('../src/unshare');
const inputBuildHomepage = {
testName: 'Check buildHomepage in en',
event: {
commonEventObject: {
platform: 'WEB',
hostApp: 'SHEETS',
userLocale: 'en',
},
},
};
const inputBuildDriveItemsSelected = {
testName: 'Check buildDriveItemsSelected in en',
event: {
commonEventObject: {
platform: 'WEB',
hostApp: 'DRIVE',
userLocale: 'en',
},
},
};

const expectedOutput = {
sections: [
{
widgets: [
{
// localizedMessage.messageList.homepageText
text: 'Press the "Continue" button to stop sharing the files with your collaborators.\n\nUnshare will delete all editors, commenters, and viewers from this file/folder except for you, the owner. If the target file/folder is shared with a class of users who have general access, for example, if it is shared with the user\'s domain, that access setting will be changed to Private, where only the users explicitly granted permission can access.\n\n<b>THIS PROCESS CANNOT BE UNDONE in Unshare</b>.',
},
],
},
],
fixedFooter: {
primaryButton: {
text: 'CONTINUE', // localizedMessage.messageList.buttonContinue
textButtonStyle: '',
onClickAction: { functionName: 'buildConfirmationPage' },
openLink: '',
},
secondaryButton: {
text: 'HELP', // localizedMessage.messageList.buttonHelp
textButtonStyle: '',
onClickAction: {},
openLink: 'https://www.scriptable-assets.page/add-ons/unshare/',
},
},
};

test(inputBuildHomepage.testName, () => {
expect(buildHomepage(inputBuildHomepage.event)).toEqual(expectedOutput);
});
test(inputBuildDriveItemsSelected.testName, () => {
expect(buildDriveItemsSelected(inputBuildDriveItemsSelected.event)).toEqual(
expectedOutput
);
});
78 changes: 78 additions & 0 deletions __test__/checkExecTime.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
const {
ADDON_EXEC_TIME_LIMIT_IN_MILLISEC,
checkExecTime,
} = require('../src/unshare');
const now = new Date();
const userLocale = 'en';
const currentIndex = 1;
const originalFileArray = [
{ id: 'fileId1', fileName: 'fileName1' },
{ id: 'fileId2', fileName: 'fileName2' },
{ id: 'fileId3', fileName: 'fileName3' },
];

const patterns = [
{
patternName: 'Check checkExecTime: Within time limit',
input: {
withinTimelimit: true,
startTime: now,
isFileEnd: false,
},
expectedOutput: null,
},
{
patternName: 'checkExecTime: Exceed time limit, File end: true',
input: {
withinTimelimit: false,
startTime: new Date(now.getTime() - ADDON_EXEC_TIME_LIMIT_IN_MILLISEC),
isFileEnd: true,
},
expectedOutput: `[Exceeded Time Limit]\nThe execution time of Unshare is limited to ${
ADDON_EXEC_TIME_LIMIT_IN_MILLISEC / 1000
} seconds by Google. It could not finish "un"sharing the following file/folder(s) due to this limit:\n${originalFileArray
.slice(currentIndex + 1)
.map((file) => file.fileName)
.join('\n')}`, // localizedMessage.replaceErrorExceededTimeLimit
},
{
patternName: 'checkExecTime: Exceed time limit, File end: false',
input: {
withinTimelimit: false,
startTime: new Date(now.getTime() - ADDON_EXEC_TIME_LIMIT_IN_MILLISEC),
isFileEnd: false,
},
expectedOutput: `[Exceeded Time Limit]\nThe execution time of Unshare is limited to ${
ADDON_EXEC_TIME_LIMIT_IN_MILLISEC / 1000
} seconds by Google. It could not finish "un"sharing the following file/folder(s) due to this limit:\n${originalFileArray
.slice(currentIndex)
.map((file) => file.fileName)
.join('\n')}`, // localizedMessage.replaceErrorExceededTimeLimit
},
];

patterns.forEach((pattern) => {
test(pattern.patternName, () => {
if (pattern.input.withinTimelimit) {
expect(
checkExecTime(
pattern.input.startTime,
currentIndex,
originalFileArray,
userLocale,
pattern.input.isFileEnd
)
).toBe(pattern.expectedOutput);
} else {
expect(() => {
checkExecTime(
pattern.input.startTime,
currentIndex,
originalFileArray,
userLocale,
pattern.input.isFileEnd
);
}).toThrowError(new Error(pattern.expectedOutput));
}
});
});
58 changes: 58 additions & 0 deletions __test__/createMessageCard.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
const { createMessageCard } = require('../src/unshare');
const TEST_MESSAGE = 'This is a test message for createMessageCard';
const USER_LOCALE = 'en';

const patterns = [
{
testName: 'Check createMessageCard: isHostDrive=true',
input: {
isHostDrive: true,
},
expectedOutput: {
sections: [
{
widgets: [{ text: TEST_MESSAGE }],
},
],
fixedFooter: {
primaryButton: {
text: 'Return Home', // localizedMessage.messageList.buttonReturnHome
textButtonStyle: 'FILLED',
onClickAction: { functionName: 'buildDriveHomepage' },
openLink: '',
},
secondaryButton: {},
},
},
},
{
testName: 'Check createMessageCard: isHostDrive = false',
input: {
isHostDrive: false,
},
expectedOutput: {
sections: [
{
widgets: [{ text: TEST_MESSAGE }],
},
],
fixedFooter: {
primaryButton: {
text: 'Return Home', // localizedMessage.messageList.buttonReturnHome
textButtonStyle: 'FILLED',
onClickAction: { functionName: 'buildHomepage' },
openLink: '',
},
secondaryButton: {},
},
},
},
];

patterns.forEach((pattern) => {
test(pattern.testName, () => {
expect(
createMessageCard(TEST_MESSAGE, USER_LOCALE, pattern.input.isHostDrive)
).toEqual(pattern.expectedOutput);
});
});
Loading

0 comments on commit 115809c

Please sign in to comment.