fileAssetFavoritePromise.test.ets 10.6 KB
Newer Older
Y
yangbo 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
/*
 * Copyright (C) 2022 Huawei Device Co., Ltd.
 * 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
 *
 *     http://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.
 */

Y
yangbo 已提交
16
import userFileManager from '@ohos.filemanagement.userFileManager';
Y
yangbo 已提交
17 18 19 20
import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from 'deccjsunit/index';
import {
    sleep,
    checkPresetsAssets,
Y
yangbo 已提交
21 22
    audioNameFetchOps,
    imageVideoNameFetchOps,
Y
yangbo 已提交
23 24 25
    checkAssetsCount,
} from '../../../../../../common';

Y
yangbo 已提交
26 27
export default function fileAssetFavoritePromiseTest(abilityContext) {
    describe('fileAssetFavoritePromiseTest', function () {
Y
yangbo 已提交
28
        var userfilemgr = userFileManager.getUserFileMgr(abilityContext);
Y
yangbo 已提交
29 30
        beforeAll(async function () {
            console.info('beforeAll case');
Y
yangbo 已提交
31
            await checkPresetsAssets(userfilemgr, 'ActsUserFileMgrFavorite');
Y
yangbo 已提交
32 33 34 35 36 37 38 39 40 41 42 43
        });
        beforeEach(function () {
            console.info('beforeEach case');
        });
        afterEach(async function () {
            console.info('afterEach case');
            await sleep()
        });
        afterAll(function () {
            console.info('afterAll case');
        });

Y
yangbo 已提交
44
        const favoriteDefaultState = async function (done, testNum, fetchOp, isAudio) {
Y
yangbo 已提交
45
            try {
Y
yangbo 已提交
46
                let fetchAssetResult;
Y
yangbo 已提交
47 48
                if (isAudio) {
                    fetchAssetResult = await userfilemgr.getAudioAssets(fetchOp);
Y
yangbo 已提交
49 50
                } else {
                    fetchAssetResult = await userfilemgr.getPhotoAssets(fetchOp);
Y
yangbo 已提交
51 52
                }
                let checkAssetCountPass = await checkAssetsCount(done, testNum, fetchAssetResult, 1);
Y
yangbo 已提交
53
                if (!checkAssetCountPass) return;
Y
yangbo 已提交
54
                let asset = await fetchAssetResult.getFirstObject();
Y
yangbo 已提交
55 56
                let isFavorite = await asset.isFavorite();
                expect(isFavorite).assertEqual(false);
Y
yangbo 已提交
57
                fetchAssetResult.close();
Y
yangbo 已提交
58 59
                done()
            } catch (error) {
Y
yangbo 已提交
60
                console.info(`${testNum} failed error: ${error}`);
Y
yangbo 已提交
61 62 63 64
                expect(false).assertTrue();
                done();
            }
        }
Y
yangbo 已提交
65
        const favoriteByTrue = async function (done, testNum, fetchOp, isAudio) {
Y
yangbo 已提交
66
            try {
Y
yangbo 已提交
67
                let fetchAssetResult;
Y
yangbo 已提交
68 69
                if (isAudio) {
                    fetchAssetResult = await userfilemgr.getAudioAssets(fetchOp);
Y
yangbo 已提交
70 71
                } else {
                    fetchAssetResult = await userfilemgr.getPhotoAssets(fetchOp);
Y
yangbo 已提交
72 73
                }
                let checkAssetCountPass = await checkAssetsCount(done, testNum, fetchAssetResult, 1);
Y
yangbo 已提交
74
                if (!checkAssetCountPass) return;
Y
yangbo 已提交
75
                const asset = await fetchAssetResult.getFirstObject();
Y
yangbo 已提交
76 77 78
                await asset.favorite(true);
                let isFavorite = await asset.isFavorite();
                expect(isFavorite).assertEqual(true);
Y
yangbo 已提交
79
                fetchAssetResult.close();
Y
yangbo 已提交
80 81
                done();
            } catch (error) {
Y
yangbo 已提交
82
                console.info(`${testNum} failed error: ${error}`);
Y
yangbo 已提交
83 84 85 86
                expect(false).assertTrue();
                done();
            }
        }
Y
yangbo 已提交
87
        const favoriteByFalse = async function (done, testNum, fetchOp, isAudio) {
Y
yangbo 已提交
88
            try {
Y
yangbo 已提交
89
                let fetchAssetResult;
Y
yangbo 已提交
90 91
                if (isAudio) {
                    fetchAssetResult = await userfilemgr.getAudioAssets(fetchOp);
Y
yangbo 已提交
92 93
                } else {
                    fetchAssetResult = await userfilemgr.getPhotoAssets(fetchOp);
Y
yangbo 已提交
94 95
                }
                let checkAssetCountPass = await checkAssetsCount(done, testNum, fetchAssetResult, 1);
Y
yangbo 已提交
96
                if (!checkAssetCountPass) return;
Y
yangbo 已提交
97
                const asset = await fetchAssetResult.getFirstObject();
Y
yangbo 已提交
98 99 100 101
                await asset.favorite(true);
                await asset.favorite(false);
                let isFavorite = await asset.isFavorite();
                expect(isFavorite).assertEqual(false);
Y
yangbo 已提交
102
                fetchAssetResult.close();
Y
yangbo 已提交
103 104
                done();
            } catch (error) {
Y
yangbo 已提交
105
                console.info(`${testNum} failed error: ${error}`);
Y
yangbo 已提交
106 107 108 109 110 111 112 113 114 115 116
                expect(false).assertTrue();
                done();
            }
        }

        /**
         * @tc.number    : SUB_USERFILE_MGR_FILEASSET_FAVORITE_PROMISE_01_001
         * @tc.name      : isFavorite
         * @tc.desc      : isFavorite(image) result false
         * @tc.size      : MEDIUM
         * @tc.type      : Function
117
         * @tc.level     : Level 2
Y
yangbo 已提交
118
         */
119
        it('SUB_USERFILE_MGR_FILEASSET_FAVORITE_PROMISE_01_001', 2, async function (done) {
Y
yangbo 已提交
120
            let testNum = 'SUB_USERFILE_MGR_FILEASSET_FAVORITE_PROMISE_01_001';
Y
yangbo 已提交
121 122 123
            let currentFetchOp = imageVideoNameFetchOps(testNum, 'Pictures/FavPro/', '01.jpg');
            let isAudio = false;
            await favoriteDefaultState(done, testNum, currentFetchOp, isAudio);
Y
yangbo 已提交
124 125 126 127 128 129 130 131
        });

        /**
         * @tc.number    : SUB_USERFILE_MGR_FILEASSET_FAVORITE_PROMISE_01_002
         * @tc.name      : favorite
         * @tc.desc      : favorite(image) by true
         * @tc.size      : MEDIUM
         * @tc.type      : Function
132
         * @tc.level     : Level 2
Y
yangbo 已提交
133
         */
134
        it('SUB_USERFILE_MGR_FILEASSET_FAVORITE_PROMISE_01_002', 2, async function (done) {
Y
yangbo 已提交
135
            let testNum = 'SUB_USERFILE_MGR_FILEASSET_FAVORITE_PROMISE_01_002';
Y
yangbo 已提交
136 137 138
            let currentFetchOp = imageVideoNameFetchOps(testNum, 'Pictures/FavPro/', '02.jpg');
            let isAudio = false;
            await favoriteByTrue(done, testNum, currentFetchOp, isAudio);
Y
yangbo 已提交
139 140 141 142 143 144 145 146
        });

        /**
         * @tc.number    : SUB_USERFILE_MGR_FILEASSET_FAVORITE_PROMISE_01_003
         * @tc.name      : favorite
         * @tc.desc      : favorite(image) by false
         * @tc.size      : MEDIUM
         * @tc.type      : Function
147
         * @tc.level     : Level 2
Y
yangbo 已提交
148
         */
149
        it('SUB_USERFILE_MGR_FILEASSET_FAVORITE_PROMISE_01_003', 2, async function (done) {
Y
yangbo 已提交
150
            let testNum = 'SUB_USERFILE_MGR_FILEASSET_FAVORITE_PROMISE_01_003';
Y
yangbo 已提交
151 152 153
            let currentFetchOp = imageVideoNameFetchOps(testNum, 'Pictures/FavPro/', '03.jpg');
            let isAudio = false;
            await favoriteByFalse(done, testNum, currentFetchOp, isAudio);
Y
yangbo 已提交
154 155 156 157 158
        });

        /**
         * @tc.number    : SUB_USERFILE_MGR_FILEASSET_FAVORITE_PROMISE_02_001
         * @tc.name      : isFavorite
159
         * @tc.desc      : isFavorite(video) result false
Y
yangbo 已提交
160 161
         * @tc.size      : MEDIUM
         * @tc.type      : Function
162
         * @tc.level     : Level 2
Y
yangbo 已提交
163
         */
164
        it('SUB_USERFILE_MGR_FILEASSET_FAVORITE_PROMISE_02_001', 2, async function (done) {
Y
yangbo 已提交
165
            let testNum = 'SUB_USERFILE_MGR_FILEASSET_FAVORITE_PROMISE_02_001';
166 167
            let currentFetchOp = imageVideoNameFetchOps(testNum, 'Videos/FavPro/', '01.mp4');
            let isAudio = false;
Y
yangbo 已提交
168
            await favoriteDefaultState(done, testNum, currentFetchOp, isAudio);
Y
yangbo 已提交
169 170 171 172 173
        });

        /**
         * @tc.number    : SUB_USERFILE_MGR_FILEASSET_FAVORITE_PROMISE_02_002
         * @tc.name      : favorite
174
         * @tc.desc      : favorite(video) by true
Y
yangbo 已提交
175 176
         * @tc.size      : MEDIUM
         * @tc.type      : Function
177
         * @tc.level     : Level 2
Y
yangbo 已提交
178
         */
179
        it('SUB_USERFILE_MGR_FILEASSET_FAVORITE_PROMISE_02_002', 2, async function (done) {
Y
yangbo 已提交
180
            let testNum = 'SUB_USERFILE_MGR_FILEASSET_FAVORITE_PROMISE_02_002';
181 182
            let currentFetchOp = imageVideoNameFetchOps(testNum, 'Videos/FavPro/', '02.mp4');
            let isAudio = false;
Y
yangbo 已提交
183
            await favoriteByTrue(done, testNum, currentFetchOp, isAudio);
Y
yangbo 已提交
184 185 186
        });

        /**
187
         * @tc.number    : SUB_USERFILE_MGR_FILEASSET_FAVORITE_PROMISE_02_003
Y
yangbo 已提交
188
         * @tc.name      : favorite
189
         * @tc.desc      : favorite(video) by false
Y
yangbo 已提交
190 191
         * @tc.size      : MEDIUM
         * @tc.type      : Function
192
         * @tc.level     : Level 2
Y
yangbo 已提交
193
         */
194 195 196 197
        it('SUB_USERFILE_MGR_FILEASSET_FAVORITE_PROMISE_02_003', 2, async function (done) {
            let testNum = 'SUB_USERFILE_MGR_FILEASSET_FAVORITE_PROMISE_02_003';
            let currentFetchOp = imageVideoNameFetchOps(testNum, 'Videos/FavPro/', '03.mp4');
            let isAudio = false;
Y
yangbo 已提交
198
            await favoriteByFalse(done, testNum, currentFetchOp, isAudio);
Y
yangbo 已提交
199 200 201 202 203
        });

        /**
         * @tc.number    : SUB_USERFILE_MGR_FILEASSET_FAVORITE_PROMISE_03_001
         * @tc.name      : isFavorite
204
         * @tc.desc      : isFavorite(audio) result false
Y
yangbo 已提交
205 206
         * @tc.size      : MEDIUM
         * @tc.type      : Function
207
         * @tc.level     : Level 2
Y
yangbo 已提交
208
         */
209
         it('SUB_USERFILE_MGR_FILEASSET_FAVORITE_PROMISE_03_001', 2, async function (done) {
Y
yangbo 已提交
210
            let testNum = 'SUB_USERFILE_MGR_FILEASSET_FAVORITE_PROMISE_03_001';
211 212
            let currentFetchOp = audioNameFetchOps(testNum, 'Audios/FavPro/', '01.mp3');
            let isAudio = true;
Y
yangbo 已提交
213
            await favoriteDefaultState(done, testNum, currentFetchOp, isAudio);
Y
yangbo 已提交
214 215 216 217 218
        });

        /**
         * @tc.number    : SUB_USERFILE_MGR_FILEASSET_FAVORITE_PROMISE_03_002
         * @tc.name      : favorite
219
         * @tc.desc      : favorite(audio) by true
Y
yangbo 已提交
220 221
         * @tc.size      : MEDIUM
         * @tc.type      : Function
222
         * @tc.level     : Level 2
Y
yangbo 已提交
223
         */
224
        it('SUB_USERFILE_MGR_FILEASSET_FAVORITE_PROMISE_03_002', 2, async function (done) {
Y
yangbo 已提交
225
            let testNum = 'SUB_USERFILE_MGR_FILEASSET_FAVORITE_PROMISE_03_002';
226 227
            let currentFetchOp = audioNameFetchOps(testNum, 'Audios/FavPro/', '02.mp3');
            let isAudio = true;
Y
yangbo 已提交
228
            await favoriteByTrue(done, testNum, currentFetchOp, isAudio);
Y
yangbo 已提交
229 230 231 232 233
        });

        /**
         * @tc.number    : SUB_USERFILE_MGR_FILEASSET_FAVORITE_PROMISE_03_003
         * @tc.name      : favorite
234
         * @tc.desc      : favorite(audio) by false
Y
yangbo 已提交
235 236
         * @tc.size      : MEDIUM
         * @tc.type      : Function
237
         * @tc.level     : Level 2
Y
yangbo 已提交
238
         */
239
        it('SUB_USERFILE_MGR_FILEASSET_FAVORITE_PROMISE_03_003', 2, async function (done) {
Y
yangbo 已提交
240
            let testNum = 'SUB_USERFILE_MGR_FILEASSET_FAVORITE_PROMISE_03_003';
241 242
            let currentFetchOp = audioNameFetchOps(testNum, 'Audios/FavPro/', '03.mp3');
            let isAudio = true;
Y
yangbo 已提交
243
            await favoriteByFalse(done, testNum, currentFetchOp, isAudio);
Y
yangbo 已提交
244 245 246
        });
    });
}