• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2021 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 *     http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16import { hasComplete } from "../utils"
17
18export function mockFile() {
19  const file = {
20    move: function (...args) {
21      console.warn("file.move interface mocked in the Previewer. How this interface works on the Previewer may be" +
22        " different from that on a real device.")
23      args[0].success(args[0].dstUri)
24      hasComplete(args[0].complete)
25    },
26    copy: function (...args) {
27      console.warn("file.copy interface mocked in the Previewer. How this interface works on the Previewer may be" +
28        " different from that on a real device.")
29      args[0].success(args[0].dstUri)
30      hasComplete(args[0].complete)
31    },
32    list: function (...args) {
33      console.warn("file.list interface mocked in the Previewer. How this interface works on the Previewer may be" +
34        " different from that on a real device.")
35      const data = {
36        fileList: [{
37          uri: '[PC Preview]: no file',
38          lastModifiedTime: "[PC Preview]: no file",
39          length: "[PC Preview]: no file",
40          type: 'file'
41        }]
42      }
43      args[0].success(data)
44      hasComplete(args[0].complete)
45    },
46    get: function (...args) {
47      console.warn("file.get interface mocked in the Previewer. How this interface works on the Previewer may be" +
48        " different from that on a real device.")
49      const data = {
50        uri: '[PC Preview]: no file',
51        lastModifiedTime: "[PC Preview]: no file",
52        length: "[PC Preview]: no file",
53        type: 'file',
54        subFiles: ["[PC Preview]: no file", "[PC Preview]: no file"]
55      }
56      args[0].success(data)
57      hasComplete(args[0].complete)
58    },
59    delete: function (...args) {
60      console.warn("file.delete interface mocked in the Previewer. How this interface works on the Previewer may be" +
61        " different from that on a real device.")
62      args[0].success()
63      hasComplete(args[0].complete)
64    },
65    writeText: function (...args) {
66      console.warn("file.writeText interface mocked in the Previewer. How this interface works on the Previewer may" +
67        " be different from that on a real device.")
68      args[0].success()
69      hasComplete(args[0].complete)
70    },
71    writeArrayBuffer: function (...args) {
72      console.warn("file.writeArrayBuffer interface mocked in the Previewer. How this interface works on the" +
73        " Previewer may be different from that on a real device.")
74      args[0].success()
75      hasComplete(args[0].complete)
76    },
77    readText: function (...args) {
78      console.warn("file.readText interface mocked in the Previewer. How this interface works on the Previewer may" +
79        " be different from that on a real device.")
80      const data = { text: "[PC Preview]: success default" }
81      args[0].success(data)
82      hasComplete(args[0].complete)
83    },
84    readArrayBuffer: function (...args) {
85      console.warn("file.readArrayBuffer interface mocked in the Previewer. How this interface works on the" +
86        " Previewer may be different from that on a real device.")
87      const data = { buffer: ["[PC Preview]: default", "[PC Preview]: default", "[PC Preview]: default"] }
88      args[0].success(data)
89      hasComplete(args[0].complete)
90    },
91    access: function (...args) {
92      console.warn("file.access interface mocked in the Previewer. How this interface works on the Previewer may be" +
93        " different from that on a real device.")
94      args[0].success()
95      hasComplete(args[0].complete)
96    },
97    mkdir: function (...args) {
98      console.warn("file.mkdir interface mocked in the Previewer. How this interface works on the Previewer may be" +
99        " different from that on a real device.")
100      args[0].success()
101      hasComplete(args[0].complete)
102    },
103    rmdir: function (...args) {
104      console.warn("file.rmdir interface mocked in the Previewer. How this interface works on the Previewer may be" +
105        " different from that on a real device.")
106      args[0].success()
107      hasComplete(args[0].complete)
108    }
109  }
110  return file
111}