-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #52 from ttsukagoshi/main
v1.1.0 release
- Loading branch information
Showing
26 changed files
with
6,744 additions
and
1,167 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
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 |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,3 +6,6 @@ node_modules/ | |
|
||
# clasp | ||
.clasp.json | ||
|
||
# jest | ||
coverage/ |
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,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 | ||
); | ||
}); | ||
}); |
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,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); | ||
}); |
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,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 | ||
); | ||
}); |
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,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)); | ||
} | ||
}); | ||
}); |
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,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); | ||
}); | ||
}); |
Oops, something went wrong.